Nexus Modding > Scripting
Scripting Issues
Mularac:
Arparso: Yes I know, I did that from the start (I in fact used the asteroid generator of the mission editor ranging from 3 or 4 shipclass and then I replaced those with my shipclases), I was looking for something better.
Old Dragon: Thanks a lot, I'll look into it when I have some time.
Arparso:
I've made a few modifications to Old Dragons script to make it just a bit more flexible. Your typical shipwreck should look like this in the mission file:
--- Code: ---SHIP
Name "Wreck1"
Class #my_shipclass
Race #race_Wrecks
Behaviour 4
Position 4934.08 -4970.09 4627.69
Orientation 8.22877 41.7865 -14.8206
END
--- End code ---
It's important to define both a race and behaviour 4. If you leave out the behavior, the wreck will initially contribute to the ship limit and the game will crash, if there are too many. You won't even get to your SceneInit rule to change the behaviour, because the game will crash way before that.
The race is important to make selecting your wrecks easier and also to disable the default ship animation including blinking lights. For some reason I couldn't disable that on raceless ships... and a wreck with blinking position lights, rotating sections or simply glowing "windows" doesn't look much like a wreck. The downside is: as long as a race is specified for that wreck, you can't enable the animation again, which you might want to do on certain special wrecks the player is supposed to have a look at or something. But that's probably not the general case, so for all "normal" wrecks a race works just fine. Probably stick to a special "wreck race", so you don't accidently wreck the wrong ships.
Second part is Old Dragon's slightly modified machine:
--- Code: ---MACHINE "Wrecker"
STATE Default
RULE event In
:action
// select all wrecks
Wrecks:=GetFreeSel();
Select(Wrecks, S.race = #race_Wrecks & S.behaviour = 4);
If(AllNumOf(Wrecks) > 0,
// make all wrecks visible to the player (and everyone else)
ExecList(Wrecks,
MakeFullyKnown(s.this);
FreezeReconState(s.this, 1);
);
// make each wreck "float" in space
LocalEvent(MakeFloat);
,
// leave state, if there were no wrecks at all
LeaveState();
);
:end
END
RULE event MakeFloat
:action
// randomly pick a wreck
E.Wreck := Pick(Wrecks);
// temporarely make it a normal ship and apply some damage
E.Wreck:behaviour := 0;
E.Wreck:damage := 65;
// make it a wreck again
E.Wreck:Behaviour:=4;
// remove current wreck from the list
RemoveItem(Wrecks,E.Wreck);
E.Wreck:=0;
// repeat above for all remaining wrecks and leave current state, if done
If(AllNumOf(Wrecks) > 0,
LocalEvent(MakeFloat);
,
LeaveState();
);
:end
END
END
END //end machine "Wrecker"
--- End code ---
Selecting the wrecks is now a breeze as you just look for the "wreck race" and "behaviour 4" setting. Strangely, wrecks with a race won't be visible to the player immediately, so I added the MakeFullyKnown/FreezeReconState bit for every wreck. The rest of the machine is more or less the same, except for two changes:
* I made "M.Change" from a global variable to a local event variable "E.Wreck", so it isn't visible in any other part of the mission script
* I added LeaveState() after the machine has done its job to prevent it from ever running again (for example, if you use LocalEvent(MakeFloat) somewhere in a mission-level rule, you WILL call this machine as well, which you probably didn't want to... so LeaveState() works just as a safeguard here)I had a quick test mission with a hundred wrecked Hecate-class destroyers in my FreeSpace mod, which worked really well. Even perfomance wasn't an issue with all these huge ships, probably because the 100+ blink lights on each ship weren't active and no AI was needed for them.
Arparso:
Okay, small addendum:
The script somewhat fails, if you've got more than 256 wrecks. I tried it with 1000 and apart from the bad performance, quite a lot of the wrecks didn't float like they actually should. It turns out, they weren't picked up by the script, because the wreck list only selected the first 256 wrecks. Trying to raise the list's capacity using Dim(list, size) crashed the game for values above 256, so it seems Nexus only supports lists/selections with up to 256 items.
What a bummer... :(
The Old Dragon:
Little question, I'm trying to select all ships in the scene except the players and any possible stations/ platforms, etc. This is my current line...
--- Code: ---SelectShips(MainList,Not(S.race=#race_Player)&HasDevType(S.this,S.Engine));
--- End code ---
It all works exept for the 'S.Engine' part (I'm using the engines as a filter 'cause that's the one thing that a stationary object shouldn't require). Anyone got an idea on how to get the last part working?
Mularac:
Did you try using inSet instead of s.engine? (sorry, I can't try anything right now, I'm writing from my linux partition)
Also, if that doesn't work a much uglier way could be this:
--- Code: ---selectShips(mainList, s.this:race!=#race_player); //select all the non-player ships
execlist(mainList,
selectDevices(1, s.this, InSet(s.this, 50)); //put in the list 1 all the devices that fall under the set 50 (engines)
If(AllNumOf(1)!=0, removeItem(mainList, s.this)); //and if that list isn't empty then remove that ship from the mainList (because it has at least one engine)
);
--- End code ---
Sorry I didn't test... but it may work. And it's ugly as hell. So you should just wait to have Arparso tell you the way it's done :P
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version