Jump to content
Kameradenschwein

delay for "addAction" after activation

Recommended Posts

Hello everybody

 

I try to get a delay for a Action but i cant get it set up. Here is my problem. For a MP mission I made i wanted to hide a little easter egg. This easter egg is a sound of a little polka music that gets played.

 

At the moment they players can go to the radio and can activate this sound.

 

In the Init field of the Radio

„this AddAction [„Play Polka“, „scripts\polkka.sqf]

 

But I know some of my fellow players, as soon as they find out they will spam the action, make this sound get played like 100 times at the same time and maybe even crash the server that way…

 

What I need is a delay that they only can play the song again after it has stopped. So I need a delay for this action of 144 seconds. What i tried so far is this

 

Init field

Cooldown = 0; this AddAction [„Play Polka“, „scripts\polkka.sqf“, „Cooldown < 1“];

 

and in the sqf

 

Cooldown = 1;

radio01 say3d „ivean_polkka“;

Sleep 144;

Cooldown = 0;

 

but still, i can spam the action and make the song play as many times as i wish…

Share this post


Link to post
Share on other sites

make sure you are passing correct parameters to the addaction. I dont understand the code you posted, it seems to be missing a lot? the addaction condition is the number 7 parameter. addaction wiki

 

also I would suggest using boolean for the condition variable instead of number.

Share this post


Link to post
Share on other sites

Fairly simple:

//init.sqf
TAG_fnc_radioSong = {

	params ["_object","_caller","_ID"];
	_object removeAction _ID;
	_object say3d "ivean_polkka"; 
	sleep 144;
	_object AddAction ["Play Polka again", {_this spawn TAG_fnc_radioSong}];

};

//radio init field
this AddAction ["Play Polka", {_this spawn TAG_fnc_radioSong}];

Edit: For multiplayer purposes you need to broadcast the sound, so everyone can hear it, otherwise only the person who activated the action would hear it:

//init.sqf
TAG_fnc_radioSong = {

	params ["_object","_caller","_ID"];
	_object removeAction _ID;
	[_object,"ivean_polkka"] remoteExec ["say3d",0];
	sleep 144;
	[_object,["Play Polka again", {_this spawn TAG_fnc_radioSong}]] remoteExec ["addAction",0];

};

//radio init field
[this,["Play Polka", {_this spawn TAG_fnc_radioSong}]] remoteExec ["addAction",0];

 

 

Cheers

Share this post


Link to post
Share on other sites

That is because i am really not that good - lets say i am a beginner so i tried to copy and paste what i need from other scripts :) , so just one step back

 

In the Init field of the Radio

„this AddAction [„Play Polka“, „scripts\polkka.sqf]

 

Radio sqf

radio01 say3d „ivean_polkka“;

 

how can I get a delay so that nobody can spam that song?

 

Share this post


Link to post
Share on other sites
11 minutes ago, Grumpy Old Man said:

Fairly simple:


//init.sqf
TAG_fnc_radioSong = {

	params ["_object","_caller","_ID"];
	_object removeAction _ID;
	_object say3d "ivean_polkka"; 
	sleep 144;
	_object AddAction ["Play Polka again", {_this spawn TAG_fnc_radioSong}];

};

//radio init field
this AddAction ["Play Polka", {_this spawn TAG_fnc_radioSong}];

 

Cheers

 

Thank you a lot :) - so i replaced my init field and my sqf with your expressions

but now i get the error ""_this spawn |#|Tag_fnc_radioSong" Error undifined variable in expression: Tag_fnc_radioSong

Share this post


Link to post
Share on other sites
3 minutes ago, Kameradenschwein said:

 

Thank you a lot :) - so i replaced my init field and my sqf with your expressions

but now i get the error ""_this spawn |#|Tag_fnc_radioSong" Error undifined variable in expression: Tag_fnc_radioSong

 

Right, my bad, init.sqf is initialized after object init fields, that was causing the error.

Simply put the stuff from the radio init into the init.sqf and name the radio, so it looks like this:


//init.sqf
TAG_fnc_radioSong = {

	params ["_object","_caller","_ID"];
	_object removeAction _ID;
	_object say3d "ivean_polkka"; 
	sleep 144;
	_object AddAction ["Play Polka again", {_this spawn TAG_fnc_radioSong}];

};
radio01 AddAction ["Play Polka", {_this spawn TAG_fnc_radioSong}];

 

Cheers

  • Like 1

Share this post


Link to post
Share on other sites

I get a bit confused what you mean by "and name the radio"

 

At the moment it looks like this

 

radio01

Variable name: radio01

Init field:

radio01 AddAction ["Play Polka", {_this spawn TAG_fnc_radioSong}];

polkka.sqf

TAG_fnc_radioSong = {

	params ["_object","_caller","_ID"];
	_object removeAction _ID;
	_object say3d "ivean_polkka"; 
	sleep 144;
	_object AddAction ["Play Polka again", {_this spawn TAG_fnc_radioSong}];

};
radio01 AddAction ["Play Polka", {_this spawn TAG_fnc_radioSong}];

Still get the ""_this spawn |#|Tag_fnc_radioSong" Error undifined variable in expression: Tag_fnc_radioSong"

sorry for making this so hard

  • Like 2

Share this post


Link to post
Share on other sites
  1. Put my above example to the init.sqf
  2. no need for any other sqf file
  3. leave the init field of the radio empty but
  4. keep the radio named "radio01"

:yay:

 

Cheers

 

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

×