hook.Add("PlayerCanPickupWeapon", "RespawnTrigger", function(ply,wep)
local nextclass, nextpos, nextang = wep:GetClass(), wep:GetPos(), wep:GetAngles()
if wep:GetClass() == "weapon_smg1" and !ply:HasWeapon("weapon_physcannon") then
timer.Simple(30,function()
local ent = ents.Create(nextclass)
ent:SetPos( nextpos )
ent:SetAngles( nextang )
ent:Spawn()
local entphys = ent:GetPhysicsObject();
if entphys:IsValid() then
entphys:EnableMotion(false)
return true
else
nextclass:EquipAmmo()
return false
end
end)
end
end)
Near and at the timer
Where did I go wrong?
[editline]16th December 2015[/editline]
For anyone who can’t understand
This is a script to respawn an smg1 if you are holding a physcannon, and it will respawn in 30 seconds…
One thing that might be setting you back is your reference to nextclass, nextpos, and nextang in the timer function, as they’ve been declared as local variables in the hook function, which will expire and go away a long time before the thirty seconds are finished and the timer starts.
Just to debug, try globalizing your variables and see if that affects anything.
They do not expire thats not the issue, your problem is still returning true or false from within the timer, you can not affecte the hook by that as I mentioned in your previous thread.
To simplify what I mean:
[lua]hook.Add(“PlayerCanPickupWeapon”, “test1”, function(ply, wep)
return true – Will work
end)[/lua]
[lua]hook.Add(“PlayerCanPickupWeapon”, “test1”, function(ply, wep)
timer.Simple(1, function()
return true – Executed later, will NOT work on the hook.
end)
– Leaving at this point has the return value nil
end)[/lua]
Also if you say “This is a script to respawn an smg1 if you are holding a physcannon” then it should be
[lua]
if wep:GetClass() == “weapon_smg1” and IsValid(ply:GetActiveWeapon()) and ply:GetActiveWeapon():GetClass() == “weapon_physcannon” then
[/lua]
EDIT: God damnit, editing posts with lua is awful.
Ok thanks again for the support. I’ll take a look and mark as solved if I get home and it all works.
Know where I can understand Garry’s Mod’s lua language?
Hey I do not get it still…
Since I only know Gmod lua wiki and it barely has any descriptions, I do not know how this works, but
Here’s the first three lines of the code I tried
I also put a end) at the line under return true.
I got this error:
And I tried fixing it, removing the end), because really I believe if I put an end) right after it, then the hook would end there without continuing with the rest of the features of the code.
When I tried it without end)
I got this:
Full code:
hook.Add("PlayerCanPickupWeapon", "RespawnTrigger", function(ply,wep)
return true
end)
local nextclass, nextpos, nextang = wep:GetClass(), wep:GetPos(), wep:GetAngles()
if wep:GetClass() == "weapon_smg1" and !ply:HasWeapon("weapon_physcannon") then
timer.Simple(30,function()
local ent = ents.Create(nextclass)
ent:SetPos( nextpos )
ent:SetAngles( nextang )
ent:Spawn()
local entphys = ent:GetPhysicsObject();
if entphys:IsValid() then
entphys:EnableMotion(false)
else
nextclass:EquipAmmo()
return false
end
end)
end
end)
No I do not expect you to do everything for me (I promise) It’s just, one simply can’t do anything in a code for a game that uses its own syntax and it’s wiki for the syntax has no description.
I just don’t know what they do.
I need to fix this error and everything so this problem can be solved.
Many people have seemed to want it, and on a server idea I need it to work.
Thanks for the support, but unfortunately from here I have no clue what to do next.
Take your time, I am asking for help, so I can’t complain if it takes a while for you to reply (I’m sure you have much better things to be doing right now)
but it’d really make my day.
Then why do I put c++ code in and it doesn’t do crap, because the objects and stuff I need to interact with, are using gmod’s own language?
I can’t simply LEARN LUA WITHOUT A DAMN TUTORIAL.
It’s frustrating that I cannot finish an easy script.
So I ask, do you even know how to fix it?
If not, I won’t so telling me to learn lua basically means that I will have to close down my server or maybe edit each map with source-fucking sdk broken hammer and spend countless days on editing the maps, losing custom textures and have weird shit happen to the map due to decompiling.
hook.Add("PlayerCanPickupWeapon", "RespawnTrigger", function(ply,wep)
return true
end) -- ENDS THE HOOK, AND WITH THAT DOESNT RUN THE CODE BELOW!!
-- All the rest of the NOT RAN code
AwfulRanger,
It’s like you are trying to prove a point to every post I made.
It’s time I do the same…
2: I have used google countless times, why don’t you use google first to figure out why I can’t find any tutorials good enough for GMOD LUA to learn off of.
3: I do understand c++ which is used in everything except modules, as you just now said (are you dumb?)
4: I never said Hammer didn’t work, but if you don’t know any problems in it you’ve only spent a few minutes on it. And it would take forever to edit the maps, because that’s my point.
STOP
You are ALWAYS creating this stupid thread and we ALWAYS tell you to stop being a dick…You are getting banned, ignored, flawed and you keep doing the damn same questions over and over and over…Stop wasting everyones time (Including your time in asking and creating alt accounts) and hire someone