itemListCursor
- Betelgeuse
- Fleet Officer
- Posts: 1920
- Joined: Sun Mar 05, 2006 6:31 am
nope still doesn't work
Crying is not a proper retort!
- dvlenk6
- Militia Captain
- Posts: 519
- Joined: Sun Mar 05, 2006 6:56 am
- Location: Sanctuary and beyond
- Contact:
Well, you'll just have to settle for using the picker on a usescreen for the time being. Let the player pick the slot.
Only thing is that you lose the ability to force an inferior armor segment onto somebody.
Who's going to willingly install blast plate over holochroal or something?
Only thing is that you lose the ability to force an inferior armor segment onto somebody.
Who's going to willingly install blast plate over holochroal or something?
- Betelgeuse
- Fleet Officer
- Posts: 1920
- Joined: Sun Mar 05, 2006 6:31 am
well I was thinking more of non player ships and custom ships (trade having lesser armor for something else)
Crying is not a proper retort!
-
- Developer
- Posts: 2997
- Joined: Thu Jul 24, 2003 9:53 pm
- Contact:
A few things:
1. Burzmali is right that (shpInstallArmor) is missing an itemStruct version. I've added that to the next version. Of course, even then you will need to add the item to the ship before you try to install it.
2. Without the above fix, you can still do it using an item list cursor. The (objEnumItems) function will iterate using an item cursor. Do something like this:
(objEnumItems) will loop over all items on the given ship (shipToInstall) and of the given criteria (in this case, "aU" means all uninstalled armor segments).
On each pass through the loop, cursorVar will be set to point to one of the items that matches the criteria.
(IsThisTheArmorToInstall cursorVar) is some way of deciding whether this is the item to install. You might replace it with:
(eq (itmGetUNID (itmAtCursor cursorVar)) &itTitaniumPlate;)
Which checks to see if the armor is titanium plate (replace the constant as appropriate).
We set installDone to True because we don't want to install more than one item per loop. One problem with (objEnumItems) is that it doesn't work very well when the items are being changed inside the loop (which is what shpInstallArmor would do).
Your best bet is to create a function that wraps it all in a single function. Something like:
Then you can install 4 segments on a ship like this:
Note: I have not tried any of this code, so there might be typos and/or bugs.
1. Burzmali is right that (shpInstallArmor) is missing an itemStruct version. I've added that to the next version. Of course, even then you will need to add the item to the ship before you try to install it.
2. Without the above fix, you can still do it using an item list cursor. The (objEnumItems) function will iterate using an item cursor. Do something like this:
Code: Select all
(setq installDone Nil)
(objEnumItems shipToInstall "aU" cursorVar
(if (and (not installDone)
(IsThisTheArmorToInstall cursorVar))
(block Nil
(shpInstallArmor
shipToInstall
cursorVar
segmentToInstall
)
(setq installDone True)
)
)
)
On each pass through the loop, cursorVar will be set to point to one of the items that matches the criteria.
(IsThisTheArmorToInstall cursorVar) is some way of deciding whether this is the item to install. You might replace it with:
(eq (itmGetUNID (itmAtCursor cursorVar)) &itTitaniumPlate;)
Which checks to see if the armor is titanium plate (replace the constant as appropriate).
We set installDone to True because we don't want to install more than one item per loop. One problem with (objEnumItems) is that it doesn't work very well when the items are being changed inside the loop (which is what shpInstallArmor would do).
Your best bet is to create a function that wraps it all in a single function. Something like:
Code: Select all
(setq installArmorHelper
(lambda (theShip theArmorType theSegment)
(block (installDone)
(objEnumItems theShip "aU" cursorVar
(if (and (not installDone)
(eq (itmGetUNID (itmAtCursor cursorVar))
theArmorType))
(block Nil
(shpInstallArmor
theShip
cursorVar
theSegment
)
(setq installDone True)
)
)
)
)
))
Code: Select all
(block Nil
(objAddItem gPlayerShip (itmCreate &itTitaniumPlate; 4))
(installArmorHelper gPlayerShip &itTitaniumPlate; 0)
(installArmorHelper gPlayerShip &itTitaniumPlate; 1)
(installArmorHelper gPlayerShip &itTitaniumPlate; 2)
(installArmorHelper gPlayerShip &itTitaniumPlate; 3)
)
- Betelgeuse
- Fleet Officer
- Posts: 1920
- Joined: Sun Mar 05, 2006 6:31 am
thanks, is there a itemstruct version of shpEnhanceItem or should I just do what you did there? (do enemy devices obey enhancements?)
Crying is not a proper retort!