Jump to content
heizung124

Catch Key press in Mod

Recommended Posts

The key pressing and corresponding actions/update on server are done via rpc from what I've read.

Corey on Discord shared the following as a quick example how can you send an RPC on key press, way over my head but maybe helpful for you.

This goes into your missionGameplay onKeypress

if ( key == KeyCode.KC_O )
        {
            ScriptRPC rpc = new ScriptRPC();
            rpc.Write("string");
            rpc.Write(1);
            rpc.Write(12.5);
            rpc.Send(null, M_RPCs.M_TEST, true);
        }

so if you press O, it will forge the RPC, fill with desired data then send it to the server

  • Thanks 1

Share this post


Link to post
Share on other sites
1 hour ago, smasht said:

The key pressing and corresponding actions/update on server are done via rpc from what I've read.

Corey on Discord shared the following as a quick example how can you send an RPC on key press, way over my head but maybe helpful for you.

This goes into your missionGameplay onKeypress


if ( key == KeyCode.KC_O )
        {
            ScriptRPC rpc = new ScriptRPC();
            rpc.Write("string");
            rpc.Write(1);
            rpc.Write(12.5);
            rpc.Send(null, M_RPCs.M_TEST, true);
        }

so if you press O, it will forge the RPC, fill with desired data then send it to the server

Nice exactly what i was looking for
thanks

 

Edit but does not work

 

override void OnKeyPress( int key )
	{
		Print("key releae" + key) // does not print
		super.OnKeyRelease( key );

		if ( key == KeyCode.KC_T ) 
		{
			Print("key press" + key + "t") // surly does not print
			GetPlayer().MessageStatus( "Key pressed" ); //same
		}
	}

Any Idea?

Edited by heizung124

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×