Using hook.Call?

Could someone give me an example of how to use hook.Call, I need to simulate a player pressing a key, so that all the other scripts and the game itself would think the key was pressed manually, I’ve been told to use hook.Call, but I have no idea how to use it. So could someone write me a quick example of its usage?

I believe

hook.Call( String name, Table gm[, …] ) + GM:KeyPress( Player player, (IN_KEYS) key ) =


hook.Call( “KeyPress”, GAMEMODE, ply, IN_ATTACK)


Should call the KeyPress Hook saying ply pressed the attack button, this is un-tested, but may work, I’ve tried using hook.Call for something else, but can’t quite remember what it was.

Thank you.

[editline]13th March 2011[/editline]

I don’t get it, I’m using it on an addon and on sandbox gamemode, not working with your code. What should I use instead of the “GameMode” argument?

GAMEMODE is the correct argument. Post the code you’re calling it with.

hook.Call("KeyPress", GAMEMODE, Ply, IN_FORWARD)

Called every 0.2 seconds, basically this is just for testing if I can figure out how it works. It doesn’t do anything tho, also its being ran server side, Ply Arg is correct too.

You didn’t do what I told you to do.

Whats the point posting irrelevant code? Its being ran in a think hook every 0.2 seconds and its being ran serverside.

The entire point of you making this thread is so as we can help solve the problem in your code. Please explain how we’re meant to do that without your code.

well if you want help then you should just post it…

Oh for god sakes… I told you that first I’m testing if I can make it work, haven’t implemented it yet, heres the ServerSide test code:[LUA]hook.Add(“Think”, “Example_think”, function()
if !TimerVar or CurTime() >= TimerVar then
for _, ply in pairs(player.GetAll()) do
hook.Call(“KeyPress”, GAMEMODE, ply, IN_FORWARD)
TimerVar = CurTime()+ 0.2
end)[/LUA]Did exactly as mentioned above… So as I’ve said, irrelevant.

Do you have a KeyPress Hook somewhere else with a print statement in it, to see if it is maybe calling the hook but not making anything happen? Maybe the hook won’t actually make the player move forward, and is only used for reporting key presses.

You were right, it registers on the Hook.Call, but the game itself does not recognize them.

hey found something for you to try, use **[Player.ConCommand](** and the command +forward that player walk forward and the send -forward to stop.

[editline]15th March 2011[/editline]

just tested, and it worked

rcon lua_run player.GetAll()[1]:ConCommand('+forward')

and I started walking forward.

Forgot about the concommands. Thanks.