Author Topic: Tool-Belt Settings  (Read 1180 times)

I need a run-down on how to manipulate tool belts. (E.G. where hammers and weapons are stored.)

A player's tools are stored in an array in the player object, and the GUI is clientside. It is best to update the GUI every time you change a client's inventory, or they may not be able to use it (0 items in the GUI means slots don't open even if you "really" do have one) or see the wrong symbol.

The array is from 0 (first slot, standard as hammerItem) to (%player.getDatablock().maxtools)-1. In all normal circumstances, anything except the Juggernaut which has increased inventory space, it is from 0 to 4.

To update a client's inventory, set their player's tool[slot] variable to the ID of the item, then send an update ('MsgItemPickup') message to the client with the slot and ID of the item.

For instance, this code gives all players a Gun in slot 4, if you are a Super Admin:

Code: [Select]
function servercmdGiveItems(%client)
{
        if(%client.isSuperAdmin)
        {
                for(%i=0;%i<ClientGroup.getCount();%i++){
               %cl = ClientGroup.getObject(%i);
               %cl.player.tool[4] = nametoID(gunItem);
               messageClient(%cl, 'MsgItemPickup', '', 4, nametoID(gunItem));
        }
}

In saving scripts, it's best to save the name of an item, not the ID, as this can change when you restart the game or enable/disable add-ons. Here, from my old RPG code:

Code: [Select]
function save(%client)
{
 ...
 %file.openForWrite("Add-Ons/client/RPG Files/Client Saves/" @ %name @".client");
 ...
  for(%i=0;%i<=4;%i++)
{
if(%client.player.tool[%i] !$= "" && %client.player.tool[%i] !$= "0")
%file.writeLine("WEAPON" SPC %client.player.tool[%i].getName());
else
%file.writeLine("WEAPON -1");
}
 ...
  %file.close();
%file.delete();
}

This code may not work instantly because a player's inventory is wiped when you die, so saving while dead may cause you to lose all items anyway.

I would use bl ids instead of client ids for persistence of player stats.  Also, it should be possible to have it save players stats upon death and upon exiting the server.  Other than that, I would probably update player saves every 10-15 minutes.

The system saved by "accounts" registered by a GUI or /cmds. It saved your inventory and other things when you die or leave the game, and when you [re-]spawn it loads them.

What are tools listed under? E.G. the wrench and printer