Jump to content
Basicology Major

[Code Assistance] Problem w/ scopes/globals in Addaction Teleport with Arrays for certain units, Time pass, Fade screen

Recommended Posts

This script is a bit of a doozie and I generally wanted it to be handled within all one SQF... Or at least thats what I thought I could do. But my issue is with every attempt at (albeit randomly) changing scopes/globals I always get 'error undefined variable in _' and to be quite I have no idea what I am doing outside of looking at several examples of several things, then attempting to combine them.

So I have a scenario involving 4 groups, in a traitor-survival permadeath like scenario. Campers, killers, hunters, and guards. I wanted to an add action script on a Bell to ring that, in this order:

 

  • Institutes a 30 second COOLDOWN for the addaction.
  • Initiates a titleText BLACK FADED screen when activated, that pauses then shows text like "12 hours later"
  • Hidden by that screen I wish to teleport players to certain markers
  • And skips time 12 hours, more pause
  • BLACK IN titleCut when then the teleportation has happened and they see a different time of day upon lifting
  • Script/Addaction resets/loops

 

 

 

 Technicalities:

  • Script must be repeatable for my purpose
  • I want a UNIT VARIABLE NAME array, 1 for each pre mentioned group that is NOT SIDE dependent. All units are on Indfor. And a TELEPORTATION MARKER array, and code inserted to the teleportation bits so that once activated, for example, all campers will randomlytravel to one of the several CAMPER markers. This allows for rounds to not be the exact thing. CODE MUST NOT BE SIDE DEPENDENT.
  • Ive clearly tried to make 3 arrays, one for each 'type', the reason why all units are Indfor is for smooth 'roleplay' purposes

 

What Works:

  • I believe the time passage works. 
  • The black screen fade in/out/text works.
  • The teleportation does NOT WORK. I am screwing up with scopes/globals in accessing the array's Ive set up... Genuinely would like some help but have no idea how to proceed forward and I thank anyone in advance

 

bellInteraction.sqf

// Define the unit and marker arrays outside the function to avoid redefining them every time the script runs.
campers = ["cpr1", "cpr2", "cpr3", "cpr4", "cpr5", "cpr6", "cpr7", "cpr8", "cpr9"];
campMarkers = ["campMarker1", "campMarker2", "campMarker3"];

scouts = ["sct1", "sct2", "sct3"];
scoutsMarkers = ["scoutMarker1", "scoutMarker2", "scoutMarker3"];

hunters = ["htr1", "htr2", "htr3"];
huntersMarkers = ["hunterMarker1", "hunterMarker2", "hunterMarker3"];

guards = ["grd1", "grd2", "grd3"];
guardsMarkers = ["guardMarker1", "guardMarker2", "guardMarker3"];

// Teleport function
_teleportPlayers = {
    params ["_unitArray", "_markerArray"];
    {
        private _unit = missionNamespace getVariable _x;
        if (!isNull _unit) then {
            private _randomMarker = selectRandom _markerArray;
            _unit setPos (getMarkerPos _randomMarker);
        };
    } forEach _unitArray;
};

// The main script that will be executed when the bell is rung
_bellScript = {
    params ["_target", "_caller", "_id"];

    // Check for cooldown
    if (!isNil {bellCooldown}) exitWith {
        _caller sideChat "The bell is on cooldown. Please wait.";
    };

    // Set cooldown
    bellCooldown = true;
    _target removeAction _id;

    // Screen fade out to black
    titleText ["", "BLACK FADED", 1];
    sleep 5;
    titleText ["<t color='#ffffff' size='5'>12 hours later...</t>", "BLACK FADED", -1, true, true];
    sleep 2;

    // Skip 12 hours
    skipTime 12;

    // Teleport each group
    [campers, campMarkers] call _teleportPlayers;
    [scouts, scoutsMarkers] call _teleportPlayers;
    [hunters, huntersMarkers] call _teleportPlayers;
    [guards, guardsMarkers] call _teleportPlayers;

    // Screen fade in from black
    titleCut ["", "BLACK IN", 5];

    // Reset cooldown after 10 minutes (600 seconds)
    sleep 600;
    bellCooldown = nil;

    // Re-add the action to the bell
    _target addAction ["Ring Bell", _bellScript];
};

// Execute the script with the provided parameters
params ["_bell"];
_bell addAction ["Ring Bell", _bellScript];

The Bell Init Code: 

bell addAction ["Ring Bell", "mscripts\bellInteraction.sqf"];

 

  • Like 1

Share this post


Link to post
Share on other sites

tip: Campers, scouts are objects (units) not stringified like markers. Keep them objects even if missionNameSpace does the trick in your code.

Error : your local variable _teleportPlayers is not defined inside the addAction code. You can pass it as param or make it global (without underscore). Below, the code with params (as example)

tip: your cooldown is a part of addAction. Not necessary to remove then re-add another one

 


 

campers = [cpr1,cpr2,cpr3,cpr4,cpr5,cpr6,cpr7,cpr8,cpr9];
campMarkers = ["campMarker1", "campMarker2", "campMarker3"];

scouts = [sct1,sct2,sct3];
scoutsMarkers = ["scoutMarker1", "scoutMarker2", "scoutMarker3"];

hunters = [htr1,htr2,htr3];
huntersMarkers = ["hunterMarker1", "hunterMarker2", "hunterMarker3"];

guards = [grd1,grd2,grd3];
guardsMarkers = ["guardMarker1", "guardMarker2", "guardMarker3"];

private _teleportPlayers = {
  params ["_unitArray", "_markerArray"];
   {
       _x setPos getMarkerPos selectRandom _markerArray;
   } forEach _unitArray;
};

private _bellScript = {
  params ["_target", "_caller", "_id","_argument"];
    if (!isNil {bellCooldown}) exitWith {  _caller sideChat "The bell is on cooldown. Please wait." };
    bellCooldown = true;
    titleText ["", "BLACK FADED", 1];
    uiSleep 5;
    titleText ["<t color='#ffffff' size='5'>12 hours later...</t>", "BLACK FADED", -1, true, true];
    uiSleep 2;
    skipTime 12;
   [campers, campMarkers] call _teleportPlayers;
   [scouts, scoutsMarkers] call _teleportPlayers;
   [hunters, huntersMarkers] call _teleportPlayers;
   [guards, guardsMarkers] call _teleportPlayers;
   titleCut ["", "BLACK IN", 5];
   uiSleep 600;
   bellCooldown = nil;
 };

params ["_bell"];
_bell addAction ["Ring Bell", _bellScript, _teleportPlayers, 1.5, true, false, "", "true", 5];


Note 1 : Here bell should be an object with a global variable bell  if you want to be sure all players can see the addAction, but I can't guess where the script comes from. Make sure _bellScript is set everywhere also.

Note 2 : if you don't want to action a script during cooldown, just add a condition in addAction (8th) parameter. This way action is hidden and you don't have any cooldown message. It's a choice.
 

 




 

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×