How would I add a commad?

Post Reply
doghusky1990
Posts: 56
Joined: Wed Aug 01, 2012 2:26 pm

How would I add a commad?

Post by doghusky1990 » Wed Aug 08, 2012 1:48 pm

I am trying to modify/add a command that allows gm to add items to a targets inventory.

Reason; If i am testing something with a non gm character or I want to give a new player an item; I could just easily target them and use this command to add an item to their inventory.

I tried modifying the additem command to this

Code: Select all

function onTrigger(target,itemID,quantity)
	target:addItem(itemID,quantity);
end;
Targeted another player, and the item still added to my inventory...
Is this even possible?
Thanks to anyone in advance for helping.

PrBlahBlahtson
Developer
Posts: 539
Joined: Sun Jul 22, 2012 12:17 am

Re: How would I add a commad?

Post by PrBlahBlahtson » Wed Aug 08, 2012 2:29 pm

/dsp/conf/commands.conf also comes into play. By default, it's only configured to handle two integer values (itemID and quantity.)

And it may go deeper than that. I haven't crafted my own commands, I've just learned that it's not so easy as tampering with LUA functions :)

If you look in /src/map/commandhandler.h, you can see that permissions were planned, although I don't see where they're implemented. You might be able to find that and just unlock the command for all players.

bluekirby0
Developer
Posts: 707
Joined: Sun Jul 22, 2012 12:11 am

Re: How would I add a commad?

Post by bluekirby0 » Wed Aug 08, 2012 3:44 pm

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.

doghusky1990
Posts: 56
Joined: Wed Aug 01, 2012 2:26 pm

Re: How would I add a commad?

Post by doghusky1990 » Wed Aug 08, 2012 5:27 pm

Thank you so much, I will use this instead of editing a predefined command.
Thank you.

bluekirby0
Developer
Posts: 707
Joined: Sun Jul 22, 2012 12:11 am

Re: How would I add a commad?

Post by bluekirby0 » Wed Aug 08, 2012 9:07 pm

No problem...if you think this is a practical command to add for general use I can merge it into the svn as well.

doghusky1990
Posts: 56
Joined: Wed Aug 01, 2012 2:26 pm

Re: How would I add a commad?

Post by doghusky1990 » Wed Aug 08, 2012 10:56 pm

That would be sweat.
In all honesty, I do think it is a practical. It would allow gm give give people items in game without having to edit the database or make a whole bunch of temporary gms.

I also think that a command that adds and removed a targets keyitem would be useful as well.
ie.

Givekeyitem

Code: Select all

function onTrigger(player,target,keyID,quantity)
    tplayer = GetPlayerByName(target);
    if(tplayer ~= nil) then -- Player name (case sensitive) returned a valid entity, so continue!
        tplayer:addKeyItem(keyID);
    else -- Player name spelled wrong or not online
        printf("Player named %s not found!",target);
    end
end;
takekeyitem

Code: Select all

function onTrigger(player,target,keyID,quantity)
    tplayer = GetPlayerByName(target);
    if(tplayer ~= nil) then -- Player name (case sensitive) returned a valid entity, so continue!
        tplayer:delKeyItem(keyID);
    else -- Player name spelled wrong or not online
        printf("Player named %s not found!",target);
    end
end;

bluekirby0
Developer
Posts: 707
Joined: Sun Jul 22, 2012 12:11 am

Re: How would I add a commad?

Post by bluekirby0 » Thu Aug 09, 2012 12:43 pm

When you put it that way, I see a lot of potential for abuse as well. Even if GMs are totally trusted by the server admins, adding something like this does open up room for players to accuse GMs of granting favorable conditions unfairly to players. As a GM on the testing server, I do prefer people not have room to attack me because of things I can do but wouldn't. I have unfortunately already had people attack me over things that were totally unrelated to game balance and fairness so this just sounds like it is asking for trouble.

doghusky1990
Posts: 56
Joined: Wed Aug 01, 2012 2:26 pm

Re: How would I add a commad?

Post by doghusky1990 » Thu Aug 09, 2012 2:04 pm

Okay, well you don't have too. I will however use this on my server as it prevents me from having to edit the database constantly to give/take items that are needed for testing when i am testing with a group of people. Thank you for the help tho.

Post Reply