• custom hooks or events?
    10 replies, posted
Is it possible to have a trigger multiple on a map that when it is triggered a hook used? example code would be just fabulous. As always thanks for your time and anything helps. :P P.S. if that's not possible then how does the lua_run work and how can i use it?
[b][url=http://wiki.garrysmod.com/?title=Hook.Call]Hook.Call [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] [b][url=http://wiki.garrysmod.com/?title=Lua_run_(entity)]lua run (entity) [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] Code the the lua_run entity : [lua]if ValidEntity(TRIGGER_PLAYER) then hook.Call( "MyAwesomeCustomHook", nil, TRIGGER_PLAYER) end[/lua] Code for your gamemode : [lua]hook.Add("MyAwesomeCustomHook", function(ply) print(ply.." Activated MyAwesomeCustomHook") end)[/lua] Notes : * Any argument after nil in hook.Call will also be passed to the function used in hook.Add. * If you want to use a gamemode hook (GM:Blah) you will have to replace nil by a reference to the gamemode table. * All of this is untested, especially the lua_run part as I am no mapper. Hopefully the wiki documentation should be good enough. :eng101:
[QUOTE=Crazy Quebec;21613144][b][url=http://wiki.garrysmod.com/?title=Hook.Call]Hook.Call [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] [b][url=http://wiki.garrysmod.com/?title=Lua_run_(entity)]lua run (entity) [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] Code the the lua_run entity : [lua]if ValidEntity(TRIGGER_PLAYER) then hook.Call( "MyAwesomeCustomHook", nil, TRIGGER_PLAYER) end[/lua] Code for your gamemode : [lua]hook.Add("MyAwesomeCustomHook", function(ply) print(ply.." Activated MyAwesomeCustomHook") end)[/lua] Notes : * Any argument after nil in hook.Call will also be passed to the function used in hook.Add. * If you want to use a gamemode hook (GM:Blah) you will have to replace nil by a reference to the gamemode table. * All of this is untested, especially the lua_run part as I am no mapper. Hopefully the wiki documentation should be good enough. :eng101:[/QUOTE] thanks :D
Though hook.Call works aswell, this is the proper function to use [b][url=http://wiki.garrysmod.com/?title=Gamemode.Call]Gamemode.Call [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[QUOTE=ralle105;21614421]Though hook.Call works aswell, this is the proper function to use [b][url=http://wiki.garrysmod.com/?title=Gamemode.Call]Gamemode.Call [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b][/QUOTE] That's only valid if you're coding a gamemode you know will have this hook defined as a gamemode function. hook.Call( name, game.GetGamemode(), ... ) is probably the best form, as mentioned on gamemode.Call.
umm im getting the unexpected symbol near '<eof>' ??? :ohdear:
post the code
[QUOTE=|King Flawless|;21633842]post the code[/QUOTE] same code that he used as an example -_-
You didn't tell us what triggered the error and didn't even post the full error. By "the code" it is implied the full file where the error is occuring. The code I posted can not error on it's own. Rule #1 of programming : It's always your fault.
never mind i just have to brain storm a bit and im sure i will figure it out. thanks anyway and yea it probably is my fault
[QUOTE=Crazy Quebec;21634589]You didn't tell us what triggered the error and didn't even post the full error. By "the code" it is implied the full file where the error is occuring. The code I posted can not error on it's own. Rule #1 of programming : It's always your fault.[/QUOTE] Your trying to print the ply object, not the name name. That could be one source of error.. [lua]hook.Add("MyAwesomeCustomHook", function(ply) print(ply.." Activated MyAwesomeCustomHook") end)[/lua] Is the code i'm talking about btw
Sorry, you need to Log In to post a reply to this thread.