Eliminate specific weapons through lua (Hammer Editor) also poorly translated :)
5 replies, posted
Hi, well, I want to be quite honest, so here goes my story.
I'm creating a map for gmod. which is a campaign of cooperative horror. It turns out that on my map I have put a weapon which simulates parkour (Climb SWEP 2 from the gmod workshop).
in my map gameplay tests. everything works fine, when going through a Trigger what it does is eliminate that weapon (OnTrigger - climb_swep2 - Kill). in singleplayer mode there is no problem, the problem starts when you are playing with people. When a player goes through this trigger while one of the players has the climb swep, this is eliminated by interrupting the process of advancing with parkour.
What I'm looking for specifically is some lua code, which, when a player goes through a trigger, the weapon is eliminated to the player who goes through that trigger, not to the other players.
What I had in mind was to use a lua code through a hammer. since I believe it is much more specific in what one wants to do.
Looking through Google I have found some commands that I think may work. Both work but have their side effects.
Using this code.
player.GetByID (1): StripWeapon ([[climb_swep2]])
When going through a trigger that activates it removes the weapon but only a single player (in this case mine), a friend trying to help me, when he goes through that trigger he is not affected, he still had the parkour weapon.
I tried with this other code too...
for i, ply in pairs (player.GetAll ()) do if (ply: IsValid ()) then ply: StripWeapon ([[climb_swep2]]) end end
when going through the trigger Eliminate all parkour weapons, including that of other players who have not even touched the trigger. In other words, exactly the same thing happens when doing it through a hammer.
I have 0 knowledge about writing lua codes.
I hope you can help me because the map is almost finished, it only remains to fix small mistakes like the one I'm presenting now, I am getting impatient to upload it to the workshop so that people can play my map 🥰.
Thanks for taking the time to read this thread.
The first code looks up the first player on the server and removes his weapon, so if your friend was the first one to join the server and you were the one going through the trigger it would remove his weapon.
The second one is a for loop that goes through all the players in the server and removes their weapons.
I'm not familiar with hammer enough to know what variables can be used inside a trigger so I'll just give you a simple script to remove weapons in an area:
local triggerPos = Vector(0, 0, 0)
local triggerSize = Vector(300, 300, 300)
local plyFound = ents.FindInBox(triggerPos - triggerSize/2, triggerPos + triggerSize/2)
for _, ply in pairs(plyFound) do
if(IsValid(ply)) then
ply:StripWeapon("climb_swep2")
end
end
Replace triggerPos with the position where the trigger is found in and replace triggerSize with the size of the trigger.
player.GetByID (1): StripWeapon ([[climb_swep2]])
Try ACTIVATOR, CALLER or TRIGGER_PLAYER instead of player.GetByID (1), they are special magic global variables for the lua_run entity that should be what you are looking for.
thanks ubre for your answer. about lua in hammer, there are certain characters that I can not use, for example if I want to use ply: StripWeapon ("climb_swep2"), that ("climb_swep2") ruins the lua_run (the entity that uses hammer to execute lua), in that case I should use ply: StripWeapon ([[climb_swep2]]). all the code that you have given me would not know how to put it in that entity in hammer.
Could you help me how to order it and put it in hammer ?, I would appreciate it very much.
I have some lua codes on my map, I will leave it here so you can see how it is more or less the structural form in which I should go in the entity.
for i, ply in pairs(player.GetAll()) do if (ply:IsValid()) then ply:AllowFlashlight(true) end end
for i, ply in pairs(player.GetAll()) do if (ply:IsValid()) then ply:ConCommand([[act dance]]) end end
local function DisableNoclip( ply ) return false end hook.Add( [[PlayerNoClip]], [[DisableNoclip]], DisableNoclip )
function GAMEMODE:PlayerSpawnSWEP( ply, class, info ) return false end
He means that all the code you need to strip the weapon is
ACTIVATOR:StripWeapon([[climb_swep2]])
Thank you very much guys for your help, it worked perfectly 🥰🥰🥰🥰🥰🥰🥰
Sorry, you need to Log In to post a reply to this thread.