Forum

> > Stranded II > Scripts > Bugs in acceleration testing script
Forums overviewStranded II overview Scripts overviewLog in to reply

English Bugs in acceleration testing script

2 replies
To the start Previous 1 Next To the start

old Bugs in acceleration testing script

ModJuicer
Super User On Online

Quote
I figured out the script, mostly. The answer is below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
script=start
	on:use{
		ride;
		event "rode";
	}
	//If fighter=1 then the fighter menu pops up when the user tries to get off
	//otherwise it tests the speed of the airplane and decides whether you should
	//get off. If you choose 'get off' on fighter menu then it will trigger 'close'
	//command.
	on:getoff{
		if($fighter==1){
			if($narg==0){
				skipevent;
				msgbox "What do you want to do with this airplane";
				button 0,"Shoot",1,"shoot";
				button 1,"get off",1,"close";
			}
		}
		//Tests if the vehicle is going too fast to dismount
		elseif($fighter==0){
			$cangetoff=1;
			if($speedx >= 5){
				$cangetoff=0;
			}
			if($speedx <= -5){
				$cangetoff=0;
			}
			if($speedy >= 5){
				$cangetoff=0;
			}
			if($speedy <= -5){
				$cangetoff=0;
			}
			if($speedz >= 5){
				$cangetoff=0;
			}
			if($speedz <= -5){
				$cangetoff=0;
			}
			if($cangetoff==0){
				msg "You are going too fast to get off";
				msg "Try to slow down";
				skipevent;
			}
			elseif($cangetoff==1){
				getoff;
				event "gotoff";
			}
		}
			
	}
	//This script makes so that the user can get off of the airplane without causing
	//an infinite loop. It triggers the 'acceltest' command.
	on:close{
		closemenu;
		$narg=1;
		event "acceltest";
		timer "self",100,1,"pausemenu";
	}
	on:pausemenu{
		$narg=0;
	}
	//This script makes so that the plane shoots when the 'Shoot' button is pressed
	on:shoot{
		$id=currentid;
		msg "boom";
		closemenu;
		projectile 29,getx("self"),gety("self"),getz("self"),3,getpitch("self"),getyaw("self"),0,0,500,100;
	}
	//This script makes so the plane dissapears when killed/destroyed
	on:kill { free "self"; }
	//Starts everything off at zero, because that's what they would be to start with
	//anyway, and triggers the acceleration timer to begin
	on:rode{
		$roden=1;
		$lastx=getx("self");
		$lasty=gety("self");
		$lastz=getz("self");
		$speedx=0;
		$speedy=0;
		$speedz=0;
		$lastspeedx=0;
		$lastspeedy=0;
		$lastspeedz=0;
		$accelx=0;
		$accely=0;
		$accelz=0;
		$firsttime=1;
		timer "self",100,1,"accel";
	}
	//Gets the current position of the vehicle and compares it to the last position to
	//calculate acceleration as well as speed
	on:accel{
		if ($roden==1){
			//gets current position
			$currentx=getx("self");
			$currenty=gety("self");
			$currentz=getz("self");
			//gets difference between current position and last position
			//to get speed
			$speedx=$lastx-$currentx;
			$speedy=$lasty-$currenty;
			$speedz=$lastz-$currentz;
			//gets difference between difference between current position and last
			//position to get acceleration/deceleration
			$accelx=$lastspeedx-$speedx;
			$accely=$lastspeedy-$speedy;
			$accelz=$lastspeedz-$speedz;
			//Tests if the acceleration changed enough to cause a crash
			$crashed=0;
			if($accelx > 40){
				$crashed=1;
			}
			elseif($accelx < -40){
				$crashed=1;
			}
			elseif($accely > 40){
				$crashed=1;
			}
			elseif($accely < -40){
				$crashed=1;
			}
			elseif($accelz > 40){
				$crashed=1;
			}
			elseif($accelz < -40){
				$crashed=1;
			}
			if ($crashed==1){
				msg "YOU CRASHED!",3;
				event "gotoff";
				explosion getx("self"),gety("self"),getz("self"),200,10;
				free "self";
			}
			//Changes variables so they can be compared to variables during
			//next 'accel' event
			$lastspeedx=$speedx;
			$lastspeedy=$speedy;
			$lastspeedz=$speedz;
			$lastx=$currentx;
			$lasty=$currenty;
			$lastz=$currentz;
			timer "self",200,1,"accel";
		}
	}
	//Makes so the timer turns off when the user gets off the plane
	on:gotoff{
		$roden=0;
	}
	//This script decides if the plane is flying slow enough that the user
	//can get out.
	on:acceltest{
		$cangetoff=1;
		if($speedx >= 15){
			$cangetoff=0;
		}
		if($speedx <= -15){
			$cangetoff=0;
		}
		if($speedy >= 15){
			$cangetoff=0;
		}
		if($speedy <= -15){
			$cangetoff=0;
		}
		if($speedz >= 15){
			$cangetoff=0;
		}
		if($speedz <= -15){
			$cangetoff=0;
		}
		if($cangetoff==0){
			msg "You are going too fast to get off";
			msg "Try to slow down";
		}
		elseif($cangetoff==1){
			getoff;
			event "gotoff";
		}
	}
script=end

Previous Code >
edited 1×, last 10.04.21 01:50:50 am

old Re: Bugs in acceleration testing script

ModJuicer
Super User On Online

Quote
I fixed the script (except for maybe a small bug). The new script is shown above. You can use it if you give me credit. If there is a bug in it, please tell me, and if you can please try to fix it.

EDIT: The plane will randomly crash. Something is wrong with how the $accelx/y/z variable is calculate. I am running out of time to work on it now.
edited 2×, last 10.04.21 01:59:21 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewStranded II overviewForums overview