by Blitzky » Wed Dec 06, 2017 7:50 pm
Here's my 'analysis':
Code: Select all
DECORATE
Fire:
TNT1 A 0 A_JumpIfInventory("RifleMode", 1, "RifleFire")
TNT1 A 0 A_JumpIfInventory("ShotgunMode", 1, "ShotgunFire")
TNT1 A 0 A_JumpIfInventory("RocketMode", 1, "RocketFire")
Goto Ready
AltFire:
PLSG A 1 ACS_NamedExecute("Cycler", 0, 1, 0, 0) //Call 'Cycler' with a value of 1 for the first argument
OICW A 1 A_Log("Mode Switched")
Goto Ready
=========================================================
ACS
#library "cyclr"
#include "zcommon.acs"
script "Cycler" (int mode) //Value of 1 is passed to 'mode' by the altfire state
{
int init = 1; //'init' is created and given a value of 1
mode = init; //'mode' is given the value of 'init'(1)
if (CheckWeapon("OICW") == 1) //Make sure the player is using the OICW
{
mode++; //'mode' is incremented, now a value of 2
if(mode == init) //'mode' is 2, skip this part
{
TakeInventory("RocketMode", 1);
GiveInventory("RifleMode", 1);
Log(s:"9.5x25mm Caseless Rifle Mode: ACTIVE.");
}
if(mode == 2) //'mode' is 2, execute this
{
TakeInventory("RifleMode", 1);
GiveInventory("ShotgunMode", 1);
Log(s:"10ga Shotgun Mode: ACTIVE.");
}
if(mode == 3) //'mode' is 2, nothing beyond is executed
{
TakeInventory("ShotgunMode", 1);
GiveInventory("RocketMode", 1);
Log(s:"20mm Smart Rocket Mode: ACTIVE.");
}
if(mode == 4)
{ mode = init; }
}
}
This is what I mentioned earlier. You defined 'mode' as an argument here, and pass it a value of 1 when altfire is used.
However, your script immediately gives it a value of 1 regardless by setting it equal to 'init'.
To remedy this without editing your script, you would need to write a few more lines in the altfire state that pass values of 1, 2, or 3, depending on which of the three dummy items the player is currently holding.
The 'init' value is redundant, as it is the same as giving mode a value of 1.
However, you can completely avoid the use of variables like this:
Code: Select all
#library "cyclr"
#include "zcommon.acs"
script "Cycler" (void)
{
if (CheckWeapon("OICW") == 1) //Make sure the player is using the OICW
{
if(CheckInventory("RifleMode")) //Execute if the player has "RifleMode"
{
TakeInventory("RifleMode", 1);
GiveInventory("ShotgunMode", 1);
Log(s:"10ga Shotgun Mode: ACTIVE.");
}
else if(CheckInventory("ShotgunMode")) //Execute if the player has "ShotgunMode"
{
TakeInventory("ShotgunMode", 1);
GiveInventory("RocketMode", 1);
Log(s:"20mm Smart Rocket Mode: ACTIVE.");
}
else if(CheckInventory("RocketMode")) //Execute if the player has "RocketMode"
{
TakeInventory("RocketMode", 1);
GiveInventory("RifleMode", 1);
Log(s:"9.5x25mm Caseless Rifle Mode: ACTIVE.");
}
}
}
Here's my 'analysis':
[code]
DECORATE
Fire:
TNT1 A 0 A_JumpIfInventory("RifleMode", 1, "RifleFire")
TNT1 A 0 A_JumpIfInventory("ShotgunMode", 1, "ShotgunFire")
TNT1 A 0 A_JumpIfInventory("RocketMode", 1, "RocketFire")
Goto Ready
AltFire:
PLSG A 1 ACS_NamedExecute("Cycler", 0, 1, 0, 0) //Call 'Cycler' with a value of 1 for the first argument
OICW A 1 A_Log("Mode Switched")
Goto Ready
=========================================================
ACS
#library "cyclr"
#include "zcommon.acs"
script "Cycler" (int mode) //Value of 1 is passed to 'mode' by the altfire state
{
int init = 1; //'init' is created and given a value of 1
mode = init; //'mode' is given the value of 'init'(1)
if (CheckWeapon("OICW") == 1) //Make sure the player is using the OICW
{
mode++; //'mode' is incremented, now a value of 2
if(mode == init) //'mode' is 2, skip this part
{
TakeInventory("RocketMode", 1);
GiveInventory("RifleMode", 1);
Log(s:"9.5x25mm Caseless Rifle Mode: ACTIVE.");
}
if(mode == 2) //'mode' is 2, execute this
{
TakeInventory("RifleMode", 1);
GiveInventory("ShotgunMode", 1);
Log(s:"10ga Shotgun Mode: ACTIVE.");
}
if(mode == 3) //'mode' is 2, nothing beyond is executed
{
TakeInventory("ShotgunMode", 1);
GiveInventory("RocketMode", 1);
Log(s:"20mm Smart Rocket Mode: ACTIVE.");
}
if(mode == 4)
{ mode = init; }
}
}[/code]
This is what I mentioned earlier. You defined 'mode' as an argument here, and pass it a value of 1 when altfire is used.
However, your script immediately gives it a value of 1 regardless by setting it equal to 'init'.
To remedy this without editing your script, you would need to write a few more lines in the altfire state that pass values of 1, 2, or 3, depending on which of the three dummy items the player is currently holding.
The 'init' value is redundant, as it is the same as giving mode a value of 1.
However, you can completely avoid the use of variables like this:
[code]#library "cyclr"
#include "zcommon.acs"
script "Cycler" (void)
{
if (CheckWeapon("OICW") == 1) //Make sure the player is using the OICW
{
if(CheckInventory("RifleMode")) //Execute if the player has "RifleMode"
{
TakeInventory("RifleMode", 1);
GiveInventory("ShotgunMode", 1);
Log(s:"10ga Shotgun Mode: ACTIVE.");
}
else if(CheckInventory("ShotgunMode")) //Execute if the player has "ShotgunMode"
{
TakeInventory("ShotgunMode", 1);
GiveInventory("RocketMode", 1);
Log(s:"20mm Smart Rocket Mode: ACTIVE.");
}
else if(CheckInventory("RocketMode")) //Execute if the player has "RocketMode"
{
TakeInventory("RocketMode", 1);
GiveInventory("RifleMode", 1);
Log(s:"9.5x25mm Caseless Rifle Mode: ACTIVE.");
}
}
}[/code]