Jump to content
Lorenz94

Bomb Script - Help Needed

Recommended Posts

Hello,

I'm writing a bomb script starting from an idea found on armaholic.

 

The script works great in SP or hosted MP, but I have a problem on a Server with the timeout for the explosion.
 

  • I have set a trigger with no area and: "none, blufor, present", condition "true", on activation "_null = [bomb, 20] spawn BRZ_fnc_countdown;" (also tried to set this to "Server Only", but doing this wont display the hint of the timer at all)
  • init.sqf contains all variables utilized:
Spoiler

inputCode = [];
defuseCode = [(round(random 9)),(round(random 9))];
bombDefused = false;
bombArmed = false;

//Also tried to set these as publicVariable from here, but the timer remains different and not JIP capable

 

 

countdown fnc:

Spoiler

_toHack = _this select 0; //The object with the addAction to open a keypad to input the code
_timerTime = _this select 1; //Timer value

if !(bombDefused) then {
	_toHack addAction [("<t color='#E61616'>Hack Your Chip</t>"),"scripts\defuse_chip\call_keyPad.sqf","",25,true,true,"","(_target distance _this) < 2.2"];
}; //call_keyPad just opens the pad and its image.. from there the code is compared with the originated one

while {_timerTime > 0 && !bombDefused} do {
	_timerTime = _timerTime - 1;
	hintSilent format ["Detonation in: \n %1", [((_timerTime)/60)+.01, "HH:MM"] call BIS_fnc_timetostring] remoteExec 		["hintSilent", 0, true];
	_toHack say3D ['timer_chip', 20, 0.98];

	if (_timerTime < 1) then {
		hintSilent "triggered";
		createVehicle ["M_NLAW_AT_F", position player, [], 0, "can_collide"];
		player setDamage 1; //All player explodes (I know that this way is NOT the bomb that creates the explosion)
	};
};

 

 

I tried to set _timerTime as publicVariable, to give the trigger an area, to "transform" the fn in a "normal" sqf and execVM it (or to remoteExec it, but in this case, if using 0 or 2 the timer is not spawned, and so the addAction for the keypad is not added).

I have finished my ideas and I really don't know what's going on.. what I think is the problem is an initialitialization issue..

Resume: problem is JIP not working, so if a player joins in between the timer, he has its own timer that begins from the set value (in this case 20s), instead of syncing with the "real" timer.

Hoping to solve soon,

thank you all for your attention.

 

L

Share this post


Link to post
Share on other sites

To avoid the small problem with JIP:

In the init.sqf or where you have set the countdown variable write:

if (isNil timer) then {timer = 20;};

Cannot be local I think. 

 

To make you understand: the variable timer could be at 5. The JIP player reads that. But then after the publicVariable is initialized the init.sqf (or script.sqf) is executing and sets the timer variable back to the default value.

So before you initialize the variable countdown you have to ask if it is isNil like in the code snippet above.

 

Also a local variable is not allowed to be a public variable. It has to be global. 

 

 

PS: Well, I see you are calling it out with a trigger. Just call it up once..

if (isServer) then { // call your function}  You also have to split some parts of the code cauz Server has no keyword 'player'.

Then share the value of countdown to the network via public variable (don't forget, countdown has to be a global variable). 

Third step is that you add the isNil stuff like explained above. 

 

Share this post


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

if (isNil timer) then {timer = 20;};

This doesn't work! It throws an error because timerTime is a number.

 

1 hour ago, scheintot2 said:

Trigger changed to:

if (isServer) then {_null = [bomb, 20] spawn BRZ_fnc_countdown};

Doesn't work! The hint is not showing, nor the beep sound is present.

 

1 hour ago, scheintot2 said:

Then share the value of countdown to the network via public variable (don't forget, countdown has to be a global variable). 
//Done! I forgot to change _timerTime to timerTime and set it as global once defined.

Before reading your PS, just changing timerTime to publicVariable brought me a step further, spawning the timer for everyone, BUT the hint goes on 3s at second: eg: 30:00 1s after becomes 27:57, then 27:24.. but the beep sound is correct (once per second).

Now I'm stuck with this!

Share this post


Link to post
Share on other sites
55 minutes ago, Lorenz94 said:

 

 

Before reading your PS, just changing timerTime to publicVariable brought me a step further, spawning the timer for everyone, BUT the hint goes on 3s at second: eg: 30:00 1s after becomes 27:57, then 27:24.. but the beep sound is correct (once per second).

Now I'm stuck with this!

 

Hm, could it be a delay because of publicVariable? I've had a similiar problem with setPos. Later I found out that setPos is just laggy over the network. 

 

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

×