aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/scripts/vscripts/_networkvars.gnut
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-08-31 23:14:58 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-08-31 23:14:58 +0100
commit9a96d0bff56f1969c68bb52a2f33296095bdc67d (patch)
tree4175928e488632705692e3cccafa1a38dd854615 /Northstar.CustomServers/scripts/vscripts/_networkvars.gnut
parent27bd240871b7c0f2f49fef137718b2e3c208e3b4 (diff)
downloadNorthstarMods-9a96d0bff56f1969c68bb52a2f33296095bdc67d.tar.gz
NorthstarMods-9a96d0bff56f1969c68bb52a2f33296095bdc67d.zip
move to new mod format
Diffstat (limited to 'Northstar.CustomServers/scripts/vscripts/_networkvars.gnut')
-rw-r--r--Northstar.CustomServers/scripts/vscripts/_networkvars.gnut169
1 files changed, 0 insertions, 169 deletions
diff --git a/Northstar.CustomServers/scripts/vscripts/_networkvars.gnut b/Northstar.CustomServers/scripts/vscripts/_networkvars.gnut
deleted file mode 100644
index 14990a15..00000000
--- a/Northstar.CustomServers/scripts/vscripts/_networkvars.gnut
+++ /dev/null
@@ -1,169 +0,0 @@
-untyped
-
-
-global function SetEntityVar
-global function SetServerVar
-global function SetNetworkVar
-global function SyncServerVars
-global function SyncEntityVars
-
-
-function SetEntityVar( entity ent, varName, value )
-{
- Assert( IsServer() )
- Assert( varName in _entityClassVars[ent.GetClassName()], "Entity " + ent + " does not have remote var " + varName )
- Assert( varName in _entityClassVarsIsEnts[ent.GetClassName()] )
- Assert( varName in _entityClassVarsSyncToAllClients[ent.GetClassName()] )
- Assert( typeof value != "string" )
-
- Assert( "_entityVars" in ent )
-
- if ( ent._entityVars[varName] == value )
- return
-
- ent._entityVars[varName] = value
-
- if ( _entityClassVarsIsEnts[ent.GetClassName()][varName] && value != null )
- {
- //printl( "SET NETWORK ENTITY VAR TO AN ENTITY. GETTING EHANDLE" )
- value = value.GetEncodedEHandle()
- }
-
- local syncToAllPlayers = _entityClassVarsSyncToAllClients[ent.GetClassName()][varName]
-
- // only sync "player" variables to that player
- if ( ent.IsPlayer() && !ent.IsBot() && !syncToAllPlayers )
- {
- if ( !ent.p.clientScriptInitialized )
- return
-
- Remote_CallFunction_NonReplay( ent, "ServerCallback_SetEntityVar", ent.GetEncodedEHandle(), _entityClassVarHandles[varName], value )
- }
- else
- {
- array<entity> players = GetPlayerArray()
- foreach ( player in players )
- {
- if ( player.IsBot() )
- continue
-
- if ( !player.p.clientScriptInitialized )
- continue
-
- Remote_CallFunction_NonReplay( player, "ServerCallback_SetEntityVar", ent.GetEncodedEHandle(), _entityClassVarHandles[varName], value )
- }
- }
-}
-
-function SetServerVar( varName, value )
-{
- Assert( IsServer() )
- Assert( varName in _serverVars )
- Assert( typeof value != "string" )
- expect string( varName )
-
- if ( _serverVars[varName] == value )
- return
-
- _serverVars[varName] = value
-
- if ( varName in _serverEntityVars && value != null )
- {
- if ( IsValid( value ) )
- value = value.GetEncodedEHandle()
- else
- value = null
- }
-
- // Run server script change callback if one exists
- thread ServerVarChangedCallbacks( varName )
-
- // Update the var on all clients
- array<entity> players = GetPlayerArray()
- foreach ( player in players )
- {
- if ( !player.p.clientScriptInitialized )
- continue
-
- Remote_CallFunction_NonReplay( player, "ServerCallback_SetServerVar", _serverVarHandles[varName], value )
- }
-}
-
-function SetNetworkVar( obj, varName, value )
-{
- if ( obj == level )
- {
- return SetServerVar( varName, value )
- }
- else
- {
- expect entity( obj )
- return SetEntityVar( obj, varName, value )
- }
-}
-
-function SyncServerVars( entity player )
-{
- Assert( IsServer() )
-
- foreach ( varName, value in _serverVars )
- {
- if ( varName in _serverEntityVars && value != null )
- {
- if ( IsValid( value ) )
- value = value.GetEncodedEHandle()
- else
- value = null
- }
-
- Remote_CallFunction_NonReplay( player, "ServerCallback_SetServerVar", _serverVarHandles[varName], value )
- }
-}
-
-function SyncEntityVars( entity player )
-{
- Assert( IsServer() )
-
- foreach ( className, _ in _entityClassVars )
- {
- array<entity> entities
- if ( className == "player" )
- entities = GetPlayerArray()
- else
- entities = GetNPCArrayByClass( className )
-
- foreach ( ent in entities )
- {
- if ( !IsValid( ent ) )
- continue
-
- foreach( varName, value in _entityClassVars[className] )
- {
- local entValue = ent._entityVars[varName]
- if ( entValue == value )
- continue
-
- if ( !_entityClassVarsSyncToAllClients[className][varName] && ent != player )
- {
- Assert( className == "player" )
- continue
- }
- //if ( className == "player" && !_entityClassVarsSyncToAllClients[className][varName] )
- // continue
- //
- if ( _entityClassVarsIsEnts[className][varName] )
- {
- if ( !IsValid( entValue ) )
- continue
- // if this is an entity var, change over to e-handle
- entValue = entValue.GetEncodedEHandle()
- }
-
- Assert( player.p.clientScriptInitialized )
-
- Remote_CallFunction_NonReplay( player, "ServerCallback_SetEntityVar", ent.GetEncodedEHandle(), _entityClassVarHandles[varName], entValue )
- }
- }
- }
-}
-