Jump to content
IzKhalifa

Hard Scripting Problem, need help

Recommended Posts

So I'm creating a multiplayer PVP game mode on an Oil Rig I built. The issue is that I'm using two scripts created from two different people and I need to combine them to do what I want. There is a bomb that must be defused and laptops that you must download data from in order to retrieve the defusal code from ONE of the laptops. I have four laptops. The players must download data off of all the laptops in order to find the single defusal code on one of the laptops. The main issue is that when a player clicks the ## Download Data ## addAction, it begins the "downloadData.sqf" process, which is fine, but the bomb defusal script also has an addAction to obtain the defusal code on the same laptops, which leads to one of the laptops randomly chosen to have TWO actions, the ## Download Data ## action and the bomb defusal code action. I want the player to first have to ## Download Data ## before recieving the defusal code, instead of having the ## Download Data ## do nothing and the defusal code just being a second addAction.

First Script is the Download Data script. As follows:

 

 

 

"downloadData.sqf" *//

 

T8L_var_fileSize = 25687;                                  // Filesize ... smaller files will take shorter time to download!     // These create the text for the pop up download bar after the player clicks the addAction ## Download Data ##.

T8L_var_TLine01 = "Download aborted";                // download aborted
T8L_var_TLine02 = "Download in progress";            // download already in progress by someone else
T8L_var_TLine03 = "Download started";                // download started
T8L_var_TLine04 = "Download finished";            // download finished
T8L_var_TLine05 = "##  Download Data  ##";                // line for the addaction
T8L_var_TLine06 = "Connecting ...";
T8L_var_TLine07 = "Connected:";

T8L_var_DialogAbort = false;
T8L_var_DialogSucce = false;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
T8L_fnc_abortActionLaptop =
{
    if ( T8L_var_DialogSucce ) then 
    {
        T8L_var_DialogAbort = false;
        T8L_var_DialogSucce = false;
    
    } else {
        cutText [ T8L_var_TLine01, "PLAIN" ];    
        T8L_var_DialogAbort = true; 
        T8L_var_DialogSucce = false; 
    };
};

T8L_fnc_addActionLaptop =     //This adds the ## Download Data ## action and text to all the laptops
{
    {
        if !( _x getVariable [ "T8L_pvar_dataDownloaded", false ] ) then
        {
            _x addAction [ T8L_var_TLine05, { call T8L_fnc_ActionLaptop; [] execVM "downloadANIM.sqf"; }, [], 10, false, false];
        };
    } forEach _this;    
};


T8L_fnc_removeActionLaptop =     // This removes the action from the laptops after they have been used sequentially by the player
{
    _laptop = _this select 0;
    _id = _this select 1;
    _laptop removeAction _id;
    
    
};

T8L_fnc_ActionLaptop =     // This creates the actual data download process using a pop out download UI so that the player can visually see the download occur in real time
{
    private [ "_laptop", "_caller", "_id"];
    _laptop = _this select 0;
    _caller = _this select 1;
    _id = _this select 2;
    
    if ( _laptop getVariable [ "T8L_pvar_inUse", false ] ) exitWith { cutText [ T8L_var_TLine02, "PLAIN" ]; };
    if ( _laptop getVariable [ "T8L_pvar_dataDownloaded", false ] ) exitWith { cutText [ T8L_var_TLine04, "PLAIN" ]; };
    
    cutText [ T8L_var_TLine03, "PLAIN" ];
    
    _laptop setVariable [ "T8L_pvar_inUse", true, true ];
        
    [ _laptop, _id ] spawn 
    {
        private [ "_laptop", "_id", "_newFile", "_dlRate", "_percent" ];
        
        _laptop        = _this select 0;
        _id            = _this select 1;
        
        _newFile = 0;
        T8L_var_DialogAbort = false;
        T8L_var_DialogSucce = false;
        
        createDialog "T8L_DataDownloadDialog";
        
        sleep 0.5;
        ctrlSetText [ 8001, T8L_var_TLine06 ];
        sleep 0.5;
        ctrlSetText [ 8001, T8L_var_TLine07 ];        
        ctrlSetText [ 8003, format [ "%1 kb", T8L_var_FileSize ] ];        
        ctrlSetText [ 8004, format [ "%1 kb", _newFile ] ];    
        
        
        
        while { !T8L_var_DialogAbort } do
        {
            _dlRate = 200 + random 80;
            _newFile = _newFile + _dlRate;

            if ( _newFile > T8L_var_FileSize ) then 
            {
                _dlRate = 0;        
                _newFile = T8L_var_FileSize;
                
                ctrlSetText [ 8001, T8L_var_TLine04 ];            
                cutText [ T8L_var_TLine04, "PLAIN" ];
                
                T8L_var_DialogAbort = true;
                T8L_var_DialogSucce = true;
                _laptop setVariable [ "T8L_pvar_dataDownloaded", true, true ];            

                [ [ _laptop, _id ], "T8L_fnc_removeActionLaptop", true, true ] spawn BIS_fnc_MP;
                [] execVM "codeAction.sqf";     // Here is where I'm having issues. Both these execVM codes I have added as an attempt to combine the bomb defusal script with the Data Download script in an attempt to make the Data Download script "spit out" the defusal codes.
                [] execVM "codeRemove.sqf";     // I added a "codeRemove" script because the problem is that every time the player downloads, it executes the addAction in the bomb defusal script, leading to multiple copies of the defusal codes.
            };
            
            // percentage part by cuel!
            ctrlSetText [ 8002, format [ "%1 kb/t", _dlRate ] ];        
            _percent =  ( _newFile / T8L_var_FileSize );
            _percent = toArray str _percent;
            { _percent set [_x,-1] } forEach [ 0, 1 ]; 
            _percent = _percent - [-1];
            _percent resize 2;
            _percent = toString _percent;
            ctrlSetText [ 8004, format [ "%1 kb (%2%3)", _newFile, (if ( T8L_var_DialogAbort ) then { 100 } else { _percent }), "%" ]];     // This creates a percentage increase in the Data Download script to simulate files being downloaded over time.
            
            sleep 0.25;
        };
        
        T8L_var_DialogAbort = false;

        _laptop setVariable [ "T8L_pvar_inUse", false, true ];
    };
};

