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:
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:
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.