• [HELP] Return weapons when dead !returnweapons
    23 replies, posted
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! -Emil
[QUOTE=EmilGran;48270399]I would like to request a lua script[/QUOTE] 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!. -Emil
[QUOTE=EmilGran;48270885]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!. -Emil[/QUOTE] 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 [URL="http://wiki.garrysmod.com/page/Main_Page"]gmod wiki[/URL] 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 : [url]http://wiki.garrysmod.com/page/Player/GetWeapons[/url] and here : [url]http://wiki.garrysmod.com/page/GM/PlayerDeath[/url]
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!. -Emil
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.
[code] 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 [/code] 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.
[QUOTE=Nick78111;48271694]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.[/QUOTE] 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?
[QUOTE=Chimpanzee;48271908]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?[/QUOTE] You store the table on the player entity so there is a maximum of 1 table per player.
[QUOTE=Chimpanzee;48271908]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?[/QUOTE] 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.
[QUOTE=wh1t3rabbit;48272179]You store the table on the player entity so there is a maximum of 1 table per player.[/QUOTE] Wouldn't the server still need to run a query for the table each time the player dies?
[QUOTE=Chimpanzee;48272437]Wouldn't the server still need to run a query for the table each time the player dies?[/QUOTE] From the way you keep saying query I get the impression your thinking of mysql/database storage. We're talking about regular lua table. [lua] hook.Add("PlayerDeath", "Save weapons on death", function(ply) ply.SavedWeapons = {} for k,v in pairs(ply:GetWeapons()) do ply.SavedWeapons[v:GetClass()] = true end end) hook.Add("PlayerSpawn", "Restore weapons", function(ply) if not ply.SavedWeapons then return end for k,v in pairs(ply.SavedWeapons) do ply:Give(k) end end) [/lua] 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? [CODE]for k,v in pairs(ply:GetWeapons()) do[/CODE] ply.SavedWeapons[v:GetClass()] = true end Thanks for reply! -Emil
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 [url]http://wiki.garrysmod.com/page/Main_Page[/url]
[QUOTE=EmilGran;48274118]Where can i learn this command? [CODE]for k,v in pairs(ply:GetWeapons()) do[/CODE] ply.SavedWeapons[v:GetClass()] = true end Thanks for reply! -Emil[/QUOTE] Not sure exactly what you mean by 'learn this command' Learning basic lua stuff [url]http://facepunch.com/showthread.php?t=1337945[/url] [URL="http://lua-users.org/wiki/TablesTutorial"]Tables tutorial[/URL] [URL="http://lua-users.org/wiki/ForTutorial"]for and pairs[/URL] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Player/GetWeapons]Player:GetWeapons[/url] [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetClass]Entity:GetClass[/url]
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! -Emil
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
Okay Chimpanzee i understand, i tried made this but i dont understand whats wrong? [CODE] -- Get Weapons -- function FindPlayers(name) local matches = {} for k, v in pairs(player.GetAll()) do if (v:GetName():lower():match(name:lower())) then table.insert(matches, v) end end if (table.Count(matches) == 0 ) then MsgN("[GETWEPS] No Players Found!") return false end if (table.Count(matches) > 1 ) then MsgN ("[GETWEPS] Multiple Players Found!") return false end return matches[1] end --[[Chat Command!]]-- hook.Add("PlayerSay", "getweps", function(ply, text, public) text = string.lower(text) if (string.sub(text, 0, 8) == "!getweps") then text = string.Explode(" ", text) local victim = FindPlayers(text[2]) if (IsValid(victim)) then print( victim:GetActiveWeapon():GetClass() ) end return "" end [/CODE]
How does this thread have 20 posts, and there's still an issue? Here's a fixed version of yours, with comments. [lua] local canuse = {["superadmin"] = true, ["admin"] = true} //allows for certain usergroups to use this. hook.Add("PlayerSay", "shit", function(ply, text) if (string.sub(text, 1, 8) == "!getweps") then if (!canuse[ ply:GetUserGroup() ]) then return "" end //check to see if our rank can use this. add "user" if you want users to use it. or remove this line all together. local pts = string.Explode(text, " ") //see if we searched for another player local targ = ply //default to ourselves just in case. if (pts[ 2 ]) then for k,v in pairs(player.GetAll()) do if (v == ply) then continue end //if the target equalss ourselves, we skip this entry if (string.find(string.lower(v:Nick()), string.lower(pts[ 2 ]) )) then //try to find the search query in a players name, if so set the target to the them targ = v break //we found our target, why should we keep running the loop? end end end local len = #targ.Weapons //length of the weapon table(amount of entries) if (len == 0) then return "" end //no weapons targ:StripWeapons() //remove all current weapons for i=1, len do //loop through our table of weapons. remember, their weapons, so we have to grab their class to give it to the player. targ:Give( targ.Weapons[ i ]:GetClass() ) //give the weapon after getting its class end targ.Weapons = {} //reset to prevent spawm if (#targ.Ammo == 0) then return "" end //no ammo for k,v in pairs(targ.Ammo) do //loop through all our ammo types targ:GiveAmmo(k, v) //give the type with the amount end targ.Ammo = {} //reset to prevent spam end end) hook.Add("PlayerDeath", "SAveWeapons", function(ply) ply.Weapons = ply:GetWeapons() //get all the weapons ply.Ammo = {} //create our table. and overwrite it, if it exists. for i=1, #ply.Weapons do local wep = ply.Weapons[ i ] //index the weapon local type = wep:GetPrimaryAmmoType() //index the type of the ammo local count = ply:GetAmmoCount(type) //index the count of the ammo ply.Ammo[ type ] = count // set the ammo end end) [/lua]
crazyscouter, Thanks man i love you! SOLVED!!!!
I will have this script. Where do I place the file and What should the file be named?
Sorry, you need to Log In to post a reply to this thread.