RederickDeathwill Posted December 22, 2017 (edited) I'm trying to create different ammo recharge terminals within the same level. Here's my code so far: #include "zcommon.acs" int rechargeLimit = 5; int terminalUsageCount = 0; script "AMMO_RECHARGER" (void) { if (CheckSight(1, 2, CSF_NOBLOCKALL)) { print(s:"Terminal 1"); } else if (CheckSight(1, 3, CSF_NOBLOCKALL)) { print(s:"Terminal 2"); } else if (CheckSight(1, 4, CSF_NOBLOCKALL)) { print(s:"Terminal 3"); } else if (CheckSight(1, 5, CSF_NOBLOCKALL)) { print(s:"Terminal 4"); } str playerWeapon = getWeapon(); if (strcmp(playerWeapon, "Shotgun") == 0 || strcmp(playerWeapon, "SuperShotgun") == 0) { if (terminalUsageCount < 4) { giveInventory("Shell", 20); log(s:"Received 20 shells."); terminalUsageCount += 1; } else { print(s:"Maximum ammo recharge reached for this terminal."); } } else if (strcmp(playerWeapon, "Pistol") == 0 || strcmp(playerWeapon, "Chaingun") == 0) { if (terminalUsageCount < 4) { giveInventory("Clip", 100); log(s:"Received 100 clips."); terminalUsageCount += 1; } else { print(s:"Maximum ammo recharge reached for this terminal."); } } else if (strcmp(playerWeapon, "PlasmaRifle") == 0 || strcmp(playerWeapon, "BFG9000") == 0) { if (terminalUsageCount < 4) { giveInventory("Cell", 100); log(s:"Received 100 cells."); terminalUsageCount += 1; } else { print(s:"Maximum ammo recharge reached for this terminal."); } } else if (strcmp(playerWeapon, "RocketLauncher") == 0) { if (terminalUsageCount < 4) { giveInventory("RocketAmmo", 10); log(s:"Received 10 rockets."); terminalUsageCount += 1; } else { print(s:"Maximum ammo recharge reached for this terminal."); } } } As you can see, I use a global terminalUsageCount variable to count how many times the player have used a terminal, in order to limit him from taking more than what he should. The problem is that the other 3 terminals in the example use the same script, and therefore, the same global variable. Once he deplenishes one terminal, all the others also become unavailable. That can easily be solved by defining an array of terminals based on specific TID and with proper logic I can allow or disallow access to each terminal individually. The problem is that according to the reference on information functions, there's no getter that informs me what sidedef has just been "used". Giving that, I've tried to use "CheckSight" with invisible MapSpots with specific TIDs (It would work the same way). The problem is that apparently CheckSight does not treat a MapSpot as an actor. So... basically, I'll have to create a different global space / ACS file for each terminal??? The WAD of the example:ammo_example.7z Edited December 22, 2017 by RederickDeathwill 0 Share this post Link to post
ETTiNGRiNDER Posted December 22, 2017 Instead of (void) in the script definition, put something like (int which) and then add an argument 1 to each terminal line action with a different number (which will be loaded into variable "which" when the line is invoked). Then use a switch/case block that checks against "which". You probably still need four terminalUsageCount variables to track the four terminals separately, though. 1 Share this post Link to post
RederickDeathwill Posted December 22, 2017 (edited) 1 minute ago, ETTiNGRiNDER said: Instead of (void) in the script definition, put something like (int which) and then add an argument 1 to each terminal line action with a different number (which will be loaded into variable "which" when the line is invoked). Then use a switch/case block that checks against "which". You probably still need four terminalUsageCount variables to track the four terminals separately, though. Ohhh, scripts can have input arguments. Beautiful, thanks :p 0 Share this post Link to post
RederickDeathwill Posted December 22, 2017 (edited) For future viewers, here's the working script with each terminal working independently: #include "zcommon.acs" int rechargeLimit = 5; int terminalsUsageCount[4] = { 0, 0, 0, 0 }; script "AMMO_RECHARGER" (int terminal) { terminal = terminal + 1; str playerWeapon = getWeapon(); if (strcmp(playerWeapon, "Shotgun") == 0 || strcmp(playerWeapon, "SuperShotgun") == 0) { if (terminalsUsageCount[terminal] < 4) { giveInventory("Shell", 20); log(s:"Received 20 shells."); terminalsUsageCount[terminal] += 1; } else { print(s:"Maximum ammo recharge reached for this terminal."); } } else if (strcmp(playerWeapon, "Pistol") == 0 || strcmp(playerWeapon, "Chaingun") == 0) { if (terminalsUsageCount[terminal] < 4) { giveInventory("Clip", 100); log(s:"Received 100 clips."); terminalsUsageCount[terminal] += 1; } else { print(s:"Maximum ammo recharge reached for this terminal."); } } else if (strcmp(playerWeapon, "PlasmaRifle") == 0 || strcmp(playerWeapon, "BFG9000") == 0) { if (terminalsUsageCount[terminal] < 4) { giveInventory("Cell", 100); log(s:"Received 100 cells."); terminalsUsageCount[terminal] += 1; } else { print(s:"Maximum ammo recharge reached for this terminal."); } } else if (strcmp(playerWeapon, "RocketLauncher") == 0) { if (terminalsUsageCount[terminal] < 4) { giveInventory("RocketAmmo", 10); log(s:"Received 10 rockets."); terminalsUsageCount[terminal] += 1; } else { print(s:"Maximum ammo recharge reached for this terminal."); } } } A big map could have like... 10 to 15 terminals? One could completely remove the traditional ammo-collecting like this. 0 Share this post Link to post