Nexus Modding > Scripting
Scripting Issues
The Old Dragon:
Hi folks,
I've got a little bit of a sticky script that's been holding me up for a day or two.
What I'm trying to achieve is a script that will...
1) Install a device (well, a transport ship really, but the game sees it as a device) on a certain entity.
2) Send said device/transport model to a second entity.
3) When the device/transport gets close to the second entity, transfer and dock the device/transport.
4) Once docked, delete said device/transport to make room for others.
At the moment, I'm as far as docked. The debug code kicks to tell me that the transport has docked but I'm having trouble isolating the recently docked object from the rest. At the moment, it'll either ignore the fact that they're docking or destroy everything within the area regardless of whether it's docked or not. Here's the code I've got for the 'sticky' bit...
--- Code: ---If(E.location=M.CH_O,
TSD:=GetFreeSel();
SelectDevices(TSD,M.CH_O,Inset(S.this,25)&E.ship:docking=4);
ExecList(TSD,
Dump(TSD);
Debug("Deleting Station Transport");
DeleteDevice(S.this);
);
);
--- End code ---
Anyone have an idea on how to resolve this little issue?
EDIT:
Blooming typical, I post for a solution to something that's been bothering me for days, then ten minutes later I find one. Life sure can be mean sometimes.
By adding a 'distance' section to the condition, I've got it to do what I wanted. But if anyone knows of a neater solution, I'm still all ears.
Mularac:
so... what was the solution?
anyway, I have an other problem, a lot simpler but it still bugs me like hell:
here's the deal. I've been working on a machine that will search for brusque changes in the shield integrity values of a ship, or otherwise, it'll keep a close watch if you manually disengage shields for some reason, it'll then store the previous value of the shield integrity (so far so good) and it will, supposedly, add it back to the shield via the M.Ship:=ShieldIntegrity:=*value*; command.
But there comes my problem, if i place the variable name in the *value* slot, the game will crash with a cExpression.cpp Line:521.
so... perhaps I'm doing somithing wrong there, I'm not too fluent with nexus variables...
anyway, here's the code:
--- Code: --- RULE event Tick //I start the tick line
:action
debug("tick1");
if(flag=1, //this is a check so that the variable is not overwritten after the shield drain
set(shield,m.pship.5:ShieldIntegrity);
debug(shield); //I declare and show the "shield" variable on the console
);
Delay(0,2.9, //I set a 2.9 delay because the tick refreshes every 3 sec, and I want the less dead time possible.
set(shield2,m.pship.5:ShieldIntegrity); //I declare the variable "shield2" as the value of the shield integrity 2.9 seconds after the first check
debug("tick2");
debug(shield2);
if(shield2=0, //and here comes the magic: if the shield has been drained I perform this check
flag:=0; //I disable the check
debug("drained and the shield value is:");
debug(shield); //debuggind purposes
if(shield>1000, //and here I compare the two values. if the previous value was higher than 1000, the if will take over. This is meant to avoid triggers caused by "regular" shield draining.
debug("charged");
debug(shield);
m.pship.5:=shieldintegrity:=shield; //}And in here I refil the ships' shield tank with the previous charge.
);
);
,0);
:end
END
tick 3
--- End code ---
Damn.... there's got to be something magical about this site.... Old Dragon, same thing happened to me. The solution came no more than 10' after I finished typing this... the error was this:
m.pship.5:=shieldintegrity:=shield;
it should have been:
m.pship.5:shieldintegrity:=shield;
now I have to figure out how to make this thing generic....
Arparso:
That got to be the best help thread ever ... problems solving themselves - every tech support guy's wet dream ;)
The Old Dragon:
Indeed there is... it's the magic of Arparso, lol. The very thought of posting it on the Skirmisher forum seems to make the problem roll over and play dead. lol
But more seriously, the solution code to my problem is...
--- Code: ---If(E.location=M.CH_O,
TSD:=GetFreeSel();
SelectDevices(TSD,M.CH_O,Inset(S.this,25)&E.ship:docking=4&Distance(S.this,M.CH_O)
Arparso:
You could also store the last shield value directly at the object level like this:
--- Code: ---TICK 1
RULE event Tick
:action
SelectEx(s.ship & s.isShielded,
s:this:lastShieldIntegrity:=s:this:shieldIntegrity;
Debug("saved shield for", s.this, "with", s:this:lastShieldIntegrity);
);
:end
END
--- End code ---
If the shield is currently active, it stores the current shieldIntegrity in the lastShieldIntegrity variable for each object. If the shield is not active, the value won't be overridden.
Navigation
[0] Message Index
[#] Next page
Go to full version