uEditU
uEdit Unturned
  • uEdit
  • Home
  • uEdit
    • FAQ
  • Sources
    • Plugin Sources
    • Other Sources
    • Server Hosting
  • Tools
    • Color Codes
    • RandomKeygen
    • Crontab
  • Unturned
  • Unturned
    • Information
    • Official Wiki
    • Commands
  • Tools
    • Server Settings
    • Workshop Config
  • Assets Browser
  • RocketMod
  • RocketMod
    • Editors
      • Permissions.config.xml
    • Libraries 250
    • Documentation
  • Plugins 545
  • OpenMod
  • OpenMod
    • Documentation
  • Plugins 253
  • uScript
  • uScript
    • Information
    • Documentation
      • Getting Started
      • How To
      • Events
  • Scripts 36
  • Modules 15
Looking for quality Plugins? Restore Monarchy - Simplicity over Complexity!
Login
uScript Documentation

How To

Small patterns you will reuse in real uScript commands

These examples cover common command and event patterns you can adapt into real uScript scripts.

Allow Console To Use Commands

By default, commands are player-only. If you want the in-server console to run a command too, change the caller rules explicitly.

What Matters
  • Set allowedCaller to "player", "console", or "both" depending on who should be allowed to execute the command.
  • If a command can be called from both places, you usually need separate output behavior for players and the console.
  • A player command can reply with player.message(...), while console usage typically logs through logger.log(...).
Things To Watch
  • When the console runs the command, player is not set because the console is not a player.
  • Guard player-specific logic by checking whether player != null before using player methods or properties.
  • If the command only makes sense in-game, keep it player-only instead of trying to support both callers unnecessarily.
Example: command usable by players and console
command whoami(){
    permission = "whoami";
    allowedCaller = "both";

    execute(){
        if(player != null){
            player.message("You're a player!");
        }
        else{
            logger.log("You're the console!");
        }
    }
}

Get A Player From Name Or SteamID

To turn user input into a player object, use <code>toPlayer(...)</code> and then validate the result before touching it.

What Matters
  • Use toPlayer(<string>) when a command argument might be a player name or Steam64 ID.
  • Treat the result as optional and check whether the conversion returned a player before continuing.
  • This pattern is useful for moderation commands, utility tools, and any script that targets another online player.
Things To Watch
  • The target player must be online for this lookup to work.
  • Validate the argument itself first so your command can fail gracefully when nothing was provided.
  • If conversion fails, return a clear error message instead of assuming the input matched someone.
Example: converting a command argument to a player
command convert(myArgument){
    permission = "convert";

    execute(){
        if(myArgument == null){
            player.message("This command requires an argument!");
            return;
        }

        targetPlayer = toPlayer(myArgument);

        if(targetPlayer != null){
            player.message("Successfully converted to a player.");
        }
        else{
            player.message("Failed to convert to a player.");
        }
    }
}

Make Something Happen Every X Seconds

Repeated logic belongs in <code>onInterval</code>. It is the event used when you want the script to run a task every fixed number of seconds.

What Matters
  • Use event onInterval(<seconds>) to execute logic on a schedule.
  • onInterval is the event where you provide the interval argument directly in the event declaration.
  • Short intervals are good for lightweight checks; longer intervals are better for rewards, cleanup tasks, or recurring announcements.
Things To Watch
  • Avoid doing heavy work too frequently unless you know the script cost is acceptable.
  • If you use foreach(player in server.players), be aware that player becomes your loop variable inside that block.
  • When a script already has a meaningful player variable in scope, rename the loop variable to something like serverPlayer to avoid confusion or accidental overwrites.
Example: broadcast every 5 seconds and reward online players every 10 minutes
event onInterval(5){
    broadcast("This message is broadcast every 5 seconds.");
}

event onInterval(600){
    foreach(serverPlayer in server.players){
        serverPlayer.experience += 100;
        serverPlayer.message("You earned 100 experience for playing on the server!", "yellow");
    }
}

Quick Reference

These are the takeaways that tend to matter most once you start writing actual commands and events.

  • allowedCaller controls whether a command is usable by players, console, or both.
  • player can be null when the console is the caller.
  • toPlayer(...) should always be followed by a null check.
  • toPlayer(...) only works for players who are currently online.
  • event onInterval(...) is the pattern for repeated timed behavior.
  • Rename loop variables like serverPlayer when player would be ambiguous.

Command Reference

The command examples on this page often pair well with the core script loader commands.

/script load [scriptName] /script reload [scriptName] /script unload [scriptName]
© 2026 uEdit. All rights reserved.
Terms of Service • Privacy Policy