How to allow console to use commands
By default, the allowed caller of any command is limited to players only.
However, you can change this by setting the allowedCaller property of your command!
However, you can change this by setting the allowedCaller property of your command!
Possible values for
allowedCaller
are: player, console, or both.The player variable will not be set when the console issues the command because the console is not a player!
We can check for this by comparing player to null.
Here's an example:
command whoami(){
permission = "whoami";
allowedCaller = "both";
execute(){
if(player != null){
player.message("You're a player!");
}
else{
logger.log("You're a console!");
}
}
}
How to get a player from their name or steamid
In order to get a player from their name or steam64id, we can use the
toPlayer()
function.
It is also important to make sure that this function successfully returned a player type, so we should
follow it up by checking if the result is null (or in this case, not null).
follow it up by checking if the result is null (or in this case, not null).
The player MUST BE ONLINE for this to work.
Here's an example of converting a command argument to a player type:
command convert(myArgument){
permission = "convert";
execute(){
if(myArgument != null){
argPlayer = toPlayer(myArgument);
if(argPlayer != null){
player.message("Sucessfully converted to a player.").
}
else{
player.message("Failed to convert to a player.").
}
}
else{
player.message("This command requires an argument!").
}
}
}
How to make something happen every x seconds
You can use the onInterval event to make things happen every x amount of seconds.
The onInterval event is the ONLY event where you set an argument.
The onInterval event is the ONLY event where you set an argument.
It is also important to make sure that this function successfully returned a player type, so we should
follow it up by checking if the result is null (or in this case, not null).
follow it up by checking if the result is null (or in this case, not null).
It is used by doing:
event onInterval()
Here's an example that will be executed every 5 seconds:
event onInterval(5){
broadcast("This message is broadcasted every 5 seconds");
}
Here's another example that will be exescuted every 10 minutes:
event onInterval(600){
foreach(player in server.players){
player.experience += 100;
player.message("You have earned 100 experience for playing on the server!", "yellow");
}
}
The above example uses player as the foreach loop variable. While this is valid in the above event, be way of using this when a player variable is already defined (such as in a command). If already defined, it will be overwritten! To fix this issue, simply rename the loop variable to something else, such as serverPlayer.