Hey there, hopefully by reading this, you may have some advice for me :3
Okay, so, I started to learn Lua a few days ago, and I think I have gotten to grips with it (kinda), so, my question is:
If I searched the wiki and found something I'd like on a server I administrate, what should I do then?
For example:
[b][url=wiki.garrysmod.com/?title=Gamemode.DoPlayerDeath]Gamemode.DoPlayerDeath [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
(This would be my first real try at Lua)
Thanks for reading. :D
Umhh what?
[QUOTE=Joker213;24708785]Hey there, hopefully by reading this, you may have some advice for me :3
Okay, so, I started to learn Lua a few days ago, and I think I have gotten to grips with it (kinda), so, my question is:
If I searched the wiki and found something I'd like on a server I administrate, what should I do then?
[b][url=wiki.garrysmod.com/?title=Gamemode.DoPlayerDeath]Gamemode.DoPlayerDeath [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
(This would be my first real try at Lua)
Thanks for reading. :D[/QUOTE]
[b][url=wiki.garrysmod.com/?title=Gamemode.DoPlayerDeath]Gamemode.DoPlayerDeath [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] is a Gamemode hook, so you should define a function and then add it to
[b][url=wiki.garrysmod.com/?title=Gamemode.DoPlayerDeath]Gamemode.DoPlayerDeath [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] with [b][url=http://wiki.garrysmod.com/?title=Hook.Add]Hook.Add [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b].
That way, whenever [b][url=wiki.garrysmod.com/?title=Gamemode.DoPlayerDeath]Gamemode.DoPlayerDeath [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] is called, so will your function.
You could also override the function itself, but that wouldn't be recommended unless you're making your own gamemode.
[QUOTE=Trivkz;24708929]Umhh what?[/QUOTE]
That question was hard to state xD
Sorry if it is barely readable. Also, as I stated, I started to learn the very basics a few days ago.
So sorry if I'm not up to your standards in understanding this stuff..
[QUOTE=Blargh123;24708948][b][url=wiki.garrysmod.com/?title=Gamemode.DoPlayerDeath]Gamemode.DoPlayerDeath [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] is a Gamemode hook, so you should define a function and then add it to
[b][url=wiki.garrysmod.com/?title=Gamemode.DoPlayerDeath]Gamemode.DoPlayerDeath [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] with [b][url=http://wiki.garrysmod.com/?title=Hook.Add]Hook.Add [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b].
That way, whenever [b][url=wiki.garrysmod.com/?title=Gamemode.DoPlayerDeath]Gamemode.DoPlayerDeath [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] is called, so will your function.
You could also override the function itself, but that wouldn't be recommended unless you're making your own gamemode.[/QUOTE]
Sorry if this sounds like a really idiotic question, but how would I override it? :3
[QUOTE=Joker213;24708995]That question was hard to state xD
Sorry if it is barely readable. Also, as I stated, I started to learn the very basics a few days ago.
Sorry if this sounds like a really idiotic question, but how would I override it? :3[/QUOTE]
DON"T DO IT MAN DON'T DO IT. :smithicide:
You'd just have to define the function again.
You're better off hooking another function to it though, I think redefining the function causes it to ignore every function added to it with hook.Add.
(For reminders: I started learning Lua 2 days ago)
I have this so far:
[lua]
function GM:DoPlayerDeath( ply, attacker, dmginfo )
ply:CreateRagdoll()
ply:AddDeaths( 1 )
if ( attacker:IsValid() && attacker:IsPlayer() ) then
if ( attacker == ply ) then
attacker:AddFrags( -1 )
else
attacker:AddFrags( 1 )
end
end
end
function GM:DoPlayerDeath(ply, attacker, dmginfo)
victim:PrintMessage(HUD_PRINTTALK,killer:Nick().." killed you!\n")
end
hook.Add("DoPlayerDeath","informTheVictims",GM:DoPlayerDeath)[/lua]
And when I try to test it, I get:
[lua\doplayerdeath.lua:25] function arguments expected near ')'
Any help would be appreciated! :D
EDIT: I also tried a falldamage script:
[lua]function GM:GetFallDamage( ply, speed )
return ( speed / 8 )
end
hook.Add("GetFallDamage", GM:GetFallDamage)[/lua]
That is what I ended up with after asking for help from a few people, I get this when I test it:
"[lua\getfalldamage.lua:4] function arguments expected near ')'"
I have no idea about this..
[QUOTE=Joker213;24712147](For reminders: I started learning Lua 2 days ago)
I have this so far:
[lua]
function GM:DoPlayerDeath( ply, attacker, dmginfo )
ply:CreateRagdoll()
ply:AddDeaths( 1 )
if ( attacker:IsValid() && attacker:IsPlayer() ) then
if ( attacker == ply ) then
attacker:AddFrags( -1 )
else
attacker:AddFrags( 1 )
end
end
end
function GM:DoPlayerDeath(ply, attacker, dmginfo)
victim:PrintMessage(HUD_PRINTTALK,killer:Nick().." killed you!\n")
end
hook.Add("DoPlayerDeath","informTheVictims",GM:DoPlayerDeath)[/lua]
And when I try to test it, I get:
[lua\doplayerdeath.lua:25] function arguments expected near ')'[/QUOTE]
There is not 25 lines in the code you posted, post the entire code please.
Sorry, you need to Log In to post a reply to this thread.