• Using an entity index
    4 replies, posted
I am developing an addon for TTT I am using the TTT hook "TTTPlayerRadioCommand (ply, cmd_name, cmd_target)" to listen for KOS's (Kill On Sight) made by the players. I want to get the player name of the cmd_target. In the TTT documentation it says that: "cmd_target" is the target part of the command (an entity index if it's a player or identified corpse, an identifier like "quick_nobody" if not) So, cmd_target is apparently an entity index for the target player. I am not sure how to "use" this entity index. How do i get the name of the player the entity index is pointing at? I have tried: tostring(cmd_target), but that did not work
Try this: [url]http://wiki.garrysmod.com/page/ents/GetByIndex[/url]
[QUOTE=ms333;41885334]Try this: [url]http://wiki.garrysmod.com/page/ents/GetByIndex[/url][/QUOTE] I get a "Bad argument #1 to GetByIndex (number expected, got userdata) when i called ents.GetByIndex( cmd_target ) I guess the TTT documentation is wrong.
You can just do Entity( yourEntityIndex ) [lua] local aPlayer = Entity(1) --where 1 is your index if IsValid(aPlayer) and aPlayer:IsPlayer() then print( aPlayer:Nick() ) end[/lua]
[QUOTE=wh1t3rabbit;41885408]You can just do Entity( yourEntityIndex ) [lua] local aPlayer = Entity(1) --where 1 is your index if IsValid(aPlayer) and aPlayer:IsPlayer() then print( aPlayer:Nick() ) end[/lua][/QUOTE] Sorry but that did not work. I think the problem is that the documentation is out of date. cmd_target does not appear to be an entity index, but instead something called "userdata".
Sorry, you need to Log In to post a reply to this thread.