Jump to content
Eroge

removeAction while performing scripted reparing?

Recommended Posts

I made a repairing script with a progress bar indicates the repairing progress in my mission. And I tried command "removeAction" to temporarily remove the action for players but I can't restore it. The first addAction returned 0 and if I use addAction again it will return 1... so if the player performs repairing again the option won't be removed.

 

Any suggestions?

Share this post


Link to post
Share on other sites

please post some code?

Share this post


Link to post
Share on other sites

I would save the addaction Id and use it in removeAction and only do another addaction when the old is removed

  • Like 1

Share this post


Link to post
Share on other sites
14 minutes ago, gc8 said:

I would save the addaction Id and use it in removeAction and only do another addaction when the old is removed


params["_vehicle","_question"];

_question = [(localize "STR_HG_EMPTY_QUESTION"),(localize "STR_HG_EMPTY_VEHICLE"),(localize "STR_HG_YES"),(localize "STR_HG_NO")] call BIS_fnc_guiMessage;
waitUntil {!isNil "_question"};

_sound = "hg_repair";

if(_question) then
{
    _vehicle setFuel 0;
    _vehicle setVelocity [0, 0, 0];
    hint "正在维修载具";
    playSound _sound;
    with uiNamespace do
    {    waitUntil {!isNull findDisplay 46};
        disableSerialization;
        tag_myProgressBar = findDisplay 46 ctrlCreate ["RscProgress",-1];
        tag_myProgressBar ctrlSetPosition [safezoneX+0.3*safezoneW,safezoneY+0.95*safezoneH,0.4*safezoneW,0.02*safezoneH];
        tag_myProgressBar ctrlSetTextColor [0.2,0.8,0.4,0.8];
        tag_myProgressBar progressSetPosition 0.5;
        tag_myProgressBar ctrlCommit 0;
    };
    
    disableSerialization;
    _ctrl = uiNamespace getVariable "tag_myProgressBar";
    private _n = 0;
    while {_n < 1} do
    {    _n = _n + 0.001;
        _ctrl progressSetPosition _n;
        sleep 0.02;
    };
    ctrlDelete _ctrl;
    uiNamespace setVariable ["tag_myProgressBar",nil];
    _vehicle setDamage 0; 
    _vehicle setFuel 1;
    hint (localize "STR_HG_VEHICLE_EMPTIED");
};

 

I barely know nothing about coding... and this is the fn_emptyVehicle.sqf in [HG] SimpleShop, I modified the empty vehicle option into repair vehicle option

Share this post


Link to post
Share on other sites
20 minutes ago, gc8 said:

I would save the addaction Id and use it in removeAction and only do another addaction when the old is removed


params["_vehicle"];

_vehicle addAction ["<img image='HG\UI\Icons\reset.paa' size='1.5'/><t color='#ffffff' size='1.5'>"+(localize "STR_HG_EMPTY_VEHICLE")+"</t>",{[(_this select 0)] spawn HG_fnc_emptyVehicle},"",0,false,false,"",'(alive player) AND (alive _target) AND (speed _target <= 10) AND ((objectParent player) isEqualTo _target)'];
 

 

And this is the fn_addActions.sqf file

Share this post


Link to post
Share on other sites
1 hour ago, gc8 said:

I would save the addaction Id and use it in removeAction and only do another addaction when the old is removed

 

 

Never mind, I found a solution, just check the fuel of the vehicle and see if it's more than 0.... cause I set fuel to 0 while repairing 

Share this post


Link to post
Share on other sites

Store the action ID.  You want it stored so the action can be checked and properly removed.

 

Add action:

if (_vehicle getVariable ["actionVarName",-1] < 0) then 
{
	Private _actionID = _vehicle addAction ["Action Name", {_actionCode}];
	_vehicle setVariable ["actionVarName",_actionID];
};

. . . . . . . .

Remove action:

Private _actionID = _vehicle getVariable ["actionVarName",-1];
if (_actionId >= 0) then 
{
	_vehicle removeAction _actionID;
	_vehicle setVariable ["actionVarName",-1];
};

. . . . . . . .

 

Storing actionID should be included in addAction and removeAction pages, imo.  These type questions pop up frequently.

  • Thanks 1

Share this post


Link to post
Share on other sites
1 minute ago, opusfmspol said:

Store the action ID.  You want it stored so the action can be checked and properly removed.

 

Add action:


Private _actionID = _vehicle addAction ["Action Name", {_actionCode}];
_vehicle setVariable ["actionVarName",_actionID];

 

. . . . . . . .

Remove action:


Private _actionID = _vehicle getVariable ["actionVarName",-1];
if (_actionId >= 0) then {_vehicle removeAction _actionID;};

. . . . . . . .

 

Storing actionID should be included in addAction and removeAction pages, imo.  These type questions pop up frequently.

 

 

Thank you, that's really illuminating... and I also found one solution for that, but then I ran into another problem: I want to check the damage of the vehicle to see if it need repairing, and I use damage _target >= 0.01 and if returns true then addaction. But when the vehicle blew a tyre this function returns false.... so I cant repair the tyre, How do I fix this?

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

×