Forum
Scripts
Make an aircraft float on water
Make an aircraft float on water
7 replies
1

timer,
getx,
gety
setposhere's an example:
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
on:start {
	timer "self",1,0,"float";
}
on:float {
	local $gety;
	$y=gety("self");
	if($y<0){
		setpos "self",getx("self"),0,getz("self");
	}
}
the first one is quiete obvious, the timer is triggered very rapidly, 1000 per second which will definitely lead to laggs, especially on older computers.
therefore the number in the timer script line should be at least 10 so the timer is executed "only" 100 times a second.
the second problem is that the timer isnt started e.g. when the player builds the unit. for this to happen you need to repeat the timer command within an on:build_finish event.
the third problem is that there can be multiple aircrafts which would trigger the on:start or on:build_finish event multiple times so the timer is also executed multiple times which will lead to laggs again.
therefore use
count to check how many aircrafts there are and run the timer command only if there is just one aircraft. if there are multiple aircrafts use a
loop and let the loop circle through all the aircrafts, also use
loop_id and a variable which you set +1 each time the loop starts over. if the variable is 1 then start the timer again, if not, use
exit to stop the loop. however, this is only neccessary at the on:start event. If you wanted to get it done properly, you'd need to expand it a little.
However:
Hurri04 has writtenthe first one is quiete obvious, the timer is triggered very rapidly, 1000 per second which will definitely lead to laggs
I don't suppose you've ever tried this (or similar) simple script, to check timer accuracy
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
on:start {
	timer "self",1,1,0,"count1";
	timer "self",1,10,0,"count2";
}
on:count1 {
	$whatever++;
	text 0,"$whatever";
}
on:count2 {
	$whatever2++;
	text 1,"$whatever2";
}
}
Hurri04 has writtenthe second problem is that the timer isnt started e.g. when the player builds the unit. for this to happen you need to repeat the timer command within an on:build_finish event.
Yes, as I said (wrote) it still needs to be expanded, but built_finish isn't the best event for this purpose, better would be on:create, which is more general and "contains" the event build_finish. (You would still have to let the event start covered, though)
Hurri04 has writtenthe third problem is that there can be multiple aircrafts which would trigger the on:start or on:build_finish event multiple times so the timer is also executed multiple times which will lead to laggs again.
There is even smoother solution, because if I understand yours correctly, this way you would be able to ride only one aircraft (again I remind you that the timer is not executed 1000 times a second), you could omit the events start and create and put one event "use" and the timer would contain
if with variable
riding. if the output would be false, you would use
freetimers
But I like your way of thinking
HudaJan has written1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
on:start {
	timer "self",1,1,0,"count1";
	timer "self",1,10,0,"count2";
}
on:count1 {
	$whatever++;
	text 0,"$whatever";
}
on:count2 {
	$whatever2++;
	text 1,"$whatever2";
}
}

first of all, there is one parameter too much in both the lines with the timer.
secondly, there is a } too much at the end.
so basically you say that the first timer isnt triggered 1000 times a second? well, maybe then this a result of a delay, caused by the timer itself.
HudaJan has writtenYes, as I said (wrote) it still needs to be expanded, but built_finish isn't the best event for this purpose, better would be on:create, which is more general and "contains" the event build_finish. (You would still have to let the event start covered, though)
yes, I know that on:create contains on:build_finish but the only way to create an aircraft would be to build it, right?
HudaJan has writtenThere is even smoother solution, because if I understand yours correctly, this way you would be able to ride only one aircraft (again I remind you that the timer is not executed 1000 times a second), you could omit the events start and create and put one event "use" and the timer would contain
if with variable
riding. if the output would be false, you would use
freetimers 
if with variable
riding. if the output would be false, you would use
freetimers 
you could use on:getoff here in combination with
freetimers because when using the aircraft you will automatically ride it and the command
riding therefore will always return a number greater than 0. Secondly, what if the aircraft was made by a script?
Imagine - native tribe offers you that they'll offer you a transport home if you do something for them, in the meantime they would build it, then if you do everything for them, the script create is executed
the event getoff would be also possible, but I remember having some difficulties with the event working properly. But you're right, it should be better
HudaJan has writtenSecondly, what if the aircraft was made by a script?
Imagine - native tribe offers you that they'll offer you a transport home if you do something for them, in the meantime they would build it, then if you do everything for them, the script create is executed
Imagine - native tribe offers you that they'll offer you a transport home if you do something for them, in the meantime they would build it, then if you do everything for them, the script create is executed
yeah, you're right, I didn't think of that possibility.
1

Offline