From 27b738625069ad22407f542693bd074ca2d9bdc6 Mon Sep 17 00:00:00 2001 From: ChocoTaco Date: Tue, 4 Jun 2019 00:43:15 -0400 Subject: [PATCH] Added Observer AFK options by DarkTiger --- Classic/prefs/serverPrefs.cs | 1 + Classic/scripts/autoexec/zDarkTigerAFK.cs | 133 ++++++++++++++++++++++ Classic/scripts/serverDefaults.cs | 5 +- 3 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 Classic/scripts/autoexec/zDarkTigerAFK.cs diff --git a/Classic/prefs/serverPrefs.cs b/Classic/prefs/serverPrefs.cs index 02038ef..47901c4 100644 --- a/Classic/prefs/serverPrefs.cs +++ b/Classic/prefs/serverPrefs.cs @@ -164,6 +164,7 @@ $Host::EvoTKWarn2 = 6; $Host::EvoTourneySameMap = 1; $Host::EvoUseHighPerformanceCounter = 0; $Host::FloodProtectionEnabled = 1; +$Host::ForceAFKObserverTime = 1; $Host::GameName = "Discord PU"; $Host::HiVisibility = "1"; $Host::holoName1 = "Storm"; diff --git a/Classic/scripts/autoexec/zDarkTigerAFK.cs b/Classic/scripts/autoexec/zDarkTigerAFK.cs new file mode 100644 index 0000000..5a5ed63 --- /dev/null +++ b/Classic/scripts/autoexec/zDarkTigerAFK.cs @@ -0,0 +1,133 @@ +//Observer AFK +//Script BY: DarkTiger +// +//TacoServer: +//Change to how many minutes to set forced Observer for AFK players +//Setting to 0 disables this feature +//$Host::ForceAFKObserverTime = 1; + +$dtVar::AFKtime = 60000 * $Host::ForceAFKObserverTime;//if player is afk specific amount of time, force them into observer +$dtVar::AFKloop = 1000 * 30;//loop check timer currently set to 30 secs + +//////////////////////////////////////////////////////////////////////////////// + +package afkScript +{ + +function GameConnection::onConnect(%client, %name, %raceGender, %skin, %voice, %voicePitch) +{ + Parent::onConnect( %client, %name, %raceGender, %skin, %voice, %voicePitch ); + + if($dtVar::AFKtime > 0) + %client.afkLoopCheck();// starts it +} + +}; + +// Prevent package from being activated if it is already +if (!isActivePackage(afkScript)) + activatePackage(afkScript); + + +//////////////////////////////////////////////////////////////////////////////// + + +function GameConnection::afkLoopCheck(%this) +{ + if(isObject(%this) && !%this.isAiControlled())// make sure client is still there other wise stop + %this.schedule($dtVar::AFKloop,"afkLoopCheck"); + else + return; + + if(isObject(%this.player) && %this.player.getState() !$= "Dead" && $matchStarted) + AFKChk(%this); +} + +function AFKChk(%client) +{ + if(%client.player.curTransform $= %client.player.getTransform())//checks to see if there position and rotation are the same. + { + //echo("is not moving"); + // error(%client.player.curTransform SPC %client.player.getTransform()); + %client.player.afkTimer += $dtVar::AFKloop; + if(%client.player.afkTimer >= $dtVar::AFKtime) + { + Game.AFKForceObserver(%client); + return; + } + } + else + { + //echo("is moving"); + %client.player.afkTimer = 0;//reset if moveing + } + + %client.player.curTransform = %client.player.getTransform();//save current transform +} + +function DefaultGame::AFKForceObserver(%game, %client) +{ + //make sure we have a valid client... + if (%client <= 0) + return; + + // first kill this player + if(%client.player) + %client.player.scriptKill(0); + + if( %client.respawnTimer ) + cancel(%client.respawnTimer); + + %client.respawnTimer = ""; + + // remove them from the team rank array + %game.removeFromTeamRankArray(%client); + + // place them in observer mode + %client.lastObserverSpawn = -1; + %client.observerStartTime = getSimTime(); + + + %client.camera.getDataBlock().setMode( %client.camera, "observerFly" ); + messageClient(%client, 'MsgClientJoinTeam', '\c2You have been placed into observer mode due to being AFK.', %client.name, %game.getTeamName(0), %client, 0 ); + logEcho(%client.nameBase@" (cl "@%client@") was forced into observer mode for being AFK"); + %client.lastTeam = %client.team; + + if($Host::TournamentMode) + { + if(!$matchStarted) + { + if(%client.camera.Mode $= "pickingTeam") + { + commandToClient( %client, 'processPickTeam'); + clearBottomPrint( %client ); + } + else + { + clearCenterPrint(%client); + %client.notReady = true; + } + } + } + + // switch client to team 0 (observer) + %client.team = 0; + %client.player.team = 0; + setTargetSensorGroup( %client.target, %client.team ); + %client.setSensorGroup( %client.team ); + + // set their control to the obs. cam + %client.setControlObject( %client.camera ); + commandToClient(%client, 'setHudMode', 'Observer'); + + // display the hud + //displayObserverHud(%client, 0); + updateObserverFlyHud(%client); + + messageAllExcept(%client, -1, 'MsgClientJoinTeam', '\c2%1 has been placed into observer mode due to being AFK.', %client.name, %game.getTeamName(0), %client, 0 ); + + updateCanListenState( %client ); + + // call the onEvent for this game type + %game.onClientEnterObserverMode(%client); //Bounty uses this to remove this client from others' hit lists +} \ No newline at end of file diff --git a/Classic/scripts/serverDefaults.cs b/Classic/scripts/serverDefaults.cs index 4b22b5d..3e496df 100644 --- a/Classic/scripts/serverDefaults.cs +++ b/Classic/scripts/serverDefaults.cs @@ -202,8 +202,9 @@ $Host::loadingmsgline2content = "https://github.com/ChocoTaco1/TacoServer"; //L $Host::loadingmsgline3 = "Required Mappacks: "; //Loading screen msg line 3 $Host::loadingmsgline3content = "S5 S8 TWL TWL2"; //Loading screen msg content 3 $Host::loadingmsgline4 = "Hosted by: "; //Loading screen msg line 4 -$Host::loadingmsgline4content = "Branzone"; +$Host::loadingmsgline4content = "Branzone"; //Loading screen msg content 4 +$Host::ForceAFKObserverTime = 1; //Change the time in minutes it takes to force a player into observer mode for being AFK //LakRabbit $Host::EnableLakUnlimitedDJ = 1; //Unlimited disc-jumps if enabled $Host::LakRabbitNoSplashDamage = 0; //Splash Damage enabled or not -$Host::ShowFlagIcon = 1; //Show flag Icon in lak \ No newline at end of file +$Host::ShowFlagIcon = 1; //Show flag Icon in lak