I have a script that takes all players that deal damage, and assigns them a tag;
[code]
function preTakeDmg(ply, att)
att.hurt = true
end
hook.Add("PlayerShouldTakeDamage", "preTakeDamage", preTakeDmg)
[/code]
I also have a chat command that tells me whether or not any given player has this tag set, using getPlayer() and the player's name. It seems to return the player object just fine, but it doesn't return the custom meta-info that I assigned to the player.
Can you provide the code you use for checking it?
Also using "PlayerHurt" hook would be more appropriate, because that way it tags them if they actually take damage, everything going through "PlayerShouldTakeDamage" is not guaranteed to actually hurt them.
Here's the chat command code;
[code]
function chat(ply, text, isTeamChat, isDead)
sp = trim(text):split(" ")
com = sp[1]:lower()
if ply:IsAdmin() and #sp > 1 and com:sub(1, 1) == "!" then
conc = table.concat({unpack(sp, 2)}, " ")
tarp = getPlayer(conc)
if tarp == nil then
ply:PrintMessage(3, "Player " .. conc .. " not found.")
else
ply:PrintMessage(3, "Player " .. tarp:GetName() .. " has a tag of " .. tarp.hurt)
end
end
end
[/code]
It catches the players properly, but never displays the tags properly; it's always nil.
Here's a method for turning ! and / chat messages into console commands ( you can also add salt and pepper using example 2 ) and it shows how to separate the command from the args in example 3 and note 1..
EDIT: Forgot the link O_o: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_commands/chat_commands.lua.html[/url]
[QUOTE=Acecool;47326138]Here's a method for turning ! and / chat messages into console commands ( you can also add salt and pepper using example 2 ) and it shows how to separate the command from the args in example 3 and note 1..[/QUOTE]
You forgot the link
[QUOTE=Acecool;47326138]Here's a method for turning ! and / chat messages into console commands ( you can also add salt and pepper using example 2 ) and it shows how to separate the command from the args in example 3 and note 1..
EDIT: Forgot the link O_o: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/chat_commands/chat_commands.lua.html[/url][/QUOTE]
I don't need help parsing chat commands, I already have that down. I need help with custom player userdata.
[editline]15th March 2015[/editline]
I might end up just using a serverside table to store plugin information, however that isn't saved between script refreshes. So if anyone can come up with another answer to my problem that allows persistent information to be stored and fetched universally, then that'd be great.
I think you have your arguments wrong. The attacker is the entity that is hurting the player.
Try this instead:
[code]ply.hurt = true[/code]
Look, it doesn't matter who has the tag. The problem is that it doesn't show up on anybody, no matter how much it ought to.
1. Localize your functions please.
2. Are you sure they're being set/called on the same realm? i.e. you're not hooking into PlayerShouldTakeDamage on clientside, but then having the chat command on serverside. (or vice versa)
Also, Kogitsune is right. You're setting the attacker to hurt, not the person being hurt.
Alternatively, you could just use NWBools.
[QUOTE=Lolcats;47329291]1. Localize your functions please.
2. Are you sure they're being set/called on the same realm? i.e. you're not hooking into PlayerShouldTakeDamage on clientside, but then having the chat command on serverside. (or vice versa)
Also, Kogitsune is right. You're setting the attacker to hurt, not the person being hurt.
Alternatively, you could just use NWBools.[/QUOTE]
1. sure, sure.
2. Yes, they're both in the same serverside file.
And the value "hurt" is tagged on players that have hurt other players, not the other way around.
I've just ended up initializing a general metainfo table at the top of my script, and storing custom information in that.
[QUOTE=Maurdekye;47327958]I don't need help parsing chat commands, I already have that down. I need help with custom player userdata.
[editline]15th March 2015[/editline]
I might end up just using a serverside table to store plugin information, however that isn't saved between script refreshes. So if anyone can come up with another answer to my problem that allows persistent information to be stored and fetched universally, then that'd be great.[/QUOTE]
So, storing data on a player object shouldn't get overwritten on auto-refresh... Now, if you want a variable to store info during auto-refresh.. it needs to be global and it looks like this: data = data || { }; so the first time the script is executed, data doesn't exist so it gets assigned as a new table and any subsequent refresh, data will be assigned to something so it uses its' own reference meaning it won't reset.
If you're saving data to clients ( unless there is an issue with meta-tables or this was the issue... ) then it shouldn't reset. Remember, players are entities and they're considered meta-tables. This doesn't matter for storing data really, just use ply.Data = true;
The only reason the data would be getting lost would be if you're resetting it somewhere in a script somewhere OR if you're using a variable which is used for something else and the something else is updating the variable OR you're not setting it in the right place...
Push comes to shove, you could do what I do and store data in a table of its own ( mine is global data ) which uses EntIndex as the key... It's built together with my networking system so when the server sets the data on a player, the player will get it. If it is public data, then everyone knows it. Private means only the player, or linked players get it ( for example, vehicles.. you don't need to broadcast the vehicle speed, fuel, odo, etc.. to everyone each time it updates so it is set to private for the vehicle meaning only the server knows about it, and if a driver gets in then that driver gets linked and will receive updates; think of linking as being able to subscribe to data you need to know about )...
If a client sets a flag/data on anything, public or private, only the client knows about this ( clients can't network to server any data unless you call SyncFlag.. In that case, only specific vars can be changed by players if they are the player or they're in control of the object in question.. ie a player can try SyncFlag to send data to the server to turn on headlights on a car only if they are the driver, all other data gets denied... SyncFlag is close-ended to prevent bad clients [ never trust client data ] so you can have vars registered as open-ended but it isn't recommended so you can define data-types allowed and even go so far as limit it to specific values )...
[url]https://bitbucket.org/Acecool/acecooldev_networking/src/[/url]
Hopefully this helps.
Yeah, I kind of figured out the globaldata = globaldata or {} on my own, and i've been using that. I'm not sure about script refreshes, but it seems to be working just fine. I save the player's names as indexes. I'll mark this thread as solved.
Sorry, you need to Log In to post a reply to this thread.