Forum

> > Stranded II > Scripts > Make an aircraft float on water
Forums overviewStranded II overview Scripts overviewLog in to reply

English Make an aircraft float on water

7 replies
To the start Previous 1 Next To the start

old Make an aircraft float on water

aimeewilbury
User Off Offline

Quote
I created a hot-air balloon with the aircraft behavior. However if you land it in water it sinks and it kinda looks silly. Is there a way to make it float? I already tried changing the material.

old Re: Make an aircraft float on water

HudaJan
Super User Off Offline

Quote
Well this should be easily solved by s2 cmd timer, s2 cmd getx, s2 cmd gety s2 cmd setpos
here's an example:
1
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");
	}
}
I tried it with an airplane and it worked quite well

old Re: Make an aircraft float on water

Hurri04
Super User Off Offline

Quote
well, I see at least 3 major problems with this script:

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 s2 cmd 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 s2 cmd loop and let the loop circle through all the aircrafts, also use s2 cmd 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 s2 cmd exit to stop the loop. however, this is only neccessary at the on:start event.

old Re: Make an aircraft float on water

HudaJan
Super User Off Offline

Quote
Well, this was just the main idea.
If you wanted to get it done properly, you'd need to expand it a little.
However:
user Hurri04 has written
the 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
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";
}
}
Try it, you will be surprised

user Hurri04 has written
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.

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)
user Hurri04 has written
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.

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 s2 cmd if with variable s2 cmd riding. if the output would be false, you would use s2 cmd freetimers

But I like your way of thinking

old Re: Make an aircraft float on water

Hurri04
Super User Off Offline

Quote
user HudaJan has written
1
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";
}
}
Try it, you will be surprised

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.

user HudaJan has written
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)

yes, I know that on:create contains on:build_finish but the only way to create an aircraft would be to build it, right?

user HudaJan has written
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 s2 cmd if with variable s2 cmd riding. if the output would be false, you would use s2 cmd freetimers

you could use on:getoff here in combination with s2 cmd freetimers because when using the aircraft you will automatically ride it and the command s2 cmd riding therefore will always return a number greater than 0.

old Re: Make an aircraft float on water

HudaJan
Super User Off Offline

Quote
The script is made in a hurry and I agree it's messed up, but I'm sure particularly you can deal with it, as I said, try it, you'll see

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

old Re: Make an aircraft float on water

Hurri04
Super User Off Offline

Quote
user HudaJan has written
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

yeah, you're right, I didn't think of that possibility.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewStranded II overviewForums overview