T8L_var_INITDONE = true;

 

The second script is the Bomb Defusal script (many parts to this script) which creates a bomb timer and defusal UI that allows you to cut wires and press buttons on a keypad. The Bomb defusal script generates a randomized code and wire color to defuse the bomb, and this random defusal code is then put on a random laptop. One of the four random laptops I have in my mission:

 

BOMB DEFUSAL SCRIPT: 

"codeInput.sqf* //"

 

CODEINPUT = [];
CODE = [(round(random 9)), (round(random 9)), (round(random 9)), (round(random 9)), (round(random 9)), (round(random 9))]; //6 digit code can be more or less
WIRE = ["BLUE", "WHITE", "YELLOW", "GREEN"] call bis_fnc_selectRandom; // This creates the randomized defusal code.
DEFUSED = false;     // The defused = false and armed = false is to prevent the bomb from immediately going into one of the two states as this is tied to the endMission tasks.
ARMED = false;
codeHolder = [laptop1,laptop2,laptop3,laptop4] call BIS_fnc_selectRandom;      // This creates an array that randomizes the selection of which laptop will receive the defuse code.     

codeHolder addAction [("<t color='#E61616'>" + ("The Code") + "</t>"),"DEFUSE\searchAction.sqf","side (group player) == west",1,true,true,"","(_target distance _this) < 3"];     // This creates the addAction command that allows the player to see the code. When they click it it executes the "searchAction.sqf":

 

"searchAction.sqf" *//

 _host = _this select 0;
 _caller = _this select 1;
 _id = _this select 2;
 
 _host removeAction _id;
 
 _caller playMove "AmovPercMstpSrasWrflDnon_AinvPercMstpSrasWrflDnon_Putdown";     // This just makes the player do an animation when they pick up the code from the laptop.
 cutText [format ["Code: %1\n Wire: %2", CODE, WIRE], "PLAIN DOWN"];     // I'm guessing this communicates with the functions .hpp scripts and somehow generates the code.

 

 

"caseBomb.sqf" *//        

caseBomb addAction [("<t color='#E61616'>" + ("Defuse the Bomb") + "</t>"),"defuseAction.sqf","",1,true,true,"","(_target distance _this)< 5, side (group player) == west"];  // This creates the addAction command on the Bomb Case which brings up the keypad to defuse the bomb. The bomb detonates if the player inputs the wrong code or the timer runs out.

 

So the main issue I'm having is that I want there to be an addAction after the Download finishes. but the problem is that when I try to put the addAction where the download finishes, it spawns a new action every time the player downloads even if its on the wrong laptop that doesn't have the code. It's because the defusal code addAction is firing every time the download finishes but I only want it to fire once. Anybody got any ideas for adding like a limit or something to the addAction, so that the defusal code can only go out once?

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Share this post


Link to post
Share on other sites

Heya @IzKhalifa, welcome to the forums!

If I understand correctly, you're getting duplicate addactions. Could you not give the laptops variable names, then have the script select one of them to add the action?

  • Like 1

Share this post


Link to post
Share on other sites

@Melody_Mike I'm very new to scripting, how would I go about that in this instance. I named the laptops in Eden Editor, do those count as the variable names? [laptop1, laptop2, laptop3, laptop4] ? The problem is that I only want the addAction to spawn once. Right now it spawns for as many times as players click download on the laptop. I want the correct laptop to spit out the code after the initial ## Data Download ## script. I don't really know how to go about this. XD

 

