Too much to put in title, involves datastream and usermessages... :)

Uhm…where to start… ok ill put my objective first

OBJECTIVE: When a player dies, the player’s weapons are stored into a table in the ragdoll(a serverside ragdoll). When a player presses use on the ragdoll, a derma menu comes up with the dead player’s holstered weapons, and the player looking through the weapons may click on a spawnicon to take the weapon, and the spawnicon is removed, and the weapon is removed from the table on the server

PROBLEM: I’ve got everything BUT to the point where the player clicks on the spawnicon to get the weapon, I removed the spawnicon from the clientside derma panel list… but ran into a problem on the server…see… the way my code works is, when the ragdoll is created, its local, which is fine and all cause I can get the ragdoll entity using tr.Entity when the player presses use, but by the time the datastream gets sent back to the server…the player could be looking somewhere else(some may argue it freezes you…not if your moving and press e at the same time, or stand up after crouching), so then there is no way of “finding” the the entity’s table to be removed from :frowning:


EDIT: Would it be possible to have some sort of reference to the ragdoll stored into the player? Like ply.lastusedragdoll

If the issue is datastream isn’t working fast enough, then just use a concommand. There’s rarely a reason to use datastream unless you just have MASSIVE amounts of data you need to send from client to server or vice versa.

[editline]14th February 2011[/editline]

For example, instead of sending the entire table of information about the weapon or whatever just send an ID. On the server, you have a table of all the weapons and stuff you can scavenge, and you find the info from the table based on the ID.

I’m sticking with datastream cause 1) I’ll need to send tables of tables…maybe even tables of tables of tables later on :slight_smile:
2) I’m too lazy to change everything to use concommands lol

EDIT: I was thinking of using a reference stored on the player, like ply.lastusedragdoll, where the last ragdoll the player pressed use on is stored

You could send the :EntIndex() of the ragdoll with the concommand to the server.

Uhmmm how do I set the key of a table to nil, or how do I remove the key from the table completely, what I’m trying to do is:

if table.HasValue( ragObj.holster, decoded.class ) then
// Set ragObj.holster[decoded.class] to nil, both the key and value

btw, ragObj.holster[decoded.class] contains a table with the value decoded.class inside

If I understand Lua tables correctly, they’re set up nicely such that you can always attempt to access a value at any index without getting an exception (research the __index metamethod). So you can’t ever really set a “key” to nil, only a value. If you use an index for which a value is not stored, it just returns nil. i.e.

[lua]local t = {};
t.a = 5;
print(t.a); – prints 5
t.a = nil;
print(t.a) – prints nil
print(t.b) – prints nil

It’s as simple as that.

[editline]14th February 2011[/editline]

When I do this it does not say “And its nil”

Basically, how do I remove a key completely, when the key is a string