Well,
This is the question..
How to call the player(as a table) on a hook?
Just like concommand..
For concommand, I can use:
RunConsoleCommand()
ply:ConCommand()
But, how to do it with the hook?
Here is the function i'm using:
[lua]function VerificarTime(ply, team)
return ply:IsAdmin()
end
hook.Add("PlayerCanJoinTeam", "PodeEntrar", VerificarTime)[/lua]
And I need to call from another file, to verify that..
PS.: The language I'm writing is Portuguese.. (On the code obviously :) )
Yeah, you pass an argument like "ply" just like that. What's wrong? That should be the correct syntax.
I guess you didn't understand..
I mean that how should I call the hooked function with parameters you know..
Here is the rest:
[lua]
Time5 = vgui.Create("DButton", Time)
Time5:SetPos(100, 205)
Time5:SetSize(60, 45)
Time5:SetText("Policia")
Time5.DoClick = function()
RunConsoleCommand("rpbr_time", "5")
Time:Close()
end
[/lua]
I would like to call that function hooked, before running that Console Command, you know?
PS.: This code above, is inside cl_init.lua
The hook is on init.lua
I think what you're looking for is [url="http://wiki.garrysmod.com/?title=User_Messages"]User Messages[/url]
You can get the player object in a number of ways. You can use [b][url=http://wiki.garrysmod.com/?title=G.Entity]G.Entity [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] if you know the entity ID of the player, or you can try to find the player you want in the table returned by [b][url=http://wiki.garrysmod.com/?title=Player.GetAll]Player.GetAll [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b].
[lua]
Time5.DoClick = function()
if hook.Call("CanPlayerJoinTeam",nil,LocalPlayer()) then
RunConsoleCommand("rpbr_time", "5")
Time:Close()
end
end
[/lua]
Something like that?
Yes, like that.
I'll try it, and tell if worked or not.
[b]Edit[/b]
It worked fine. Thanks :D
Sorry, you need to Log In to post a reply to this thread.