LoD_PRC8/_module/nss/onuse_beamlever.nss
Jaysyn904 94990edc60 Initial Upload
Initial Upload
2023-09-21 21:20:34 -04:00

127 lines
5.3 KiB
Plaintext

void main()
{
if (GetLocalInt(OBJECT_SELF, "Activated")) {
PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE);
SetLocalInt(OBJECT_SELF, "Activated", 0);
} else {
PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE);
SetLocalInt(OBJECT_SELF, "Activated", 1);
}
PlaySound("as_sw_lever1");
string sTag = GetTag(OBJECT_SELF);
string sBeam;
int nTurnOn = GetFortitudeSavingThrow(OBJECT_SELF);
if (nTurnOn > 0) {
nTurnOn = TRUE;
}
int nTurnOff = GetReflexSavingThrow(OBJECT_SELF);
if (nTurnOff > 0) {
nTurnOff = TRUE;
}
if (GetStringLength(sTag) == 16) {
// We turn one matching beam on or off
sBeam = GetStringRight(sTag, 6);
object oBeamSource = GetNearestObjectByTag("BeamSource_" + sBeam);
if ((nTurnOff && !nTurnOn) || (nTurnOff && nTurnOn && GetLocalInt(oBeamSource, "BeamSetToOn"))) {
SetLocalInt(oBeamSource, "BeamSetToOn", FALSE);
effect eCheck = GetFirstEffect(oBeamSource);
while(GetIsEffectValid(eCheck)) {
if(GetEffectType(eCheck) == EFFECT_TYPE_BEAM) {
RemoveEffect(oBeamSource, eCheck);
SetLocalInt(GetArea(OBJECT_SELF), sBeam + "IsOn", FALSE);
}
eCheck = GetNextEffect(oBeamSource);
}
} else {
if (!GetLocalInt(oBeamSource, "BeamSetToOn")) {
SetLocalInt(oBeamSource, "BeamSetToOn", TRUE);
SetLocalInt(oBeamSource, "DoOnce", TRUE);
ExecuteScript("ud_beamtarget", oBeamSource);
}
}
} else if (GetStringLength(sTag) == 14) {
// We turn all beams of matching type on or off
int nCountNum = 0;
string sType = GetStringRight(sTag, 4);
string sCount = "00";
object oBeamSource= GetNearestObjectByTag("BeamSource_" + sCount + sType);
while (GetIsObjectValid(oBeamSource)) {
if ((nTurnOff && !nTurnOn) || (nTurnOff && nTurnOn && GetLocalInt(oBeamSource, "BeamSetToOn"))) {
SetLocalInt(oBeamSource, "BeamSetToOn", FALSE);
effect eCheck = GetFirstEffect(oBeamSource);
while(GetIsEffectValid(eCheck)) {
if(GetEffectType(eCheck) == EFFECT_TYPE_BEAM) {
RemoveEffect(oBeamSource, eCheck);
SetLocalInt(GetArea(OBJECT_SELF), sCount + sType + "IsOn", FALSE);
}
eCheck = GetNextEffect(oBeamSource);
}
} else {
if (!GetLocalInt(oBeamSource, "BeamSetToOn")) {
SetLocalInt(oBeamSource, "BeamSetToOn", TRUE);
SetLocalInt(oBeamSource, "DoOnce", TRUE);
ExecuteScript("ud_beamtarget", oBeamSource);
}
}
nCountNum++;
sCount = IntToString(nCountNum);
if (nCountNum < 10) {
sCount = "0" + sCount;
}
oBeamSource = GetNearestObjectByTag("BeamSource_" + sCount + sType);
}
} else if (GetStringLength(sTag) == 13) {
// We turn all beams in area on or off
int nCountNum;
int nForCount;
string sCount;
object oBeamSource;
string sType;
for (nForCount = 0; nForCount <= 6; nForCount++) {
nCountNum = 0;
sCount = "00";
if (nForCount == 0) {
sType = "Cold";
} else if (nForCount == 1) {
sType = "Elec";
} else if (nForCount == 2) {
sType = "Evil";
} else if (nForCount == 3) {
sType = "Fire";
} else if (nForCount == 4) {
sType = "Holy";
} else if (nForCount == 5) {
sType = "Lash";
} else if (nForCount == 6) {
sType = "Mind";
}
oBeamSource = GetNearestObjectByTag("BeamSource_" + sCount + sType);
while (GetIsObjectValid(oBeamSource)) {
if ((nTurnOff && !nTurnOn) || (nTurnOff && nTurnOn && GetLocalInt(oBeamSource, "BeamSetToOn"))) {
SetLocalInt(oBeamSource, "BeamSetToOn", FALSE);
effect eCheck = GetFirstEffect(oBeamSource);
while(GetIsEffectValid(eCheck)) {
if(GetEffectType(eCheck) == EFFECT_TYPE_BEAM) {
RemoveEffect(oBeamSource, eCheck);
SetLocalInt(GetArea(OBJECT_SELF), sCount + sType + "IsOn", FALSE);
}
eCheck = GetNextEffect(oBeamSource);
}
} else {
if (!GetLocalInt(oBeamSource, "BeamSetToOn")) {
SetLocalInt(oBeamSource, "BeamSetToOn", TRUE);
SetLocalInt(oBeamSource, "DoOnce", TRUE);
ExecuteScript("ud_beamtarget", oBeamSource);
}
}
nCountNum++;
string sCount = IntToString(nCountNum);
if (nCountNum < 10) {
sCount = "0" + sCount;
}
oBeamSource = GetNearestObjectByTag("BeamSource_" + sCount + sType);
}
}
}
}