PlaceholderAPI/Javascript-Expansion

Return Custom Afk Output - Community Scripts Contribution

HLX-DENNIS opened this issue · 2 comments

Return Custom Afk Output

  • Author: DennisTheSeagull
  • Description: Check if a player is afk & then return a custom output depending on the boolean.
    This script is using the %essentials_afk% placeholder. In simpler terms, this allows you to change the normal yes/no output to something of your choice. Very useful!
  • Usage: %javascript_check_afk%

Javascript Code:

check_afk.js
var afk = "%essentials_afk%";

function checkAfk() {
    if (afk == "yes") {
        return "[AFK]";
    }
    return "";
}

checkAfk();

Commented Javascript Code:

check_afk.js
// create a variable and name it to whichever you prefer
// %essentials_afk% is the placeholder that we'll be changing the output of
var afk = "%essentials_afk%";

// create a function with your prefered name
function checkAfk() {

// if the afk variable that we created before returns yes (true boolean)
// the javascript placeholder will return whichever we set the return output to
    if (afk == "yes") {
        return "[AFK]";
    }

// if the afk variable isn't true, it will return a different output
    return "";
}
// this calls the function to run
checkAfk();

Add to javascript_placeholder.yml

check_afk:
  file: check_afk.js

// the PlaceholderAPI.static.setPlaceholders() is used to parse placeholders inside the javascript placeholder

Wrong, that method is used if you have placeholders like "%expannsion_" + argument + "%", all the other placeholders are replaced by default

// the PlaceholderAPI.static.setPlaceholders() is used to parse placeholders inside the javascript placeholder

Wrong, that method is used if you have placeholders like "%expannsion_" + argument + "%", all the other placeholders are replaced by default

I stand corrected ¯_(ツ)_/¯ Thank you kind sir for the clarification. I've updated the post with the correct information.