(ACS) Terminating a script if bool cvar returns false
Thu Jan 20, 2022 12:41 am
I am using Zombie Killer's enhanced third person code in a project, and it uses a custom boolean cvar, that uses a acs script, to create a rotating chasecam. I was able to create a toggle for the camera since originaly you had to disable the chasecam via console, however, i noticed that the specific script that creates the rotating chasecam, also causes issues with my mod's pitch and angle effects, such as when i fire a weapon, the A_SetPich(pitch+2) does nothing, so my idea is that if i can terminate the script wenever i toggle the chasecam off, and while in first person all my A_SetPitch and A_SetAngle effects could work correctly, at least i hope that works, not sure how to go about this exactly im very new to acs.
this is the zombie killer's acs
Spoiler:
Code:
// ACS #library "cam" #include "zcommon.acs"
// Defines #define MAXPLAYERS 8
// Variables int camTID[MAXPLAYERS]; int camWayTID[MAXPLAYERS];
Script "CameraMain" ENTER { // Set up the TID's and spawn the waypoint int tid, playerNum, plrInput, plrHealth, yawAdd, pitchAdd, plrRotType, a, p; int plrAngle = GetActorAngle(0); a = plrAngle; playerNum = PlayerNumber(); tid = UniqueTID(-32768, 32767); camTID[playerNum] = tid; SpawnForced("ChaseCam", GetActorX(0), GetActorY(0), GetActorZ(0), tid, GetActorAngle(0)); while (true) { plrHealth = GetActorProperty(0, APROP_Health); plrInput = GetPlayerInput(-1, INPUT_BUTTONS); yawAdd = GetPlayerInput(-1, INPUT_YAW); pitchAdd = -GetPlayerInput(-1, INPUT_PITCH); a = a + yawAdd; p = p + pitchAdd; if (p > 0.23) p = 0.23; if (p < -0.23) p = -0.23; LineAttack(0, a + 0.5, -p, 0, "ChaseCamWaypoint", "", GetCVar("chase_dist"), FHF_NORANDOMPUFFZ); SetActorAngle(camWayTID[playerNum], a); SetActorPitch(camWayTID[playerNum], p); SetActorAngle(camTID[playerNum], a); SetActorPitch(camTID[playerNum], p); plrRotType = GetCVar("chase_rotateplr"); if (plrRotType == 1 && plrHealth) plrAngle = a; else if (plrRotType == 2 && plrHealth) { if (plrInput & BT_FORWARD || plrInput & BT_BACK || plrInput & BT_MOVELEFT || plrInput & BT_MOVERIGHT || plrInput & BT_ATTACK || plrInput & BT_ALTATTACK) plrAngle = a; } else if (plrRotType == 3 && plrHealth) { if (plrInput & BT_FORWARD || plrInput & BT_BACK || plrInput & BT_MOVELEFT || plrInput & BT_MOVERIGHT) plrAngle = a; } if (GetCVar("chase_active")) ChangeCamera(camTID[playerNum], 0, 0); else { if (plrHealth) plrAngle = a; ChangeCamera(0, 0, 0); } SetActorAngle(0, plrAngle); SetActorPitch(0, p); Delay(1); } }
This is the Keyconf i made to make it toggle on or off, note the "chase_active" is the boolean that by default is set to false
Spoiler:
Code:
addkeysection "Chase Toggle" ChasecamToggle addmenukey "CToggle" +chase alias +chase "chase_active true; rebind -chase" alias -chase "chase_active false; rebind +chase"
And this is the code i attempted to create to terminate the script wenever the chasecam is off
Spoiler:
Code:
Script "ChasecamDestroy" ENTER { int ccvar=0; { while (true) { delay(1); ccvar = GetCVar("chase_active");
if (ccvar == 1) { ACS_NamedExecute("CameraMain", 0); } else if (ccvar == 0) { ACS_Terminate("CameraMain", 0); } } } }
The script i made most likely isn't correct, but even if it was im not sure it would even do what need.
Re: (ACS) Terminating a script if bool cvar returns false
Thu Jan 20, 2022 7:35 am
Ok so i just surprised myself today, i cant believe it but my script actually works, i only made two changes to it, the only thing that doesn't quite look right, is when i exit first person mode and go into chase cam it does a quick flash like glitch that goes away right after, its not too bad tho but, if there is a way to fix it, i would appreciate any advice.
This is how i changed the code, i only turned "CameraMain" ENTER to (void) and re arranged true and false, i still can't believe it worked tho
Spoiler:
Code:
Script "ChasecamDestroy" ENTER { int ccvar=true; { while (true) { delay(1); ccvar = GetCVar("chase_active");
if (ccvar == false) { ACS_NamedExecute("CameraMain", 0); } else if (ccvar == true) { ACS_NamedTerminate("CameraMain", 0); } } } }
Script "CameraMain" (void) { // Set up the TID's and spawn the waypoint int tid, playerNum, plrInput, plrHealth, yawAdd, pitchAdd, plrRotType, a, p; int plrAngle = GetActorAngle(0); a = plrAngle; playerNum = PlayerNumber(); tid = UniqueTID(-32768, 32767); camTID[playerNum] = tid; SpawnForced("ChaseCam", GetActorX(0), GetActorY(0), GetActorZ(0), tid, GetActorAngle(0)); while (true) { plrHealth = GetActorProperty(0, APROP_Health); plrInput = GetPlayerInput(-1, INPUT_BUTTONS); yawAdd = GetPlayerInput(-1, INPUT_YAW); pitchAdd = -GetPlayerInput(-1, INPUT_PITCH); a = a + yawAdd; p = p + pitchAdd; if (p > 0.23) p = 0.23; if (p < -0.23) p = -0.23; LineAttack(0, a + 0.5, -p, 0, "ChaseCamWaypoint", "", GetCVar("chase_dist"), FHF_NORANDOMPUFFZ); SetActorAngle(camWayTID[playerNum], a); SetActorPitch(camWayTID[playerNum], p); SetActorAngle(camTID[playerNum], a); SetActorPitch(camTID[playerNum], p); plrRotType = GetCVar("chase_rotateplr"); if (plrRotType == 1 && plrHealth) plrAngle = a; else if (plrRotType == 2 && plrHealth) { if (plrInput & BT_FORWARD || plrInput & BT_BACK || plrInput & BT_MOVELEFT || plrInput & BT_MOVERIGHT || plrInput & BT_ATTACK || plrInput & BT_ALTATTACK) plrAngle = a; } else if (plrRotType == 3 && plrHealth) { if (plrInput & BT_FORWARD || plrInput & BT_BACK || plrInput & BT_MOVELEFT || plrInput & BT_MOVERIGHT) plrAngle = a; } if (GetCVar("chase_active")) ChangeCamera(camTID[playerNum], 0, 0); else { if (plrHealth) plrAngle = a; ChangeCamera(0, 0, 0); } SetActorAngle(0, plrAngle); SetActorPitch(0, p); Delay(1); } }