[ACTION MAKER][WEAPON][SOLVED] Alternative for Sleep function in MP4

Moderator: NADEO

User avatar
weerwolf
Posts: 630
Joined: 15 Jun 2010, 21:21
Location: Wijchen, Netherlands
Contact:

Re: [ACTION MAKER][WEAPON][SOLVED] Alternative for Sleep function in MP4

Post by weerwolf »

BSO wrote: 11 Mar 2019, 09:54 Hi, in your case the main function will be executed not once but a lot of time so I think you need to declare a variable that will not be reset every time like this :

Code: Select all

Void main() {
	declare Integer TimeToAddFragment for This; // Will keep its previous value
But I don't know how you can know if it's the first time this main is call so you can set the default value
I use this at the moment for that check to give the first shot without loading time

Code: Select all

main() {
declare FirstRun for This = True;
	if (FirstRun == True) { // check if its the first yield of script
		Energy = EnergyMax;
		FirstRun = False;
		if (FirstRun == False) {
			if (Energy < EnergyMax) { // energy reload workaround
			Energy += 1; // every ms
				if (Energy > EnergyMax) {
				Energy = EnergyMax;
				}
			}
		}
	}
	}
BSO wrote:TimeToAddFragment = Now + Delay;
Testing with the logging fuction i took a look at which timestamps (NOW) the script would catch
For example 2 runs trying to catch = 9010,9020,9040,9050,9060,9070,9080,9090,10000:

Code: Select all

9010		9010
9040		9040
9060		9070
10000		10000
Multiple runs of this show that its alway with a diffence of 20 or 30 ms.
As far as i can judge by this to catch a value of 1 to 9 ms would be impossible.
In the above example if the Now + Delay (or TimeToAddFragment) would never be executed.

Logging and trying to catch designated values showed me that the value has to be at least 30+ ms in order for the script catch every stamp.
I do not know if this is the same on a server with players. (when multiple actions are executed at the same time)
BSO
Posts: 118
Joined: 08 Oct 2018, 08:49

Re: [ACTION MAKER][WEAPON][SOLVED] Alternative for Sleep function in MP4

Post by BSO »

Hi,
Okay so add this in the beginning of your main function :

Code: Select all

main() {
declare FirstRun for This = True;
declare Integer Delay = C_Cooldown / C_Fragments;
declare Integer TimeToAddFragment for This = Now + Delay;// Or 0 if you want to Add a Fragment at the first execution of your action
And if you do like I this (code from my previous answer) this will definitely do what you want :

Code: Select all

if (Stage == 1 && Now >= TimeToAddFragment) {
	log("Fire fragment");
	Counter += 1;
	log(Counter);
	// need to put this into a function ->
	declare Real PPX	= MathLib::Rand(96.0, 288.0); // 0.0,384.0
	declare Real PPY	= 192.0; // 192.0
	declare Real PPZ	= MathLib::Rand(96.0, 288.0); //  0.0,384.0
	declare Vec3 P_Pos		= <PPX, PPY, PPZ>;
	declare Real Angle1		= MathLib::Rand(-0.4, 0.4);
	declare Real Angle2		= MathLib::Rand(-0.4, 0.4);
	declare Vec3 P_Dir		= <Angle1, -1.0, Angle2>;
	declare Vec3 P_Speed	= <0.0, 0.0, 0.0>;
	declare Proj1 = Projectile_CreateAtLocation(ProjectileId1, Owner, P_Pos, P_Dir, P_Speed);
	SendRulesEvent("fire", [], Owner, Null);
	if (Counter == C_Fragments) {
		Stage = 0;
		Counter = 0;
	} else {
		// Set the next "TimeStamp"
		TimeToAddFragment = Now + Delay;
	}
}
Because at the first execution of you action you enter the main let's say at Now == 9010
You set FirstRun = True , Delay = 9// for exemple and TimeToAddFragment = 9010(Now) + 9(Delay)
we force Stage to 1 just for testing purpose
after that you check the if (Stage == 1 && 9010(Now) >= 9019(TimeToAddFragment)) {
so you don't enter in that if statement
next time your action is called let's say at Now == 9030, you will check again the if (Stage == 1 && 9030(Now) >= 9019(TimeToAddFragment)) {
and this time you enter in the if statement like you wanted, you will add a frament decrease the number of remainning fragment and if you still have fragments to add you will see the new value of TimeToAddFragment to (Now + Delay)

So yes since you main action function isn't called every ms you will add fragment with little variations and this is normal, variation like 10 ms is nothing, this represent 1/100 of a seconde so you eye cannot see that.

Conclusion : if you enter a Delay value inferior of the interval between two call of you main function this will add a fragment every time your function is called and it's normal :)
User avatar
weerwolf
Posts: 630
Joined: 15 Jun 2010, 21:21
Location: Wijchen, Netherlands
Contact:

Re: [ACTION MAKER][WEAPON][SOLVED] Alternative for Sleep function in MP4

Post by weerwolf »

BSO wrote: 14 Mar 2019, 09:49 So yes since you main action function isn't called every ms you will add fragment with little variations and this is normal, variation like 10 ms is nothing, this represent 1/100 of a seconde so you eye cannot see that.
I have retinal bionic eye implants, i can see that :mrgreen: :mrgreen: :mrgreen:

Thank u very much for all your help BSO. I'll finish this one up and update it in the title.
Although my vision on the mechanics are not 100 % clear yet, i have plenty of info to
experiment with now. More questions will undoubtedly rise :D

End result (delays between each meteor fragment):
https://youtu.be/4Nvt8z0U960
BSO
Posts: 118
Joined: 08 Oct 2018, 08:49

Re: [ACTION MAKER][WEAPON][SOLVED] Alternative for Sleep function in MP4

Post by BSO »

Very nice result!!

Yeah if you have questions about code I will be happy to answer them or redirect you to the right guy at the studio :)
User avatar
Miss
Posts: 2155
Joined: 05 Jan 2016, 11:34
Location: The Netherlands
Contact:

Re: [ACTION MAKER][WEAPON][SOLVED] Alternative for Sleep function in MP4

Post by Miss »

That is super cool looking! Nice work! :thumbsup:
3080 RTX, Ryzen 3700X, 32GB RAM, Windows 11
Forum moderator, opinions are my own. :thx:
Check out Image openplanet, the alternative ManiaPlanet & Turbo scripting platform! (Openplanet subforum)
I also stream and tweet.
Post Reply

Return to “ActionMaker and Item editor”

Who is online

Users browsing this forum: No registered users and 0 guests