diff options
author | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2022-03-11 03:30:24 +0000 |
---|---|---|
committer | BobTheBob <32057864+BobTheBob9@users.noreply.github.com> | 2022-03-11 03:30:24 +0000 |
commit | dfaa2c1515665c9a4927fa3a0e6045421e0c135a (patch) | |
tree | 88556dc23a196f2393476c570c70d3a9cdb2daa3 /Northstar.CustomServers/mod/scripts/vscripts | |
parent | 846cd1efbb9e8c8de0f0c50ae90d271281c45719 (diff) | |
download | NorthstarMods-dfaa2c1515665c9a4927fa3a0e6045421e0c135a.tar.gz NorthstarMods-dfaa2c1515665c9a4927fa3a0e6045421e0c135a.zip |
script api for server=>client stringcmds
Diffstat (limited to 'Northstar.CustomServers/mod/scripts/vscripts')
-rw-r--r-- | Northstar.CustomServers/mod/scripts/vscripts/sh_server_to_client_stringcommands.gnut | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/Northstar.CustomServers/mod/scripts/vscripts/sh_server_to_client_stringcommands.gnut b/Northstar.CustomServers/mod/scripts/vscripts/sh_server_to_client_stringcommands.gnut new file mode 100644 index 00000000..a51e528f --- /dev/null +++ b/Northstar.CustomServers/mod/scripts/vscripts/sh_server_to_client_stringcommands.gnut @@ -0,0 +1,52 @@ +#if CLIENT +global function ServerToClientStringCommands_Init + +global function AddServerToClientStringCommandCallback +global function NSClientCodeCallback_RecievedServerToClientStringCommand +#endif + +#if SERVER +global function ServerToClientStringCommand +#endif + +#if CLIENT +struct { + table< string, array< void functionref( array<string> args ) > > callbacks +} file + +void function ServerToClientStringCommands_Init() +{ + getroottable().rawset( "NSClientCodeCallback_RecievedServerToClientStringCommand", NSClientCodeCallback_RecievedServerToClientStringCommand ) +} + +void function AddServerToClientStringCommandCallback( string command, void functionref( array<string> args ) callback ) +{ + if ( !( command in file.callbacks ) ) + file.callbacks[ command ] <- [] + + file.callbacks[ command ].append( callback ) +} + +void function NSClientCodeCallback_RecievedServerToClientStringCommand( string cmd ) +{ + array<string> args = split( cmd, " " ) + if ( args.len() == 0 ) + return + + string callbackName = args[ 0 ] + args.remove( 0 ) + + if ( callbackName in file.callbacks ) + { + foreach ( void functionref( array<string> args ) callback in file.callbacks[ callbackName ] ) + callback( args ) + } +} +#endif + +#if SERVER +void function ServerToClientStringCommand( entity player, string command ) +{ + ClientCommand( player, "ns_script_servertoclientstringcommand " + command ) +} +#endif
\ No newline at end of file |