feature(iw5: gsc): use preprocessor to deduplicate code (#308)

This commit is contained in:
Edo 2023-07-17 15:28:14 +02:00 committed by GitHub
parent 41efe26a48
commit dc707f75b3
5 changed files with 136 additions and 106 deletions

View File

@ -161,6 +161,8 @@ _SetDvarIfUninitialized( dvarName, dvarValue )
_GetPlayerFromClientNum( clientNum )
{
assertEx( clientNum >= 0, "clientNum cannot be negative" );
if ( clientNum < 0 )
{
return undefined;
@ -540,6 +542,7 @@ AddClientCommand( commandName, shouldRunAsTarget, callback, shouldOverwrite )
OnClientDataReceived( event )
{
assertEx( isDefined( self ), "player entity is not defined");
clientData = self.pers[level.clientDataKey];
if ( event.subtype == "Fail" )

View File

@ -1,5 +1,7 @@
#include common_scripts\utility;
#inline scripts\_integration_utility;
Init()
{
thread Setup();
@ -82,10 +84,7 @@ WaitTillAnyTimeout( timeOut, string1, string2, string3, string4, string5 )
GiveWeaponImpl( event, data )
{
if ( !IsAlive( self ) )
{
return self.name + "^7 is not alive";
}
_IS_ALIVE( self );
self IPrintLnBold( "You have been given a new weapon" );
self GiveWeapon( data["weaponName"] );
@ -96,10 +95,7 @@ GiveWeaponImpl( event, data )
TakeWeaponsImpl()
{
if ( !IsAlive( self ) )
{
return self.name + "^7 is not alive";
}
_IS_ALIVE( self );
self TakeAllWeapons();
self IPrintLnBold( "All your weapons have been taken" );
@ -109,10 +105,7 @@ TakeWeaponsImpl()
TeamSwitchImpl()
{
if ( !IsAlive( self ) )
{
return self + "^7 is not alive";
}
_IS_ALIVE( self );
team = level.allies;
@ -130,10 +123,7 @@ TeamSwitchImpl()
LockControlsImpl()
{
if ( !IsAlive( self ) )
{
return self.name + "^7 is not alive";
}
_IS_ALIVE( self );
if ( !IsDefined ( self.isControlLocked ) )
{
@ -170,6 +160,8 @@ LockControlsImpl()
NoClipImpl()
{
_VERIFY_PLAYER_ENT( self );
if ( !IsAlive( self ) )
{
self IPrintLnBold( "You are not alive" );
@ -215,10 +207,11 @@ NoClipImpl()
HideImpl()
{
_VERIFY_PLAYER_ENT( self );
if ( !IsAlive( self ) )
{
self IPrintLnBold( "You are not alive" );
return;
}
if ( !IsDefined ( self.isHidden ) )
@ -274,6 +267,8 @@ GotoImpl( event, data )
GotoCoordImpl( data )
{
_VERIFY_PLAYER_ENT( self );
if ( !IsAlive( self ) )
{
self IPrintLnBold( "You are not alive" );
@ -287,6 +282,8 @@ GotoCoordImpl( data )
GotoPlayerImpl( target )
{
_VERIFY_PLAYER_ENT( self );
if ( !IsAlive( target ) )
{
self IPrintLnBold( target.name + " is not alive" );
@ -299,10 +296,7 @@ GotoPlayerImpl( target )
PlayerToMeImpl( event )
{
if ( !IsAlive( self ) )
{
return self.name + " is not alive";
}
_IS_ALIVE( self );
self SetOrigin( event.origin GetOrigin() );
return "Moved here " + self.name;
@ -310,10 +304,7 @@ PlayerToMeImpl( event )
KillImpl()
{
if ( !IsAlive( self ) )
{
return self.name + " is not alive";
}
_IS_ALIVE( self );
self Suicide();
self IPrintLnBold( "You were killed by " + self.name );
@ -323,6 +314,8 @@ KillImpl()
SetSpectatorImpl()
{
_VERIFY_PLAYER_ENT( self );
if ( self.pers["team"] == "spectator" )
{
return self.name + " is already spectating";

View File

@ -0,0 +1,40 @@
/*
* This file contains reusable preprocessor directives meant to be used on
* Plutonium & AlterWare clients that are up to date with the latest version.
* Older versions of Plutonium or other clients do not have support for loading
* or parsing "gsh" files.
*/
/*
* Turn off assertions by removing the following define
* gsc-tool will only emit assertions if developer_script dvar is set to 1
* In short, you should not need to remove this define. Just turn them off
* by using the dvar
*/
#define _INTEGRATION_DEBUG
#ifdef _INTEGRATION_DEBUG
#define _VERIFY( cond, msg ) \
assertEx( cond, msg )
#else
// This works as an "empty" define here with gsc-tool
#define _VERIFY( cond, msg )
#endif
// This function is meant to be used inside "client commands"
// If the client is not alive it shall return an error message
#define _IS_ALIVE( ent ) \
_VERIFY( ent, "player entity is not defined" ); \
if ( !IsAlive( ent ) ) \
{ \
return ent.name + "^7 is not alive"; \
}
// This function should be used to verify if a player entity is defined
#define _VERIFY_PLAYER_ENT( ent ) \
_VERIFY( ent, "player entity is not defined" )

View File

@ -3,14 +3,7 @@
Allows integration of IW4M-Admin to GSC, mainly used for special commands that need to use GSC in order to work.
But can also be used to read / write metadata from / to a profile and to get the player permission level.
## Installation Plutonium IW5
## Installation Guide
Move `_integration.gsc` to `%localappdata%\Plutonium\storage\iw5\scripts\`
## Installation IW4x
Move `_integration.gsc` to `IW4x/userraw/scripts`, `IW4x` being the root folder of your game server.
The documentation can be found here: [GameInterface](https://github.com/RaidMax/IW4M-Admin/wiki/GameInterface)

View File

@ -4,6 +4,7 @@ ECHO "Pluto IW5"
xcopy /y .\GameInterface\_integration_base.gsc "%LOCALAPPDATA%\Plutonium\storage\iw5\scripts"
xcopy /y .\GameInterface\_integration_shared.gsc "%LOCALAPPDATA%\Plutonium\storage\iw5\scripts"
xcopy /y .\GameInterface\_integration_iw5.gsc "%LOCALAPPDATA%\Plutonium\storage\iw5\scripts"
xcopy /y .\GameInterface\_integration_utility.gsh "%LOCALAPPDATA%\Plutonium\storage\iw5\scripts"
xcopy /y .\AntiCheat\IW5\storage\iw5\scripts\_customcallbacks.gsc "%LOCALAPPDATA%\Plutonium\storage\iw5\scripts\mp"
ECHO "Pluto T5"
@ -13,8 +14,8 @@ xcopy /y .\GameInterface\_integration_t5.gsc "%LOCALAPPDATA%\Plutonium\storage\t
xcopy /y .\GameInterface\_integration_t5zm.gsc "%LOCALAPPDATA%\Plutonium\storage\t5\scripts\sp\zom"
ECHO "Pluto T6"
xcopy /y .\AntiCheat\PT6\storage\t6\scripts\mp\_customcallbacks.gsc "%LOCALAPPDATA%\Plutonium\storage\t6\scripts\mp"
xcopy /y .\GameInterface\_integration_base.gsc "%LOCALAPPDATA%\Plutonium\storage\t6\scripts"
xcopy /y .\GameInterface\_integration_shared.gsc "%LOCALAPPDATA%\Plutonium\storage\t6\scripts"
xcopy /y .\GameInterface\_integration_t6.gsc "%LOCALAPPDATA%\Plutonium\storage\t6\scripts"
xcopy /y .\GameInterface\_integration_t6zm_helper.gsc "%LOCALAPPDATA%\Plutonium\storage\t6\scripts\zm"
xcopy /y .\AntiCheat\PT6\storage\t6\scripts\mp\_customcallbacks.gsc "%LOCALAPPDATA%\Plutonium\storage\t6\scripts\mp"