Skip to content
This repository was archived by the owner on Oct 15, 2022. It is now read-only.

Functions

Daranix edited this page Sep 6, 2015 · 19 revisions

gm.utility.proximityMessage(radi, sender, message, opt_color)

Sends a message to all players around another player (sender)

commands.set("say", (player,args) {
 let text = args.join(" ");
 gm.utility.proximityMessage(50.0, player, text, new RGB(255,255,255));
});

gm.utility.adminMessage(message, opt_color)

Send a message to all connected administrators

commands.set("a", (player, args) {
 let text = args.join(" ");

 gm.utility.adminMessage(text, new RGB(255,255,255));
});

gm.utility.factionMessage(faction, message, opt_color)

Send a message to all players connected with faction id = (faction)

commands.set("f", (player, args) {
 let text = args.join(" ");

 gm.utility.factionMessage(PlayerInfo[player.name].faction, text, new RGB(255,255,255));
});

gm.utility.groupMessage(gid, message, opt_color)

commands.set("g", (player, args) {
 let text = args.join(" ");

 gm.utility.groupMessage(PlayerInfo[player.name].groupid, text, new RGB(255,255,255));
});

gm.utility.PlayerToPoint(radi, player, x, y, z)

Checks if a player is in range of a point

commands.set("inrange", (player) {

 if(gm.utility.PlayerToPoint(10.0, player, 3360.19, -4849.67, 111.8)) {
  player.SendChatMessage("Yes! you are in range"); // True
 } else {
  player.SendChatMessage("You are not in range"); // False
 }

});

gm.utility.print(message)

Send a message to console (console.log) with ( date-month-year || hour:minute:seconds )


gm.utility.isInArray(value, array)

Check if a value is in array

commands.set("checkarray", (player) {
 let datArray = [0, 7, 8];

 if(gm.utility.isInArray(7, datArray)) {
  player.SendChatMessage("Yes it's"); // TRUE
 } else {
  player.SendChatMessage("Nope"); // FALSE
 }
});

gm.utility.GetPlayerMoney(player, money)

gm.utility.SetPlayerMoney(player, money)

gm.utility.GivePlayerMoney(player, money)


Group functions

gm.utility.Group.Update(indexGroup)

Update members, and members ranks information to the database.

gm.utility.Group.addmember(player, gid)

NOTE: gid is index of the group in array.

gm.utility.Group.removemember(player)

remove (kick) a player from his group

If player removed is the leader, new leader is the guy in index 0 of GroupInfo array (GroupInfo[indexGroup].members[0])

gm.utility.Group.findById(id)

find a group index in array GroupInfo using the id on the database.

gm.utility.Group.create

Creates a group and put it in a player.

example:

commands.set("groupcreate", (player, args) => {
      let gname = args[0];

      if(typeof gname === 'undefined') {
        return player.SendChatMessage("/groupcreate [group name]");
      }

      if(PlayerInfo[player.name].groupid >= 1) return player.SendChatMessage("You was already in a group");

      let group = new gm.utility.Group(gname);
      group.create(player);

});

gm.utility.LoadGroups(dbconnection)

Used to load all groups saved in the database at the start of the server

Shop functions

gm.utility.Shop.Create

Used to create a shop.

You can se a example on [gm.utility.LoadShops()](NOLINK)

gm.utility.Shop.buy(player, item, quantity)

Used to give a item of the shop where is the player.

the buy function checks in what shop was the player, if the item was in the shop (checks by number in the shop and by name)

commands.set("shop", (player, args) => {

  let product = args[0]; // Get the product
  let quantity = parseInt(args[1]) || 1; // Put as default 1 if no quantitiy especified

  for(let i = 0; i < g_shops; i++) { // Check all shops

    let sphere = new gm.utility.sphere(ShopInfo[i].position.x, ShopInfo[i].position.y, ShopInfo[i].position.z);
    if(sphere.inRangeOfPoint(player.position)) { // To check if the player was in a shop.
      if(product == null) { // If just write /shop see all items in the shop.
        player.SendChatMessage("Shop items:");
        for(let c = 0; c < ShopInfo[i].items.length; c++) {
          player.SendChatMessage(c + ": " + ShopInfo[i].items[c])
        }
        break;
      } else {
        if(isNaN(quantity) || quantity <= 0) return player.SendChatMessage("invalid quantity");
        gm.utility.Shop.buy(player, product, quantity); // Buy the item if the item was in the shop
      }
      return true;
      break;
    }
    return player.SendChatMessage("No shop here");
  }
});

gm.utility.LoadShops()

Used to load all shops at the start of the server

Example:

Utility.LoadShops = () => {
	
	console.log("Loading shops...");
	let shop, position, items;

	// 1 - 
	items = ["apple", "orange", "kebab", "cocacola", "bannana", "rat", "lemon juice"];
	position = new Vector3f(3360.19, -4849.67, 111.8);
	shop = new Utility.Shop(position, items)
	shop.create();

	// 2 - 
	items = ["shears", "wives", "explosive charge", "flanges keys"];
	position = new Vector3f(-90.0, -2365.8, 14.3);
	shop = new Utility.Shop(position, items)
	shop.create();

	console.log("Loaded " + g_shops + " shop(s)");
}

Items functions

gm.utility.Item.findByName(target, name)

Finds a item on gm.items inventory.js array by name

gm.utility.Item.give(player)

Give a item to a player checking if the player gots space in his inventory.

Example

commands.set("additem", (player, args) => {

  let item = args[0];
  let quantity = parseInt(parseInt(args[1]));

  if(isNaN(quantity)) return player.SendChatMessage("Quantity must be a number");

  /*PlayerInventory[player.name].objects.push(item);
  PlayerInventory[player.name].objectsQuantity.push(quantity);
  */

  let objitem = new gm.utility.Item(item, quantity);

  objitem.give(player);

  player.SendChatMessage("Added Item: " + item + " quantity: " + quantity);

});

gm.utility.Item.remove(player)

Remove a item from player inventory

commands.set("removeitem", (player, args) => {

  let item = args[0];
  let quantity = parseInt(parseInt(args[1]));

  if(isNaN(quantity)) return player.SendChatMessage("Quantity must be a number");

  let objitem = new gm.utility.Item(item, quantity);
  objitem.remove(player);

  player.SendChatMessage("Removed Item: " + item + " quantity: " + quantity);

});