Page 2 of 2

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

Posted: 13 Mar 2019, 21:10
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)

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

Posted: 14 Mar 2019, 09:49
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 :)

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

Posted: 14 Mar 2019, 19:51
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):

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

Posted: 15 Mar 2019, 09:28
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 :)

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

Posted: 15 Mar 2019, 13:48
by Miss
That is super cool looking! Nice work! :thumbsup: