UScript for Unturned Code Samples: Difference between revisions

From Free Knowledge Base- The DUCK Project
Jump to navigation Jump to search
mNo edit summary
 
(6 intermediate revisions by the same user not shown)
Line 10: Line 10:


== SQL Related ==
== SQL Related ==
=== populate an arrow with records from SQL table ===
=== populate an array with records from SQL table ===
  vRecords = database.allRows("SELECT * FROM uconomy ORDER BY balance DESC LIMIT " + n);
  vRecords = database.allRows("SELECT * FROM uconomy ORDER BY balance DESC LIMIT " + n);


Line 23: Line 23:


  event onPlayerEquipped(player, item){
  event onPlayerEquipped(player, item){
== custom commands ==
When creating a command the following is a minimum requirement
command yourcommandname(){
  execute(){
  }
}
you can precede the command with a declaration of permissions
When creating a command the following is a minimum requirement
command yourcommandname(){
  permission = config["permission_prefix"] + ".yourcommandname"
  allowedCaller = "player";
  execute(){
  }
}
variables set outside of the "execute()" block will not be available from within.
you may accept command line parameters, and check if any are supplied by the user when executed.
command mycommand(str){
  permission = config["permission_prefix"] + ".mycommand";
  allowedCaller = "player";
  execute(){
    if(arguments.count < 1){
      player.message("please specify an argument.", "yellow");
== player inventory ==
=== search player inventory for item ===
=== remove item from player inventory ===
This code sample makes sure the item is in the player's inventory, then removes it:
  if (player.inventory.hasItem(24749)) {
    player.inventory.removeItem(24749, 1);
  }


== Other Examples ==
== Other Examples ==
Line 28: Line 64:
   foreach(player in server.players) {
   foreach(player in server.players) {
   }
   }
=== Rocket Groups, Game Voice Groups, Group Examples ===
//  print("VIP Player Group:" + objPlayer.Group);
== related ==
* [[Unturned]]
[[Category:Unturned]]
[[Category:uScript]]

Latest revision as of 16:58, 31 January 2025

Messages

broadcast a message to allow players on server

broadcast("Door Alarm triggered! Door InstanceID: {0} | Name of inturder: {1}".format(doorid, player.name), "red");

send an on screen message to a single player

player.message("Door InstanceID: " + doorid, "red");

echo a message to console

echo ("message");

SQL Related

populate an array with records from SQL table

vRecords = database.allRows("SELECT * FROM uconomy ORDER BY balance DESC LIMIT " + n);

prevent error from comparisons when array is empty because SQL record is missing or null

if (vPlayerName.count == 0) {

Event Examples

event  onZombieKilled(player){
    PlayerData = AllPlayerInfo[i];
    broadcast(player.name + " killed a zombie.");
}
event onPlayerEquipped(player, item){

custom commands

When creating a command the following is a minimum requirement

command yourcommandname(){
  execute(){
  }
}

you can precede the command with a declaration of permissions When creating a command the following is a minimum requirement

command yourcommandname(){
  permission = config["permission_prefix"] + ".yourcommandname"
  allowedCaller = "player";
  execute(){
  }
}

variables set outside of the "execute()" block will not be available from within.

you may accept command line parameters, and check if any are supplied by the user when executed.

command mycommand(str){
  permission = config["permission_prefix"] + ".mycommand";
  allowedCaller = "player";
  execute(){
    if(arguments.count < 1){
      player.message("please specify an argument.", "yellow");

player inventory

search player inventory for item

remove item from player inventory

This code sample makes sure the item is in the player's inventory, then removes it:

 if (player.inventory.hasItem(24749)) {
   player.inventory.removeItem(24749, 1);
 }

Other Examples

Players in server

 foreach(player in server.players) {
 }

Rocket Groups, Game Voice Groups, Group Examples

//  print("VIP Player Group:" + objPlayer.Group);


related