help with auto-replacing armor

Freeform discussion about anything related to modding Transcendence.
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

I'm working on an overwrite of the salvagers to make them auto-upgrade themselves. I have already got everything working except for armor replacement. I have my code here:

Code: Select all

(objEnumItems gSource "aUN" armorItem
						(if armorItem
							(switch
								(ls (armGetHitPoints (shpGetArmor gSource (objGetData gSource 'CurrentSegment))) (armGetHitPoints armorItem))
									(shpInstallArmor gSource armorItem (objGetData gSource 'CurrentSegment))
								(geq (armGetHitPoints (shpGetArmor gSource (objGetData gSource 'CurrentSegment))) (armGetHitPoints armorItem))
									(block nil
										(if (ls (objGetData gSource 'CurrentSegment) 35)
											(objIncData gSource 'CurrentSegment 1)
										)
										(if (geq (objGetData gSource 'CurrentSegment) 35)
											(objSetData gSource 'CurrentSegment 0)
										)
									)
							)
						)
					)
My idea is that if the armor in the cargo hold doesn't have higher HP than the first segment, it will go on to the next one, then keep going until it finds a segment to replace. It comes up with an error saying "Integer expected (armGetHitPoints armorItem)" then the whole line. I've tried several different things but it always comes up with an error.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

I made a paste here that demonstrates how I would do it. Note, I have not actually tested it. Please read the comments... it should make it quite clear what is going on. That should allow you to fix any immediate mistakes. If you have any questions about it, then just ask.

Note. I implemented the solution like this to show how it is possible to use a function to abstract a simeple problem (finding an armor segment with less hp than some number). You could implement the solution in other ways as well... I just personally prefer this one.

http://paste.neurohack.com/view/YLSre/
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

Thanks for all the help.
I do have a few questions, mostly just for how the code works. First, what does the (block ((howMany 0) getSegment) do?
Also, what does (setq installed (shpGetArmor source i)) do?

I am also a little confused on how to implement it. Do I put it in globals or under the ship, or does it matter?
Thanks again.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

OK... some answers:

Code: Select all

(block ((howMany 0) getSegment)
is just a compact way of writing this:

Code: Select all

(block (howMany getSegment)
    (setq howMany 0)
So, basically, you just initialize `howMany' to 0 at the same time as you define it.

-------------------------------------------------------------------------------------

Code: Select all

(setq installed (shpGetArmor source i))
That above needs to bee seen in the context it appears... inside a `for' loop.

If you look at the for loop on xelerus you might have an idea to start with.
Basically, the variable `i' always refers to the current iteration in the sequence of numbers from 0 to `segments'.
So, on the first run through, `i' will be 0, on the next 1, and so on, until the loop terminates.

That means that the above code gets the armor installed at position `i'

-------------------------------------------------------------------------------------

When it comes to using it, you have a few choices. You could place the whole function in a <Globals> block
in your mod, and use it there (remember to give the function a propper name). Or, you could just pull out the
block, and put that where you need the code to run. Say, in an event on the Salvager ship.

If you choose the last route, then i would probably take the `getSegment' function, give it a propper name,
and make it global (so you don't need to redefine it every time the event runs)


Hope that makes sense. Just ask and I will try to clarify things.
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

Awesome thanks. That helps a lot.

An error message comes up saying "Integer Expected (16514 1) ###(armGetHitPoints installed)###"
Any ideas why? I checked the function on Xelerus and it doesn't need any integers.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

Nevermind, I got it. The function expects a UNID, and "installed" is an itemstruct, so you need to do (itmGetType installed)
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Ahh, it is because armGetHitPoints needs a type, not an item (basically, a UNID, not the item itself as it is ingame)

To fix that change it to:

Code: Select all

(setq installed (itmGetType (shpGetArmor source i)))
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Ahh, cool... great you found it! :D
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

So it seems to be working well, and I added code so it also changes armor if the armor in its hold is three levels higher than the armor it has, because Hexaphase has 150 hp, and its default armor has 200. Hexaphase is better than reinforced titanium. But then it got shot by a Sung Slaver, and the game crashed. This is on the debug Log:
program state: OnAnimate
program state: updating object behavior
obj class: CShip
obj name: Salvager Nomad
obj pointer: a9ab268
CStandardShipAI
Order: 10
m_State: 3
m_pDest: none
m_pTarget: aa2ea30 Earth Slaver (CShip)
m_pNavPath: none
game state: in game

Is this something to do with the overwrite?
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

Umm.... that is really hard to say (from that information).

Does it happen multiple times? If you take out the armor code, does it stop happening? What changes did you make to the code? Have you checked that the ship ends up with all segments installed?

In cases like this i comment/uncomment code like crazy and put in tons of dbgLog statements, to see what is going on.... oh... and test and test again.
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

I ran several more tests and couldn't reproduce it. I remember I had a similar experience once, where I took the main cannon away from a phobos and the game crashed. I think it crashed because it got hit on the same tick as when the ship was swapping weapons so the game didn't know what to shoot with. So it's like a 1/1,000,000 shot.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

I think I've figured out what causes the crash. It happens when a shot hits it in the same tick that it is leaving a wreck and installing installing a new device. So, yeah, very remote chances of it happening.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

That does not really sound like something that would make the game crash... I am pretty sure that can not be it.
Drako Slyith
Fleet Officer
Fleet Officer
Posts: 1036
Joined: Wed Feb 03, 2010 4:28 am
Location: Researching how to make St. Kats star go supernova.
Contact:

So far I've seen it crash twice, and both times it had just got done looting a wreck. I was trying to reproduce it and so I shot it with a weapon that fired continuously. After several tries it didn't crash.

I've checked an it isn't a problem with it installing anything. I've tested most items it can install.
Image
Image
Play in over 100 systems in a network. Play the 2011 Mod Of the Year
and the highest rated mod on Xelerus, The Network.
Play the July Mod of the Month, Fellow Pilgrims!
Play My other mods as well
(Drako Slyith)* I am a person
(Eliza chatbot)> Do you believe it is normal to be a person?
User avatar
alterecco
Fleet Officer
Fleet Officer
Posts: 1658
Joined: Wed Jan 14, 2009 3:08 am
Location: Previously enslaved by the Iocrym

dbgLog, dbgLog, dbgLog :D

No, seriously :P The only reason i can think of it crashes after looting is because it finds something on that ship that makes it crash when it runs the install check. I assume that you are installing other things than armor now?

Put dbgLogs so that you can see all items it is testing, and especially all items it decides to install... Put dbgLogs around any actuall installs.... something like: (dbgLog "Installing: " (itmGetName itm 0) " - " (shpInstallItem ship itm))... That way you can see what is going on.

Typically crashes can happen if the ship ends up with no weapon or missing armor. There are probably other edge cases.
Post Reply