Jump to content
Sign in to follow this  
uait

script freezee

Recommended Posts

hi all

i hope somone can help me

i have a script that make players construct and demolish a static defense during battle

he can build only 1 static

but i want that when the player call that script he cant recall it for 300 seconds

i dont know if i explain right...

i write an example:

the player constructs static defense, if he demolishes the static (he calls another scripts) he cant rebuild it until 300 seconds pass from he builds the static

thx anyway

Share this post


Link to post
Share on other sites

Try this. It is untested and please excuse typos:

Put this code at the end of your demolish script:

delayStartTime = time;

Now put this at the beginning of your build script. Hint is optional of course.

if (time < (delayStartTime + 300)) then exitWith {hint "You must wait 5 mins between builds";};

Good luck!

Share this post


Link to post
Share on other sites

:confused:

sry... that doesnt work

i put here the scripts... maybe some errors

this is: "mortar.sqf"

private ["_dir_to_set","_m_name","_marker"];

#include "x_setup.sqf"

if ((player call XfGetHeight) > 5) exitWith {
"..." call XfGlobalChat;
};

if (count d_mortar_pos > 0) exitWith {
"Remouve your first." call XfGlobalChat;
};

d_mortar_pos = player modeltoworld [0,2,0];

// controllo posizione
if (surfaceIsWater [d_mortar_pos select 0, d_mortar_pos select 1]) exitWith {
"You cant have a mortar here." call XfGlobalChat;
d_mortar_pos = [];
};


_helper1 = "HeliHEmpty" createVehicleLocal [d_mortar_pos select 0, (d_mortar_pos select 1) + 4, 0];
_helper2 = "HeliHEmpty" createVehicleLocal [d_mortar_pos select 0, (d_mortar_pos select 1) - 4, 0];
_helper3 = "HeliHEmpty" createVehicleLocal [(d_mortar_pos select 0) + 4, d_mortar_pos select 1, 0];
_helper4 = "HeliHEmpty" createVehicleLocal [(d_mortar_pos select 0) - 4, d_mortar_pos select 1, 0];

if ((abs (((getPosASL _helper1) select 2) - ((getPosASL _helper2) select 2)) > 2) || (abs (((getPosASL _helper3) select 2) - ((getPosASL _helper4) select 2)) > 2)) exitWith {
"Find another place." call XfGlobalChat;
d_mortar_pos = [];
for "_mt" from 1 to 4 do {call compile format ["deleteVehicle _helper%1;", _mt];};
};

for "_mt" from 1 to 4 do {call compile format ["deleteVehicle _helper%1;", _mt];};


player playMove "AinvPknlMstpSlayWrflDnon_medic";
sleep 3;
waitUntil {animationState player != "AinvPknlMstpSlayWrflDnon_medic"};
if (!(alive player)) exitWith {
d_mortar_pos = [];
"You Are dead before mortar been created." call XfGlobalChat;
};

_dir_to_set = getdir player;

mortar = d_mortar createvehicle d_mortar_pos;
mortar setdir _dir_to_set;
mortar setPos [position mortar select 0, position mortar select 1, 0];

"Mortar ready." call XfGlobalChat;
_m_name = format ["Mortaio  %1", player];
[_m_name, position mortar,"ICON","ColorBlue",[0.5,0.5],format ["  Mortar  %1", name player],0,"mil_dot"] call XfCreateMarkerGlobal;

_d_placed_obj_add = [format ["%1", player], position mortar,1];
["d_placed_obj_add",_d_placed_obj_add] call XSendNetStartScriptServer;

mortar addAction ["Remove Mortar", "x_scripts\x_removemortar.sqf"];
mortar addEventHandler ["killed",{[_this select 0] spawn XMortarKilled;}];

player moveInGunner mortar;

if (alive mortar) then {
_isVeh = getNumber(configFile >> "CfgVehicles" >> typeOf(mortar) >> "ARTY_IsArtyVehicle");
   if (_isVeh == 1) then {
	mortar setVehicleInit "[this] call BIS_ARTY_F_initVehicle";
	processInitCommands;
};
};	

if (true) exitWith {};

this is: "removemortar.sqf"

private ["_m_name"];

if (vehicle player == mortar) exitWith {
"You must dismount." call XfGlobalChat;
};

player playMove "AinvPknlMstpSlayWrflDnon_medic";
sleep 3;
WaitUntil {animationState player != "AinvPknlMstpSlayWrflDnon_medic"};
if (!(alive player)) exitWith {
"you are dead before mortar been delete." call XfGlobalChat;
};

deleteVehicle mortar;

"Mortar delete." call XfGlobalChat;
d_mortar_pos = [];
_m_name = format ["Mortar %1", player];
deleteMarker _m_name;

if (true) exitWith {};

Share this post


Link to post
Share on other sites

Hi there,

it's probably easiest to use object variables for this. You attach a variable called "build_lock" (choose your own name if you like) to the player. You set it to 0 during mission start (notin the creation script, then it would be set to 0 each time called).

