Nexus Modding > Scripting
Scripting Issues
The Old Dragon:
Well, I managed to find an alternative route round this one, got a tick running every five seconds which issues a 'SelectShips' command with a few conditions. Not particularly neat, but it works (for the most part).
But now I've got another happy little question...
If a ship (or any item really) is in a list, is it possible to get that list ID from the ship/item?
So, for example, just say a single ship in a squadron has a cloaking device. Once the squadron has located an enemy, then the cloaked ship will engage its cloak for maximum advantage. Now while cloaked, this ship won't be able to follow the AI orders of the other ships so I'll need to pluck it out and place it in a 'squadron' of it's own. My problem is finding the squadron list ID to begin with.
EDIT 15/06/10:
Kind of got an answer. If' it's a ship and it's in a formation than the answer's yes (needs some carefull setting up first though). Don't know about things not in a formation though.
Arparso:
Using IndexOf() it should be possible. You'd have to loop through all your squadron lists and look for your ship in one of them using the aforementioned IndexOf(). I wrote a short rule doing just that:
--- Code: ---// description: looks through all lists with ids between E.firstList
// and E.lastList to find E.object and returns the list's id or -1
// param: E.firstList - id of the first list to look through
// param: E.lastList - id of the last list to look through
// param: E.object - the object being searched
RULE event GetFirstListContainingObject
:action
// stores the list currently being searched, starts with first list
E.currentList := E.firstList;
// marks, if the object has been found yet (currently 0, false)
E.foundObject := 0;
// loop through all lists, unless the object has been found
While(E.currentList -1,
E.foundObject := 1;
);
// advance to the next list
E.currentList := E.currentList + 1;
);
// check, if the object has actually been found in one of the lists
If(E.foundObject = 1,
// object has been found
// get the last list id and return it to the event caller
E.currentList := E.currentList - 1;
Debug("Object", E.object, "was found in list", E.currentList);
return(E.currentList);
,
// else return -1
Debug("Object not found in any list");
return(-1);
);
:end
END
--- End code ---
Use it like so:
--- Code: ---E.listId := LocalEvent(GetFirstListContainingObject,
E.firstList := 10;
E.lastList := 14;
E.object := m.ship)
);
--- End code ---
There's one big problem regarding the scope of variables, though. Basically, every MACHINE has it's own lists. List 55 in one MACHINE can and probably will contain a totally different selection than list 55 in a different MACHINE. If the above rule for "GetFirstListContainingObject" is not in the same MACHINE as the place where you're calling it via LocalEvent(), it won't be able to access the correct lists and give wrong results. Sadly I don't know a way around this issue...
Also don't search through lists with the Id -1, because the above code returns -1 as error code, if it didn't find the object in any of the lists. If including the list -1 in the search, you couldn't differentiate between "not found" and "found in list -1" ;)
PS: While looking at the list of script commands Nexus offers, I realize I could have used InSelection() instead of IndexOf(), but it works either way.
The Old Dragon:
Thanks Arparso, that's certainly opened up a new avenue or two.
Quick question, where did you get the 'E.FirstList' & 'E.LastList' parameters from? It's the first time I've seen those particular variables.
My solution went along these lines...
--- Code: --- E.Leader:=E.ship:FormLeader;
Debug("Squadron leader is ",E.Leader);
E.Index:=IndexOf(M.LeadersList,E.Leader);
ThisSquadron:=GetN(M.SquadIndex,E.Index);
Debug("This Squadron is ",ThisSquadron);
M.NewList:=GetfreeSel();
SelectShips(M.NewList,InSelection(ThisSquadron,S.this));
ExecList(M.NewList,
Debug(ThisSquadron,"Squadron consists of ",S.this);
);
--- End code ---
I should point out that during the filtering process, all available ships are placed in formations which are then catalogued (M.SquadIndex) with the formation leaders also being recorded (M.LeadersList). Although I believe this'll be sufficient for my needs (at least for now, lol), I daresay I'll integrate your approach at some point to handle any possible stationary objects.
Once again, thank you :thumbup:
Arparso:
--- Quote ---Quick question, where did you get the 'E.FirstList' & 'E.LastList' parameters from? It's the first time I've seen those particular variables.
--- End quote ---
Well, I just defined them on my own. As you know, you can raise a certain event using one of the following commands:
* LocalEvent(event, var_set)
* PEvent(event, var_set)
* MEvent(event, var_set)
* RootEvent(event, var_set)
* UEvent(event, var_set)
* Timer(event, time, var_set)
* ...
These commands will execute all "reachable" (*) RULEs belonging to that particular event and supply them with a list of named parameters in var_set. Like so:
--- Code: ---// no parameters:
LocalEvent(myEvent, 0);
// one parameter containing the number 1:
LocalEvent(myEvent, E.myParameter := 1);
// one parameter containing the value of another variable:
LocalEvent(myEvent, E.myShip := M.playerShip);
// multiple parameters combined:
LocalEvent(myEvent, E.myParameter := 1; E.myShip := M.playerShip; E.anotherParameter := P.count);
--- End code ---
You can name these parameters as you wish, much like I named mine E.firstList, E.lastList and E.object. Predefined events such as FatalDamaged already come with a range of variables supplied by the game itself, but generally work just the same.
(*) what RULEs are "reachable" depends on the command itself and its location in the script. E.g. LocalEvent can reach each RULE in its own MACHINE and each embedded "child" MACHINE. Calling LocalEvent at the "root" SceneInit-RULE that every mission has, can reach ALL rules belonging to that event in the whole mission script, for example, because all of the mission's rulesets/MACHINEs are "children" of that root level. Calling LocalEvent() inside a MACHINE, however, won't execute any RULE outside that particular MACHINE (and its embedded child MACHINES, if it has any).
Mularac:
Today I was working on a scripted "progress bar" for the repairing devices tab (critical for one mission, where you start with all your devices off-line (damage 100)). However, if you set the damage of a device to '100', you can't then set it to anything other than '0' (the variable will be changed, but nothing will appear on the gui until the bar reaches '0'.
The workarround to that problem I found was setting the damage to 99, but then the ship will start to automatically fix the devices, as it is supposed to, but completely screwing the "climax" of the mission.
So my question:
a) is there an other work-arround to my 1° problem?
b) if not, anyone know a way to stop the ship from fixing it's devices withouth altering the tacticstypes.ini?
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version