The issue is there is no BaseEntity or BattleEntity fed to a script for a targeted player. You will have to pass the name of a currently logged in player to GetPlayerByName (see scripts/commands/bring.lua for an example). You will then have to use the pointer you created with that function as the base for the addItem command. After all that, you will have to add a relevant entry to conf/commands.conf (as mentioned above). You should end up with something like:
giveitem.lua
Code: Select all
function onTrigger(player,target,itemID,quantity)
tplayer = GetPlayerByName(target);
if(tplayer ~= nil) then -- Player name (case sensitive) returned a valid entity, so continue!
tplayer:addItem(itemID,quantity);
else -- Player name spelled wrong or not online
printf("Player named %s not found!",target);
end
end;
And then in commands.conf you would need to add a line:
Code: Select all
commands_ini[32] = { ["name"] = "giveitem", ["path"] = "scripts/commands", ["parameters"] = "sii" };
The first number (32 in this case) needs to be the next consecutive number after the previous entry. "giveitem" is the name of both the lua script and the command to listen for. "sii" tells it to expect 3 arguments...a string (target player's name), and two integers (item ID and quantity).
If you really just want to modify your additem command it will be a little more complicated as svn changes are merged with your local server.