why is shpOrder not working?

Freeform discussion about anything related to modding Transcendence.
Post Reply
User avatar
Shivan Hunter
Commonwealth Pilot
Commonwealth Pilot
Posts: 81
Joined: Tue Nov 29, 2011 3:07 am

OK, what I want to do is have a ring of ships patrolling 300 lightseconds away from a star, who attack any ship coming within 350 lightseconds of the star. I do this by putting a <Ships> section on the star which spawns the ships (they're spawned at the star's location and have to fly out to the 300 lightseconds, but that's alright) and orders them to patrol.

But there's a problem; the patrol order makes them attack anything that gets near the star. 350 lightseconds away is not "near the star", so they just let me past this barrier they're supposed to be forming.

So I set up a script that detects any ships not of their faction within 350 ls, and orders their nearby ships to attack the intruders using shpOrder. This does not work- neither of the shpOrder functions in my script are having any effect whatsoever.

I made a test mod that does this in Eridani, creating several hundred Centauri raiders. Here's the file.

Here is the script (on the star object):

Code: Select all

<Events>
			<OnCreate>
				(block (i ship)
					(sysAddObjRecurringTimerEvent 6 gSource "ShpOrderTimer")
					)
			</OnCreate>
			
			<ShpOrderTimer>
				(block (allWarlords allEnemies)
					(setq allWarlords (sysFindObject Nil "s B:centauriWarlords;"))
					(setq allEnemies (sysFindObject gSource "s -centauriWarlords; N:350"))
					
					; display how many enemies are detected
					;(plyMessage gPlayer (cat "enemies: " (count allEnemies) " centauriWarlords: " (count allWarlords)))
					
					; set all centauri ships to patrol
					(enum allWarlords theShip
						(shpOrder theShip 'patrol gSource 300)
						)
					
					; for all detected enemies,
					(enum allEnemies theEnemy
						(block (nearbyWarlords)
							; get nearby centauri ships that can attack
							(setq nearbyWarlords (sysFindObject theEnemy "s B:centauriWarlords; N:40"))
							;(plyMessage gPlayer (cat "nearbyWarlords: " (count nearbyWarlords)))
							; and order them to attack
							(enum nearbyWarlords theShip2
								(shpOrder theShip2 'attack theEnemy)
								)
							)
						)
					)
			</ShpOrderTimer>
		</Events>
Any ideas?

[EDIT] Yeah, I just noticed I have junk in my OnCreate event. It's irrelevant.
I'm here to shift paradigms and chew bubblegum... and I'm all out of bubblegum.

<+The_Shrike> If you install 2 solar panels, you will have 2 solar panels installed.
<DarthGeek|2> :o
User avatar
Shivan Hunter
Commonwealth Pilot
Commonwealth Pilot
Posts: 81
Joined: Tue Nov 29, 2011 3:07 am

RPC and I got this worked out on IRC. I wasn't cancelling the existing orders (or using shpOrderImmediate to insert the new orders at the top of the stack), so the ships never stopped doing what they were doing to begin with.
I'm here to shift paradigms and chew bubblegum... and I'm all out of bubblegum.

<+The_Shrike> If you install 2 solar panels, you will have 2 solar panels installed.
<DarthGeek|2> :o
User avatar
digdug
Fleet Admiral
Fleet Admiral
Posts: 2620
Joined: Mon Oct 29, 2007 9:23 pm
Location: Decoding hieroglyphics on Tan-Ru-Dorem

Yes, patrol is a persistent order, that has no end. You can do 2 things, cancel the current order then order the ship to attack the intruders and order them to patrol again. When the intruding ships are attacked and destroyed, the ships will resume patrolling, since that is the next order.

Or

Use shporderimmediate function to order the attack. This will add the order at the beginning of the order stack. So when the ship destruction is finished, the ship will resume patrolling automatically.
Shporderimmediate has been added by George more recently and it's awesome because it won't disrupt complicated order stacks.
Post Reply