When the creation script is called it checks if the timeout period of 300 seconds is over already. After creating the item the build_lock is increased to time + 300. So the build script can never create another mortar if the time between 1st and 2nd creation is < 300 sec.

// e.g. put this into the init line of the player

// Init variable (run only once during mission start)
player setVariable ["build_lock", 0,false];

In the creation script:

// Check if player is allowed to build static item
IF (time > (player getVariable "build_lock")) THEN
{
  // create the static item here
  // Now set the timer to time + 300 sec
  player setVariable ["build_lock", (time + 300),false];
};

Regards, VictorFarbau

Share this post


Link to post
Share on other sites

mmm i'll try but i want know if somone know if in mortar.sqf i can set something that say:

DONT RUN "REMOVEMORTAR.SQF" UNTIL 300 SECONDS PASS FROM MORTAR.SQF WAS RUNNED

:confused:

i hope i can do it :(

Share this post


Link to post
Share on other sites

Ok, I think I found where I made mistakes...some were syntax errors and some were program flow errors. I did a test mission with these scripts and it worked. Here is the explanation in reverse.

At the end of removemortar.sqf you set a global variable with the current time.

At the beginning of mortar.sqf we set a local boolean called _delay that we will use later. It is reset every time the script is run. Then we check if delayStartTime is nil (which it will be the first time you run it because you have not set it in removemortar.sqf). If it is nil it skips further conditions and moves on to your main code. If it is not nil, that means that removemortar.sqf has been run at least once and it must check if 300 seconds has passed since it last run. So, if time now is greater than delayStartTime + 300 then _delay remains false and. If it is less than 300, _delay is set to true. Lastly, we check if _delay is true. If it is, then the script exits immediately, if still false then it moves to your main code.

Here is the code:

At the end of removemorder.sqf, like above, put this line:

delayStartTime = time;

Now at the beginning of mortar.sqf, put the following code:

private ["_delay"];

_delay = false;

if (!isNil "delayStartTime") then
{
if (time < (delayStartTime + 300)) then {_delay = true};
};

if (_delay) exitWith {hint "You must wait 5 mins between builds."}; // Change the hint to anything you want or remove if unwanted.

I hope that is better!

Share this post


Link to post
Share on other sites

I hope that is better!

:(

for me nothing happen

exc me, but you try to put your corrections in my script or i a new script without anything?

because nothing change from normal script...

now i must go to work, maybe in evening i try another time!

thank you anyway!

Share this post


Link to post
Share on other sites

I used by own scripts. I couldn't use yours since I don't have x_setup.sqf or x_removemortar.sqf and all the function calls you make: XfGlobalChat, XSendNetStartScriptServer, etc.

Just out of curiousity, did you put my code in removemortar.sqf before or after "if (true) exitWith {};" If after, that could be the reason why it is not working.

Share this post


Link to post
Share on other sites
I used by own scripts. I couldn't use yours since I don't have x_setup.sqf or x_removemortar.sqf and all the function calls you make: XfGlobalChat, XSendNetStartScriptServer, etc.

Just out of curiousity, did you put my code in removemortar.sqf before or after "if (true) exitWith {};" If after, that could be the reason why it is not working.

sry i was in hurry

i put it before...and after.

i write in the beginning _DELAY in

private ["_delay","_dir_to_set","_m_name","_marker"];

now i try something different

thank you for now!

if you see error send me :)

---------- Post added at 08:12 AM ---------- Previous post was at 07:58 AM ----------

:yay:

i find it!

the error was simple.

---------- Post added at 08:14 AM ---------- Previous post was at 08:12 AM ----------

:)

THIS at the end of mortar.sqf:

delayStartTime = time;

THIS at the beginning of removemortar.sqf:

private ["_delay"];

_delay = false;

if (!isNil "delayStartTime") then
{
if (time < (delayStartTime + 300)) then {_delay = true};
};

if (_delay) exitWith {hint "You must wait 5 mins between builds."}; // Change the hint to anything you want or remove if unwanted.

now i try to create a countdown! like "you have to wait XXX time before remove ecc" :p

Share this post


Link to post
Share on other sites

everything work :yay::yay::yay:

Share this post


Link to post
Share on other sites

I'm glad you got it working! :)

Are you still working on a countdown? If you need one to tell the player how long they have to wait to place a new mortar try this at the beginning of mortar.sqf:

private ["_delay", "_dif", "_wait"];

_delay = false;

if (!isNil "delayStartTime") then
{
if (time < (delayStartTime + 300)) then
{
	_delay = true;
	_dif = time - delayStartTime;
	_wait = round (300 - _dif);
};
};

if (_delay) exitWith {hint format ["You must wait %1 more secs before placing a new mortar.", _wait];};

If you need something for removemortar.sqf you can do something similar (just don't use delayStartTime as your variable name, use a different one to avoid conflict.)

Share this post


Link to post
Share on other sites

ohhh thank you

i do a think more simple! :bounce3:

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
Sign in to follow this  

×