[HELP] Return weapons when dead !returnweapons

Hello Facepunch Members.

I would like to request a lua script if some of you will help me, i really need it to my server,.:

So, Lets say someone rdm a person and i want to return his weapons he got before his dead.

Then i want to say !returnweapons bob (Or what his name is)

Hope some of you want to help me, thanks!


Wrong place buddy

You’d have to run a call with OnDeath to grab all the weapons the person had and store them in somewhere like PData, then add another command to grab those weapons and remit them. I wouldn’t recommend this as it’d end up in a lot of unused data and it would probably end up lagging the shit out of your server

Hello Chimpanzee.
Thanks for your reply i appreciate it!.
Can you make a code for me, im good to learn at reading codes and then i can try by my own hand!.

Hope you wanna make the code!.


Maybe you didn’t understand what I’m trying to say. This is a terribly bad idea unless you run a timer to delete the data after a minute or so of dying, but then people wouldn’t get admin help in enough time. I guess you could also delete all the data on server restart but I’m not quite sure how to go about that yet. What I’m trying to say is sorry, but I won’t make the code because I’d rather not lol. Just look up on the gmod wiki how to use PData and OnDeath hooks, and look up some lua tutorials on youtube. It shouldn’t be too hard to figure out.

Once again, I do not recommend doing this. You could always use it to print a text of the player’s weapons to the admin instead of actually returning the weapons automatically, which would be a lot intensive. Btw, good places to start are here : http://wiki.garrysmod.com/page/Player/GetWeapons
and here : http://wiki.garrysmod.com/page/GM/PlayerDeath

But Chimpanzee im playing on a server calling “Stavox” (Only danish however you will get banned!)
they can do !returnweps and then they return all the weapons they got before they died :P.
But maybe its pretty hard!
Thanks for reply!.


You don’t understand what he is trying to tell you.

The idea is incredibly simple, that is not the problem. The implementation you have in mind is rather wasteful, which is what he is trying to tell you. If you store EVERY player’s weapons on death, but have it so only an admin can give the weapons back, that is going to cause a lot of data that is never used. The reason a lot of data will never be used is because not everyone is going to get RDMed, so you won’t be giving ever player their weapon back upon spawn.

Simply put, you are going to store a lot of information, and you are only going to use a small portion of it. Which is very wasteful.

PlayerDeath( Guy Who Died )
  Create a table on Guy Who Died
  for each of Guy Who Died's weapons
    Create a row that contains the class name of the weapon

Your Chat Command
  Check if they have a weapon table from the above function
  Strip their current weapons
  for each entry
    Give them that weapon

  Remove the weapon table

PlayerDeath is called before the player is actually dead ( see PostPlayerDeath ), so they should still have their weapons at that point.

This would mean they can’t just store weapons across multiple deaths - if they die without claiming, the stash gets overwrote with their new set of weapons.

There’s no way that is better, and the data storage is incredibly minimal - a flat table of strings of the weapon class, tied to their player object. The data is only changed at one point - when they die - and only referenced in one place - that chat command.

Yeh I don’t understand why Chimpanzee is saying it is going to be resource intensive to store a table of strings…

Listen to Kogitsune.

So if he gets 50 people on his server and every time they die, which would be quite often, the server runs a query each time, you don’t think that would cause even the slightest bit of distress?

You store the table on the player entity so there is a maximum of 1 table per player.

Do you even understand how much data is being written, stored, and sent as is? Storing a table of strings will not created any stress what so ever.

Wouldn’t the server still need to run a query for the table each time the player dies?

From the way you keep saying query I get the impression your thinking of mysql/database storage. We’re talking about regular lua table.

hook.Add(“PlayerDeath”, “Save weapons on death”, function(ply)
ply.SavedWeapons = {}
for k,v in pairs(ply:GetWeapons()) do
ply.SavedWeapons[v:GetClass()] = true

hook.Add(“PlayerSpawn”, “Restore weapons”, function(ply)
if not ply.SavedWeapons then return end
for k,v in pairs(ply.SavedWeapons) do

That’s basically it. Would need some improvements to give back the correct amount of ammo, and should probably strip any exisiting weapons before restoring them.

I think these times are when you realize you should probably get some sleep. Apologies for my impotence/incompetence.

I was thinking of lua tables as well but I believed that (for some god forsaken reason that must be linked to a sleep deficit) lua tables get stored outside of the server.

Where can i learn this command?

for k,v in pairs(ply:GetWeapons()) do

    ply.SavedWeapons[v:GetClass()] = true

Thanks for reply!


what? learn? who? what? you’ve been fed the command, you don’t need to learn it. if you’re really trying to actually learn something, go http://wiki.garrysmod.com/page/Main_Page

Not sure exactly what you mean by ‘learn this command’

Learning basic lua stuff http://forum.facepunch.com/showthread.php?t=1337945

Tables tutorial
for and pairs



Any of you can make the code for me, you know where i can get printed the weapons the person had before he died?
Thanks for reply!


We’ve already told you how to do it. I’d bet nobody wants to sit here and force feed the 100% finished and completed script for you. If you want a server, learn how to do work for it yourself