forked from Krutchen/SLMCLBA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MLBA_v001.lsl
401 lines (375 loc) · 19.3 KB
/
MLBA_v001.lsl
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/*
Module LBA v001 by Shaxei(datbot)
In order to use this armour system your physbase should
listen on channel -255 for messages from the physbase
Death commands start with "die," followed by a number
representing the cause of death which may be sent to
the wreckage to induce different sets of effects.
the cause being '2' means ammo explosion,
'1' means the fuel/engine burning down.
Upon recieving the command "crewdie" the sitbase should eject and kill
the user, since this means the crew of the vehicle has been killed.
The physbase's core script should also send this script a link message
with the text 'newcrew' when a new user sits on the vehicle, to reset
the crew's health pool lest they die on the next hit.
If you wish to see particle effects for engine damage and ammo cookoff then
your physbase should include two upright prims where the engine is
located called 'enginefx' and 'enginefx2' for engine fire/smoke particles
and one where an ammo fire would erupt from (commander's hatch) called 'ammofx'
If your vehicle re-rezzes its physbase or wants to rez it with specific health values
then it should first set its own description as follows:
"LBA.v.,"+(string)enginehealth+","+(string)transhealth+","+(string)crewhealth+","+(string)ammohealth
e.g.
LBA.v.,50,40,30,30
This system was designed to be used in vehicles that retain their physbases
when the user disembarks (or is ejected) so that they can continue to burn
and have armour. If you don't plan on having your vehicles work this way,
it's recommended to have your vehicle continue to burn down after de-rezzing
its physbase if the engine's health is below half or the ammo's health is
below 20%.
Adjust everything below to match your vehicle.
Note that this should be set to your EFFECTIVE armour thicknesses
since in the hit angle calculations you are always represented as a cuboid.
(aka 100mm of armour angled at 45 degrees should be written below as 200mm of armour)
*/
float frontarmour=0.5; //Effective armour thicknesses in metres (0.5=500mm)
float sidearmour=0.2;
float reararmour=0.06;
float toparmour=0.06;
float bottomarmour=0.07;
vector enginepos=<-2,0,0>; //the engine's position relative to the root
float enginehealthmax=70;
/*Keep in mind when setting the above that the engine catches fire and essentially
dooms the vehicle to burning down unless repaired when it drops below half its max*/
vector transpos=<-2.5,0,0>;
float transhealthmax=20;
vector ammopos=<-0.5,0,0>;
float ammohealthmax=30;
vector crewpos=<1,0,0>;
float crewhealthmax=50;
//Add your own particle effects for engine smoke, engine fire, and ammo cook-off in here
//(optional, only use if you have the particle emitter prims set up)
enginesmoke()
{
llLinkParticleSystem(enginefx,[]);
llLinkParticleSystem(enginefx2,[]);
}
enginefire()
{
llLinkParticleSystem(enginefx,[]);
llLinkParticleSystem(enginefx2,[]);
}
ammofire()
{
llLinkParticleSystem(ammofx,[]);
}
//NO TOUCHING ANYTHING BELOW HERE FAM (unless it specifically says you can uncomment it for features/debugging)
vector siz;
float hitangl;
vector lochit;
vector lochitN;
rotation rothit;
vector hn;
float anglehitat;
float armour;
list recents;
integer i;
key sitbase;
float pen;
string mesg;
string hitface;
float mofs;
integer ammofx;
integer enginefx;
integer enginefx2;
float crewhealth;
float transhealth;
float enginehealth;
float ammohealth;
key hitby;
integer ERAr;
integer ERA=7; //Bitwise integer representing which sides of your vehicle have ERA, add up and set this number to the total for 1=front 2=left 4=right 8=rear (4+2+1=7)
ref()
{
llSetObjectDesc("LBA.v.MLBA,"+(string)llRound(enginehealth)+","+(string)llRound(transhealth)+","+(string)llRound(crewhealth)+","+(string)llRound(ammohealth)+","+(string)ERAr);
llSetText(
"ENG: "+(string)(llRound(enginehealth)%90000)+"/"+(string)llRound(enginehealthmax)+" TRA: "+(string)(llRound(transhealth)%90000)+"/"+(string)llRound(transhealthmax)+
"\nCRW: "+(string)(llRound(crewhealth)%90000)+"/"+(string)llRound(crewhealthmax)+" AMM: "+(string)(llRound(ammohealth)%90000)+"/"+(string)llRound(ammohealthmax),<1,1,1>,1);
if(enginehealth<0 || ammohealth<0){
llLinkParticleSystem(-1,[]);
llSetText("",<0,0,0>,0);
if(ammohealth<0){
llRegionSayTo(sitbase,-255,"die,2");
}else{
llRegionSayTo(sitbase,-255,"die,1");
}
llSleep(.2);llDie();
}else if(crewhealth<0){
llRegionSayTo(sitbase,-255,"crewdie");
}
if(enginehealth<enginehealthmax*.5||ammohealth<ammohealthmax*.2){
if(enginehealth<enginehealthmax*.5){
enginefire();
llTriggerSound("ce357b58-03aa-1526-58e5-2bb81b8f8d81",1);
}else{
llLinkParticleSystem(enginefx,[]);
llLinkParticleSystem(enginefx2,[]);
}
if(ammohealth<ammohealthmax*.2){
ammofire();
llTriggerSound("ce357b58-03aa-1526-58e5-2bb81b8f8d81",1);
}else{
llLinkParticleSystem(ammofx,[]);
}
llSetTimerEvent(3);
}else{
if(enginehealth<enginehealthmax*.7){
llTriggerSound("69f8d03b-9c1f-7014-2a8e-c75c0022232a",1);
enginesmoke();
}else{
llLinkParticleSystem(enginefx,[]);
llLinkParticleSystem(enginefx2,[]);
}
llLinkParticleSystem(ammofx,[]);
llSetTimerEvent(0);
}
}
integer hcd;
default
{
touch_start(integer ndtt)
{
if(llGetUnixTime()-hcd>5){
hcd=llGetUnixTime();
llRegionSayTo(llDetectedKey(0),0,
"This is an LBA-based armour system that simulates effective armour thickness and module damage
Effective penetration of a projectile = damage*0.012*(1-(angle-of-attack/90))
e.g. 50LBA rocket hitting at 45 degrees = 300mm, hitting at 0 degrees = 600mm
If penetration>armour of the side it hit then damage is delivered to the crew, ammo, engine, and transmission within a 5m radius
the closer to the hit position, the more damage done to each module up to a maximum of the round's full damage
If the crew dies, the tank's user is ejected and killed. If the ammo is destroyed, the tank cooks and explodes.
If the engine is destroyed, the tank burns down and is destroyed. If the transmission is destroyed, the tank cannot move.");
llRegionSayTo(llDetectedKey(0),0,"
Specifics for this tank:
Front armour:"+(string)llRound(frontarmour*1000)+"mm
Side armour: "+(string)llRound(sidearmour*1000)+"mm
Rear armour: "+(string)llRound(reararmour*1000)+"mm
Top armour: "+(string)llRound(toparmour*1000)+"mm
Bottom armour: "+(string)llRound(bottomarmour*1000)+"mm
Engine position: "+(string)enginepos+"m
Engine maxhealth: "+(string)llRound(enginehealthmax)+"LBA
Trans position: "+(string)transpos+"m
Trans maxhealth: "+(string)llRound(transhealthmax)+"LBA
Ammo position: "+(string)ammopos+"m
Ammo maxhealth: "+(string)llRound(ammohealthmax)+"LBA
Crew position: "+(string)crewpos+"m
Crew maxhealth: "+(string)llRound(crewhealthmax)+"LBA"
);
}
}
link_message(integer sndr,integer val,string txt,key idd)
{
if(txt=="newcrew"){crewhealth=crewhealthmax;ref();}
}
on_rez(integer rz)
{
sitbase=llList2Key(llGetObjectDetails(llGetKey(),[OBJECT_REZZER_KEY]),0);
string d=llList2String(llGetObjectDetails(sitbase,[OBJECT_DESC]),0);
if(llGetListLength(llCSV2List(d))==5){ //if my sitbase's description stored the last physbase's values then take and use them
enginehealth=llList2Float(llCSV2List(d),1);
transhealth=llList2Float(llCSV2List(d),2);
crewhealth=llList2Float(llCSV2List(d),3);
ammohealth=llList2Float(llCSV2List(d),4);
ERAr=llList2Integer(llCSV2List(d),5);
}
list bb=llGetBoundingBox(llGetKey());
siz=llList2Vector(bb,1)-llList2Vector(bb,0);
siz*=.5;
llListen((integer)("0x" + llGetSubString(llMD5String((string)llGetKey(),0), 0, 3)), "","","");
ref();
if(transhealth<=0){llMessageLinked(LINK_THIS,0,"immobile","");} //if I was rezzed with no transmission health then be immobile
}
state_entry()
{
enginehealth=enginehealthmax;
transhealth=transhealthmax;
ammohealth=ammohealthmax;
crewhealth=crewhealthmax;
ERAr=ERA;
for(i=1;i<llGetNumberOfPrims()+1;i++){
if(llGetLinkName(i)=="enginefx"){enginefx=i;}
if(llGetLinkName(i)=="enginefx2"){enginefx2=i;}
if(llGetLinkName(i)=="ammofx"){ammofx=i;}
}
}
collision_start(integer ndt)
{
for(i=0;i<ndt;i++){
if(llVecMag(llDetectedVel(i))>50){
lochit=(llDetectedPos(i)-llGetPos())/llGetRot();
rothit=llRotBetween(<1,0,0>,llDetectedVel(i))/llGetRot();
recents=[llDetectedKey(i),lochit,rothit]+llListReplaceList(recents,[],9,11);
}
}
}
listen(integer i, string s, key k, string m)
{
list l = llCSV2List(m);
string target = llList2String(l,0);
integer dmg = (integer)llList2String(l,1);
if(target == (string)llGetKey())
{
hitby=llGetOwnerKey(k);
if(dmg>0){
llResetTime();
key rzr=llList2Key(llGetObjectDetails(k,[OBJECT_REZZER_KEY]),0);
if(llListFindList(recents,[k])!=-1){
lochit=llList2Vector(recents,llListFindList(recents,[k])+1);
rothit=llList2Rot(recents,llListFindList(recents,[k])+2);
}else if(llListFindList(recents,[rzr])!=-1){
lochit=llList2Vector(recents,llListFindList(recents,[rzr])+1);
rothit=llList2Rot(recents,llListFindList(recents,[rzr])+2);
}else{
lochit=llVecNorm( (llList2Vector(llGetObjectDetails(k,[OBJECT_POS]),0)-llGetPos())/llGetRot() );
//rothit=llRotBetween(<-1,0,0>,lochit);
rothit=ZERO_ROTATION;
}
lochitN=<lochit.x/siz.x,lochit.y/siz.y,lochit.z/siz.z>;
if(llFabs(lochitN.x)>llFabs(lochitN.y)&&llFabs(lochitN.x)>llFabs(lochitN.z)){
if(lochitN.x>0){
hn=<1,0,0>;armour=frontarmour;hitface="front";lochit.x=siz.x;
if(ERAr&1&&dmg>9){
if(llSubStringIndex(s,"AP")==-1 && llSubStringIndex(llToLower(s),"piercing")==-1 && llSubStringIndex(llToLower(s),"sabot")==-1){armour+=.3;}
ERAr-=1;mesg="Detonated front ERA\n";llTriggerSound("cb31159c-9d1c-6306-908b-09979f6a0e61",1);
}
}else{
hn=<-1,0,0>;armour=reararmour;hitface="rear";lochit.x=-siz.x;
if(ERAr&8&&dmg>9){
if(llSubStringIndex(s,"AP")==-1 && llSubStringIndex(llToLower(s),"piercing")==-1 && llSubStringIndex(llToLower(s),"sabot")==-1){armour+=.3;}
ERAr-=8;mesg="Detonated rear ERA\n";llTriggerSound("cb31159c-9d1c-6306-908b-09979f6a0e61",1);
}
}
}else if(llFabs(lochitN.y)>llFabs(lochitN.z)){
armour=sidearmour;
if(lochitN.y>0){
hn=<0,1,0>;hitface="left";lochit.y=siz.y;
if(ERAr&2&&dmg>9){
if(llSubStringIndex(s,"AP")==-1 && llSubStringIndex(llToLower(s),"piercing")==-1 && llSubStringIndex(llToLower(s),"sabot")==-1){armour+=.3;}
ERAr-=2;mesg="Detonated left ERA\n";llTriggerSound("cb31159c-9d1c-6306-908b-09979f6a0e61",1);
}
}else{
hn=<0,-1,0>;hitface="right";lochit.y=-siz.y;
if(ERAr&4&&dmg>9){
if(llSubStringIndex(s,"AP")==-1 && llSubStringIndex(llToLower(s),"piercing")==-1 && llSubStringIndex(llToLower(s),"sabot")==-1){armour+=.3;}
ERAr-=4;mesg="Detonated right ERA\n";llTriggerSound("cb31159c-9d1c-6306-908b-09979f6a0e61",1);
}
}
}else{
if(lochitN.z>0){
hn=<0,0,1>;armour=toparmour;hitface="top";lochit.z=siz.z;
}else{
hn=<0,0,-1>;armour=bottomarmour;hitface="bottom";lochit.z=-siz.z;
}
}
if(rothit!=ZERO_ROTATION){
anglehitat=llAngleBetween(ZERO_ROTATION,llRotBetween(hn,<-1,0,0>*rothit))/DEG_TO_RAD;
pen=(dmg*0.012*(1-(anglehitat*.011)))-armour;
}else{
pen=(dmg*0.012)-armour;
}
if(pen>0){
mesg+=(string)dmg+" basedmg: Penetrated "+hitface+" side ("+(string)llRound(dmg*12)+"mm*"+(string)llRound(anglehitat)+"°="+(string)llRound(pen*1000)+"mm>"+(string)llRound(armour*1000)+"mm)";
//mofs=llVecDist(<1,0,0>*rothit,llVecNorm(enginepos-lochit))*1.5;
mofs=llVecDist(lochit+<1,0,0>*rothit,enginepos)*.2;
if(mofs<1){
enginehealth-=dmg*(1-mofs);
if(enginehealth<0 && enginehealth>-9000){mesg+="Engine:destroyed ";enginehealth=-90000;
}else{mesg+="Engine:"+(string)llRound(enginehealth)+"/"+(string)llRound(enginehealthmax)+"hp(-"+(string)llRound(dmg*(1-mofs))+") ";}
}
mofs=llVecDist(lochit+<1,0,0>*rothit,transpos)*.2;
if(mofs<1){
transhealth-=dmg*(1-mofs);
if(transhealth<0 && transhealth>-9000){mesg+="Trans:destroyed ";transhealth=-90000;llTriggerSound("e9b5b4a7-bcb7-58ff-e831-47e9ceeda248",1);llMessageLinked(LINK_THIS,0,"immobile","");
}else if(transhealth>-9000){mesg+="Trans:"+(string)llRound(transhealth)+"/"+(string)llRound(transhealthmax)+"hp(-"+(string)llRound(dmg*(1-mofs))+") ";}
}
mofs=llVecDist(lochit+<2,0,0>*rothit,ammopos)*.2;
if(mofs<1){
ammohealth-=dmg*(1-mofs);
if(ammohealth<0 && ammohealth>-9000){mesg+="Ammo:destroyed ";ammohealth=-90000;
}else if(ammohealth>-9000){mesg+="Ammo:"+(string)llRound(ammohealth)+"/"+(string)llRound(ammohealthmax)+"hp(-"+(string)llRound(dmg*(1-mofs))+") ";}
}
mofs=llVecDist(lochit+<2,0,0>*rothit,crewpos)*.2;
if(mofs<1){
crewhealth-=dmg*(1-mofs);
if(crewhealth<0 && crewhealth>-9000){mesg+="Crew:killed ";crewhealth=-90000;
}else if(crewhealth>-9000){mesg+="Crew:"+(string)llRound(crewhealth)+"/"+(string)llRound(crewhealthmax)+"hp(-"+(string)llRound(dmg*(1-mofs))+") ";}
}
//llOwnerSay("Succ Proc time: "+(string)llGetTime()); //debugging message, tell me how long we took to process this damage
llRegionSayTo(hitby,0,mesg);
llWhisper(0,"damage recieved from "+llKey2Name(hitby)+" via "+s+":\n"+mesg);
//llRegionSayTo(sitbase,-255,"dmg,"+(string)lochitN+",0"); //Uncomment to send the relative hit position to the sitbase, for damage decals
llTriggerSound(llList2String(["32036145-8205-d4a4-8518-3d7f9f5de0d5","b0820b49-3ea6-b7b7-5a27-cfaff169427c","3977dd91-ad56-6b8e-e5cb-75fb817aaba1"],llFloor(llFrand(3))),1);
}else{
mesg+=(string)dmg+" basedmg: Didn't penetrate "+hitface+" side ("+(string)llRound(dmg*12)+"mm*"+(string)llRound(anglehitat)+"°="+(string)llRound(pen*1000)+"mm<"+(string)llRound(armour*1000)+"mm)";
llRegionSayTo(hitby,0,"\n"+mesg);
//llWhisper(0,"damage recieved from "+llKey2Name(hitby)+" via "+s+":\n"+mesg);
if(dmg>4){
//llRegionSayTo(sitbase,-255,"dmg,"+(string)lochitN+",1"); //Uncomment to send the relative hit position to the sitbase, for damage decals
llTriggerSound(llList2String(["513bf948-b2b8-fe36-0064-fc5a7f58fd52","60bda7e2-56e2-7031-6a8a-a945ee1e1c6b","72711778-7eb3-4608-3d86-9bc1aee2f54a"],llFloor(llFrand(3))),1);
}else{
llTriggerSound("34b809cf-a833-d433-911d-b0d914d82260",1);
}
}
}else{
ammohealth-=dmg/3;
if(ammohealth>ammohealthmax){ammohealth=ammohealthmax;}
enginehealth-=dmg/3;
if(enginehealth>enginehealthmax){enginehealth=enginehealthmax;}
if(transhealth<0){transhealth=0;}
transhealth-=dmg/3;
if(transhealth>transhealthmax){transhealth=transhealthmax;llMessageLinked(LINK_THIS,0,"mobile","");}
if(ammohealth>=ammohealthmax && enginehealth>=enginehealthmax && transhealth>=transhealthmax){ERAr=ERA;}
}
ref();
}
}
timer()
{
if(enginehealth<enginehealthmax*.5){
enginehealth-=1;
if(llVecDist(enginepos,ammopos)<10){ammohealth-=(10-llVecDist(enginepos,ammopos))*.1;}
if(llVecDist(enginepos,crewpos)<10){crewhealth-=(10-llVecDist(enginepos,crewpos))*.1;}
enginefire();
llTriggerSound("ce357b58-03aa-1526-58e5-2bb81b8f8d81",1);
}else{
llLinkParticleSystem(enginefx,[]);llLinkParticleSystem(enginefx2,[]);
}
if(ammohealth<ammohealthmax*.2){
ammohealth-=1;
if(llVecDist(enginepos,ammopos)<10){enginehealth-=(10-llVecDist(enginepos,ammopos))*.1;}
if(llVecDist(crewpos,ammopos)<10){crewhealth-=(10-llVecDist(enginepos,crewpos))*.1;}
ammofire();
llTriggerSound("ce357b58-03aa-1526-58e5-2bb81b8f8d81",1);
}else{
llLinkParticleSystem(ammofx,[]);
}
llSetObjectDesc("LBA.v.,"+(string)llRound(enginehealth)+","+(string)llRound(transhealth)+","+(string)llRound(crewhealth)+","+(string)llRound(ammohealth)+","+(string)ERAr);
llSetText(
"ENG: "+(string)(llRound(enginehealth)%90000)+"/"+(string)llRound(enginehealthmax)+" TRA: "+(string)(llRound(transhealth)%90000)+"/"+(string)llRound(transhealthmax)+
"\nCRW: "+(string)(llRound(crewhealth)%90000)+"/"+(string)llRound(crewhealthmax)+" AMM: "+(string)(llRound(ammohealth)%90000)+"/"+(string)llRound(ammohealthmax),<1,1,1>,1);
if(enginehealth>enginehealthmax*.5&&ammohealth>ammohealthmax*.2){
llSetTimerEvent(0);llLinkParticleSystem(-1,[]);
}else if(enginehealth<=0 || ammohealth<=0){
llLinkParticleSystem(-1,[]);
llSetText("",<0,0,0>,0);
if(ammohealth<=0){
llRegionSayTo(sitbase,-255,"die,2");
}else{
llRegionSayTo(sitbase,-255,"die,1");
}
llSleep(.2);llDie();
}else if(crewhealth<0){
llRegionSayTo(sitbase,-255,"crewdie");
}
}
}