Updated damage code

This commit is contained in:
J Maverick 16 2016-07-04 20:36:16 +02:00 committed by GitHub
parent 8033cdf585
commit d60dee869b

View File

@ -1,3 +1,11 @@
#
# Install: Include this code into an aircraft to make it damagable. (remember to add it to the -set file)
#
# Author: Nikolai V. Chr. (with some improvement by Onox and Pinto)
#
#
var clamp = func(v, min, max) { v < min ? min : v > max ? max : v }
var TRUE = 1;
@ -34,6 +42,7 @@ var warhead_lbs = {
"M71": 200.00,
"MK-82": 192.00,
"LAU-68": 10.00,
"M317": 145.00,
};
var incoming_listener = func {
@ -52,10 +61,11 @@ var incoming_listener = func {
# a m2000 is firing at us
m2000 = TRUE;
}
if (last_vector[1] == " FOX2 at" or last_vector[1] == " aim7 at" or last_vector[1] == " aim9 at"
or last_vector[1] == " aim120 at" or last_vector[1] == " RB-24J fired at" or last_vector[1] == " RB-74 fired at"
or last_vector[1] == " RB-71 fired at" or last_vector[1] == " RB-15F fired at"
or last_vector[1] == " RB-99 fired at" or last_vector[1] == " KN-06 fired at" or m2000 == TRUE) {
if (last_vector[1] == " FOX2 at" or last_vector[1] == " Fox 1 at" or last_vector[1] == " Fox 2 at" or last_vector[1] == " Fox 3 at"
or last_vector[1] == " Greyhound at" or last_vector[1] == " Bombs away at" or last_vector[1] == " Bruiser at" or last_vector[1] == " Rifle at" or last_vector[1] == " Bird away at"
or last_vector[1] == " aim7 at" or last_vector[1] == " aim9 at"
or last_vector[1] == " aim120 at"
or m2000 == TRUE) {
# air2air being fired
if (size(last_vector) > 2 or m2000 == TRUE) {
#print("Missile launch detected at"~last_vector[2]~" from "~author);
@ -110,7 +120,7 @@ var incoming_listener = func {
}
}
}
} elsif ( 1 == 1) { #
} elsif (1==1) { # mirage: getprop("/controls/armament/mp-messaging")
# latest version of failure manager and taking damage enabled
#print("damage enabled");
var last1 = split(" ", last_vector[1]);
@ -129,6 +139,16 @@ var incoming_listener = func {
#print(type~"|");
if(distance != nil) {
var dist = distance;
if (type == "M90") {
var prob = rand()*0.5;
var failed = fail_systems(prob);
var percent = 100 * prob;
printf("Took %.1f%% damage from %s clusterbombs at %0.1f meters. %s systems was hit", percent,type,dist,failed);
nearby_explosion();
return;
}
distance = clamp(distance-3, 0, 1000000);
var maxDist = 0;
@ -153,7 +173,7 @@ var incoming_listener = func {
nearby_explosion();
}
}
} elsif (last_vector[1] == " M70 rocket hit" or last_vector[1] == " KCA cannon shell hit" or last_vector[1] == " Gun Splash On " or last_vector[1] == " M61A1 shell hit" or last_vector[1] == " GAU-8/A hit") {
} elsif (last_vector[1] == " M70 rocket hit" or last_vector[1] == " M55 cannon shell hit" or last_vector[1] == " KCA cannon shell hit" or last_vector[1] == " Gun Splash On " or last_vector[1] == " M61A1 shell hit" or last_vector[1] == " GAU-8/A hit") {
# cannon hitting someone
#print("cannon");
if (size(last_vector) > 2 and last_vector[2] == " "~callsign) {
@ -176,7 +196,7 @@ var incoming_listener = func {
var maxDamageDistFromWarhead = func (lbs) {
# very simple
var dist = 6*math.sqrt(lbs);
var dist = 3*math.sqrt(lbs);
return dist;
}
@ -203,6 +223,12 @@ var stopIncomingSound = func (clock) {
setprop("sound/incoming"~clock, 0);
}
var callsign_struct = {};
var getCallsign = func (callsign) {
var node = callsign_struct[callsign];
return node;
}
var nearby_explosion = func {
setprop("damage/sounds/nearby-explode-on", 0);
settimer(nearby_explosion_a, 0);
@ -217,12 +243,6 @@ var nearby_explosion_b = func {
setprop("damage/sounds/nearby-explode-on", 0);
}
var callsign_struct = {};
var getCallsign = func (callsign) {
var node = callsign_struct[callsign];
return node;
}
var processCallsigns = func () {
callsign_struct = {};
var players = props.globals.getNode("ai/models").getChildren();
@ -237,233 +257,9 @@ var processCallsigns = func () {
processCallsigns();
var logTime = func{
#log time and date for outputing ucsv files for converting into KML files for google earth.
if (getprop("logging/log[0]/enabled") == TRUE and getprop("sim/time/utc/year") != nil) {
var date = getprop("sim/time/utc/year")~"/"~getprop("sim/time/utc/month")~"/"~getprop("sim/time/utc/day");
var time = getprop("sim/time/utc/hour")~":"~getprop("sim/time/utc/minute")~":"~getprop("sim/time/utc/second");
setprop("logging/date-log", date);
setprop("logging/time-log", time);
}
}
var ct = func (type) {
if (type == "c-u") {
setprop("sim/ct/c-u", 1);
}
if (type == "rl" and getprop("gear/gear[0]/wow") != TRUE) {
setprop("sim/ct/rl", 1);
}
if (type == "rp" and getprop("gear/gear[0]/wow") != TRUE) {
setprop("sim/ct/rp", 1);
}
if (type == "a") {
setprop("sim/ct/a", 1);
}
if (type == "lst") {
setprop("sim/ct/list", 1);
}
if (type == "ifa" and getprop("gear/gear[0]/wow") != TRUE) {
setprop("sim/ct/ifa", 1);
}
if (type == "sf" and getprop("gear/gear[0]/wow") != TRUE) {
setprop("sim/ct/sf", 1);
}
}
var lf = -1;
var ll = 0;
var code_ct = func () {
var cu = getprop("sim/ct/c-u");
if (cu == nil or cu != 1) {
cu = 0;
}
var a = getprop("sim/ct/a");
if (a == nil or a != 1) {
a = 0;
}
var ff = getprop("sim/freeze/fuel");
if (ff == nil) {
ff = 0;
} elsif (ff == 1) {
setprop("sim/ct/ff", 1);
}
ff = getprop("sim/ct/ff");
if (ff == nil or ff != 1) {
ff = 0;
}
var cl = 0;
if (cl > (ll*1.05) and getprop("gear/gear[0]/wow") != TRUE) {
setprop("sim/ct/rl", 1);
}
ll = cl;
var rl = getprop("sim/ct/rl");
if (rl == nil or rl != 1) {
rl = 0;
}
var rp = getprop("sim/ct/rp");
if (rp == nil or rp != 1) {
rp = 0;
}
var cf = getprop("/consumables/fuel/tank[0]/level-gal_us")
+getprop("/consumables/fuel/tank[1]/level-gal_us")
+getprop("/consumables/fuel/tank[2]/level-gal_us")
+getprop("/consumables/fuel/tank[3]/level-gal_us")
+getprop("/consumables/fuel/tank[4]/level-gal_us");
if (cf != nil and lf != -1 and cf > (lf*1.1) and getprop("gear/gear[0]/wow") != TRUE and getprop("/systems/refuel/contact") == FALSE) {
setprop("sim/ct/rf", 1);
}
var rf = getprop("sim/ct/rf");
if (rf == nil or rf != 1) {
rf = 0;
}
lf = cf == nil?0:cf;
var dm = !getprop("/controls/armament/mp-messaging");
if (dm == nil or dm != 1) {
dm = 0;
}
var tm = 0;#getprop("sim/ja37/radar/look-through-terrain");
if (tm == nil or tm != 1) {
tm = 0;
}
var rd = 0;#!getprop("sim/ja37/radar/doppler-enabled");
if (rd == nil or rd != 1) {
rd = 0;
}
var ml = getprop("sim/ct/list");
if (ml == nil or ml != 1) {
ml = 0;
}
var sf = getprop("sim/ct/sf");
if (sf == nil or sf != 1) {
sf = 0;
}
var ifa = getprop("sim/ct/ifa");
if (ifa == nil or ifa != 1) {
ifa = 0;
}
var final = "ct"~cu~ff~rl~rf~rp~a~dm~tm~rd~ml~sf~ifa;
setprop("sim/multiplay/generic/string[15]", final);
settimer(code_ct, 2);
}
var not = func {
if (getprop("/controls/armament/mp-messaging") == TRUE and getprop("gear/gear[0]/wow") != TRUE) {
var ct = getprop("sim/multiplay/generic/string[15]") ;
var msg = "I might be chea"~"ting..";
if (ct != nil) {
msg = "I might be chea"~"ting.."~ct;
var spl = split("ct", ct);
if (size(spl) > 1) {
var bits = spl[1];
msg = "I ";
if (bits == "000000000000") {
settimer(not, 60);
return;
}
if (substr(bits,0,1) == "1") {
msg = msg~"Used CT"~"RL-U..";
}
if (substr(bits,1,1) == "1") {
msg = msg~"Use fuelf"~"reeze..";
}
if (substr(bits,2,1) == "1") {
msg = msg~"Relo"~"aded in air..";
}
if (substr(bits,3,1) == "1") {
msg = msg~"Refue"~"led in air..";
}
if (substr(bits,4,1) == "1") {
msg = msg~"Repa"~"ired not on ground..";
}
if (substr(bits,5,1) == "1") {
msg = msg~"Used time"~"warp..";
}
if (substr(bits,6,1) == "1") {
msg = msg~"Have dam"~"age off..";
}
if (substr(bits,7,1) == "1") {
msg = msg~"Have Ter"~"rain mask. off..";
}
if (substr(bits,8,1) == "1") {
msg = msg~"Have Dop"~"pler off..";
}
if (substr(bits,9,1) == "1") {
msg = msg~"Had mp-l"~"ist on..";
}
if (substr(bits,10,1) == "1") {
msg = msg~"Had s-fai"~"lures open..";
}
if (substr(bits,11,1) == "1") {
msg = msg~"Had i-fa"~"ilures open..";
}
}
}
setprop("/sim/multiplay/chat", msg);
}
settimer(not, 60);
}
var changeGuiLoad = func()
{#return;
var searchname1 = "mp-list";
var searchname2 = "instrument-failures";
var searchname3 = "system-failures";
var state = 0;
foreach(var menu ; props.globals.getNode("/sim/menubar/default").getChildren("menu")) {
foreach(var item ; menu.getChildren("item")) {
foreach(var name ; item.getChildren("name")) {
if(name.getValue() == searchname1) {
#var e = item.getNode("enabled").getValue();
#var path = item.getPath();
#item.remove();
#item = props.globals.getNode(path,1);
#item.getNode("enabled",1).setBoolValue(FALSE);
#item.getNode("binding").remove();
#item.getNode("name",1).setValue(searchname1);
item.getNode("binding/command").setValue("nasal");
item.getNode("binding/script").setValue("missile.loadMPList()");
#item.getNode("enabled",1).setBoolValue(TRUE);
}
if(name.getValue() == searchname2) {
item.getNode("binding/command").setValue("nasal");
item.getNode("binding/dialog-name").remove();
item.getNode("binding/script",1).setValue("missile.loadIFail()");
}
if(name.getValue() == searchname3) {
item.getNode("binding/command").setValue("nasal");
item.getNode("binding/dialog-name").remove();
item.getNode("binding/script",1).setValue("missile.loadSysFail()");
}
}
}
}
fgcommand("reinit", props.Node.new({"subsystem":"gui"}));
}
var loadMPList = func () {
ct("lst");multiplayer.dialog.show();
}
var loadSysFail = func () {
ct("sf");fgcommand("dialog-show", props.Node.new({"dialog-name":"system-failures"}));
}
var loadIFail = func () {
ct("ifa");fgcommand("dialog-show", props.Node.new({"dialog-name":"instrument-failures"}));
}
changeGuiLoad();
settimer(code_ct, 5);
settimer(not, 11);
setlistener("/sim/multiplay/chat-history", incoming_listener, 0, 0);
setprop("/sim/failure-manager/display-on-screen", FALSE);
#setprop("/sim/failure-manager/display-on-screen", FALSE);
var re_init = func {
# repair the aircraft