• Need Help With A script
    11 replies, posted
Bassicly,Iam Trying to make A currently equipped swep/Entity Stay with the player if they quit and rejoin Would anyone know how to do that?
You would have to write the entities to a file or database
Untested, but should work fine. [CODE]local players = {} hook.Add("PlayerDisconnected", "SaveWeps", function(ply) local weps = ply:GetWeapons() // returns table with weapons local tbl = {} for _, wep in pairs(weps) do if IsValid(wep) then table.insert(tbl, wep:GetClass()) end end // So we're saving all weapons to the table on player disconnect. players[ply:SteamID()] = tbl end) hook.Add("PlayerInitialSpawn", "LoadoutSavedWeps", function(ply) // And here we're giving them back local weps = players[ply:SteamID()] if weps then for _, wep in pairs(weps) do ply:Give(wep) end players[ply:SteamID()] = nil end end)[/CODE]
[QUOTE=krekeris;48378841]Untested, but should work fine. [CODE]local players = {} hook.Add("PlayerDisconnected", "SaveWeps", function(ply) local weps = ply:GetWeapons() // returns table with weapons local tbl = {} for _, wep in pairs(weps) do if IsValid(wep) then table.insert(tbl, wep:GetClass()) end end // So we're saving all weapons to the table on player disconnect. players[ply:SteamID()] = tbl end) hook.Add("PlayerInitialSpawn", "LoadoutSavedWeps", function(ply) // And here we're giving them back local weps = players[ply:SteamID()] if weps then for _, wep in pairs(weps) do ply:Give(wep) end players[ply:SteamID()] = nil end end)[/CODE][/QUOTE] Alright thanks,But How could someone do it with a currently equipped entity such as a equipped helmet
[QUOTE=laithqakeesh;48378925]Alright thanks,But How could someone do it with a currently equipped entity such as a equipped helmet[/QUOTE] How is the helmet entity being applied to the player? Parented? Is there an accessor function you could call that would see if the player has a helmet? [editline]5th August 2015[/editline] [QUOTE=krekeris;48378841]Untested, but should work fine. [CODE]local players = {} hook.Add("PlayerDisconnected", "SaveWeps", function(ply) local weps = ply:GetWeapons() // returns table with weapons local tbl = {} for _, wep in pairs(weps) do if IsValid(wep) then table.insert(tbl, wep:GetClass()) end end // So we're saving all weapons to the table on player disconnect. players[ply:SteamID()] = tbl end) hook.Add("PlayerInitialSpawn", "LoadoutSavedWeps", function(ply) // And here we're giving them back local weps = players[ply:SteamID()] if weps then for _, wep in pairs(weps) do ply:Give(wep) end players[ply:SteamID()] = nil end end)[/CODE][/QUOTE] Until the server crashes/goes down :v:
[QUOTE=code_gs;48379058]How is the helmet entity being applied to the player? Parented? Is there an accessor function you could call that would see if the player has a helmet? [editline]5th August 2015[/editline] Until the server crashes/goes down :v:[/QUOTE] Using a function called "ArmorUpdate"
[QUOTE=laithqakeesh;48379092]Using a function called "ArmorUpdate"[/QUOTE] What's done in there? Is it parented to the player?
[QUOTE=code_gs;48379306]What's done in there? Is it parented to the player?[/QUOTE] It sets playermodel
Give the section of code that runs when the helmet is applied
[QUOTE=Chimpanzee;48380910]Give the section of code that runs when the helmet is applied[/QUOTE] function ENT:Use(activator,caller) if(activator:IsPlayer())then if((not(activator.Armor.Helmet))and(not(activator.Armor.Suit)))then ArmorUpdate(activator,"Helmet","HelmetA",self:GetColor()) activator:EmitSound("Flesh.ImpactSoft") JackaGenericUseEffect(activator) self:Remove() end end end
Player.Armor.Helmet is what you want to see it the player has it
[QUOTE=code_gs;48389247]Player.Armor.Helmet is what you want to see it the player has it[/QUOTE] He should change that because Armor is already a function on the player meta. Unless he turns Armor into a metatable and sets __call to the old Player.Armor function, he'll break a lot of stuff.
Sorry, you need to Log In to post a reply to this thread.