Share this post


Link to post
Share on other sites

@Melody_Mike  The problem is the Defusal Script already assigns the variable to the laptops with 

 

Quote

codeHolder = [laptop1,laptop2,laptop3,laptop4] call BIS_fnc_selectRandom; 

 

_codeHolder addAction [("<t color='#E61616'>" + ("The Code") + "</t>"),"DEFUSE\searchAction.sqf","side (group player) == west",1,true,true,"","(_target distance _this) < 3"];

 

and in the init.sqf of the mission, we have this executing the DataDownload script, so both scripts are simultaneously executing.

 

Quote

[ [laptop1,laptop2,laptop3,laptop4], "T8L_fnc_addActionLaptop" , side (group player) == west, true, true] spawn BIS_fnc_MP;

 

I can't figure out what logic to use to make the bomb defusal code be given AFTER the data download finishes. I need to find some way to merge the bomb defusal script with the data download script so that the bomb defusal code is given as a result of the download, but I don't know how to read this properly to figure out how to do it. Also, I've tried removeAction to remove the duplicated actions, but it doesn't solve the problem of the code  showing up as its own addAction disconnected from the download script. 

simply, 

 

player clicks ## Download Data ##, 

 

download finishes,

 

player sees new action ----> "The Code"

 

That's the idea, 

but right now what happens is the two scripts are separate and acting on their own accord, so when the player finds the laptop with the defusal code it says both "## Download Data ##" AND "The Code" displaying the two actions simultaneously.

 

 

Share this post


Link to post
Share on other sites

@J. Schmidt Hey! thanks. I decided to just spawn in one laptop at random locations around the oil rig, that way the code is only given once, instead of multiple times, the only issue I'm having now is making it multiplayer compatible, which the original creators of the script didn't account for since it was made back in 2013, so I've just been frankensteining this whole thing and updating the scripts to make them multiplayer compatible in a PVP style mode. Its very interesting, I've def learned alot about scripting through this project.

 

So I created this as the work around.

Quote

 

//* "hideLaptop.sqf" *//

 

myLaptops = [laptop1,laptop2,laptop3,laptop4,laptop5,laptop6];
targetLaptop = [laptop1,laptop2,laptop3,laptop4,laptop5,laptop6] call BIS_fnc_selectRandom;
    
{_x hideObjectGlobal true;}count myLaptops;

targetLaptop hideObjectGlobal false;

 

 

Then I replaced the "[] execVM "codeAction.sqf"; and "codeRemove.sqf" here


 

Quote

 

 

   if ( _newFile > T8L_var_FileSize ) then 
            {
                _dlRate = 0;        
                _newFile = T8L_var_FileSize;
                
                ctrlSetText [ 8001, T8L_var_TLine04 ];            
                cutText [ T8L_var_TLine04, "PLAIN" ];
                
                T8L_var_DialogAbort = true;
                T8L_var_DialogSucce = true;
                _laptop setVariable [ "T8L_pvar_dataDownloaded", true, true ];            

                [ [ _laptop, _id ], "T8L_fnc_removeActionLaptop", true, true ] spawn BIS_fnc_MP;
                [] execVM "codeAction.sqf";     // Here is where I'm having issues. Both these execVM codes I have added as an attempt to combine the bomb defusal script with the Data Download script in an attempt to make the Data Download script "spit out" the defusal codes.
                [] execVM "codeRemove.sqf";     // I added a "codeRemove" script because the problem is that every time the player downloads, it executes the addAction in the bomb defusal script, leading to multiple copies of the defusal codes.
            };


 

 

with this...

Quote

 

if ( _newFile > T8L_var_FileSize ) then 
            {
                _dlRate = 0;        
                _newFile = T8L_var_FileSize;
                
                ctrlSetText [ 8001, T8L_var_TLine04 ];            
                cutText [ T8L_var_TLine04, "PLAIN" ];
                
                T8L_var_DialogAbort = true;
                T8L_var_DialogSucce = true;
                _laptop setVariable [ "T8L_pvar_dataDownloaded", true, true ];            

                [ [ _laptop, _id ], "T8L_fnc_removeActionLaptop", true, true ] spawn BIS_fnc_MP;
                
                targetLaptop addAction [("<t color='#E61616'>" + ("The Code") + "</t>"), { 
                    [] execVM "DEFUSE\searchAction.sqf";
                    ["Task_Download","SUCCEEDED"] call BIS_fnc_taskSetState; 
                    side (group player) == west;
                }];

                
                
            };

 

 

I just replaced executing unconnected private variables with global variables connected to an addAction that way the scripts can talk to eachother once within the scheduled environment. This way the addAction occurs AFTER the files have been downloaded, that is when (_newFile > T8L_var_FileSize). It took me a while to figure out how this dude wrote the dataDownload script but now it make sense so I figured it would be easier to execute it only once. compromise XD.

 

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

×