Author Topic: Respawing a ship and having the sexps still work?  (Read 1927 times)

0 Members and 1 Guest are viewing this topic.

Offline sausage

  • 24
    • waynejohnson.net
Respawing a ship and having the sexps still work?
Hi Guys, I've been at this for a couple of days and am turning here again for help.

I have a situation I want to create where there a several 'objects' floating around the multiplayer space. If a player comes close to one of these things it disappears and re-appears elsewhere.

This is an easy enough thing to do by having a sexp that tests the distance of one of these objects to the player and then sets the object to invunerable, and self-destruct. If it is in a wing, it can come back in as a different wave, or if not, it can be redone with ship-create.

The problem with both of these things is that they both create new ships with slightly different names and they no longer abide by the rules in the sexp.

How do others manage to apply a sexp to a dynamically created ship or re-spawned wing ship?

 
Re: Respawing a ship and having the sexps still work?
Hmm, try changing the objects location instead of replacing it? Change -> Coordinate manipulation -> set-object-position

  

Offline FUBAR-BDHR

  • Self-Propelled Trouble Magnet
  • 212
  • Master Drunk
    • 165th Beer Drinking Hell Raisers
Re: Respawing a ship and having the sexps still work?
Yes set-object-position would be the first solution.  You could also make them a different IFF say neutral and do a <any-neutral> check.  When-argument is another option. 

Oh and be careful with distance checks with player ships in multi (and anywhere an object can be destroyed) if you aren't using recent builds.  There was a bug that would crash the engine if a check against an object not in game (destroyed for instance) was preformed. 
No-one ever listens to Zathras. Quite mad, they say. It is good that Zathras does not mind. He's even grown to like it. Oh yes. -Zathras

 

Offline sausage

  • 24
    • waynejohnson.net
Re: Respawing a ship and having the sexps still work?
Thanks for that. Yes a re-position would be a better option. My only concern is using the re-position with a RAND where I have a large object in the centre that everyone plays around. A RAND could cause it to appear in the middle of a mesh.

Don't know if the 3.6.10 engine takes this into account, I'm still learning. Anyway, I'll give this a try and report what the results are.

 

Offline FUBAR-BDHR

  • Self-Propelled Trouble Magnet
  • 212
  • Master Drunk
    • 165th Beer Drinking Hell Raisers
Re: Respawing a ship and having the sexps still work?
If it's in the center take the length of the axis of the model as the minimum of the rand-mutliple.  To get a positive or negative add one extra rand-multiple with value of 0 and 1.  If 0 leave it positive, if 1 make it negative. 

So if you have a model your fighting around that is 50x, 100y, and 25z and the object you are moving is say 10x10x10 do:

when
--<whatever condition causes move>
-modify variable
--neg
--rand-multiple
---0
---1
-modify variable
--xpos
---rand-multiple
----70 (50 + 10 + 10 for some space)
----<max you want it away>
-when
-- =
---neg
---1
--modify variable
---xpos
----*
-----xpos
----- -1
-modify variable
--neg
--rand-multiple
---0
---1
-modify variable
--ypos
---rand-multiple
----120 (100 + 10 + 10 for some space)
----<max you want it away>
-when
-- =
---neg
---1
--modify variable
---ypos
----*
-----ypos
----- -1
-modify variable
--neg
--rand-multiple
---0
---1
-modify variable
--zpos
---rand-multiple
----45 (25 + 10 + 10 for some space)
----<max you want it away>
-when
-- =
---neg
---1
--modify variable
---zpos
----*
-----zpos
----- -1
set-object-position
--<object>
--xpos
--ypos
--zpos


No-one ever listens to Zathras. Quite mad, they say. It is good that Zathras does not mind. He's even grown to like it. Oh yes. -Zathras

 

Offline sausage

  • 24
    • waynejohnson.net
Re: Respawing a ship and having the sexps still work?
Thanks Fubar for the formula for avoiding re-spawing co-ords on top of another object.

Ended up trying the tips above (thanks guys) and set-object-position was certainly the most sensible way to handle it. I did notice something rather odd with my sexp. Here is what I ended up with:

--every-time
--<
----distance
------Phantom
------Alpha 1
----50
--set-object-position
----Phantom
----rand 0 500 
----rand 0 500 
----rand 0 500 
 
The sexp certainly does move the Phantom every time you fly within 50 metres of it. What is weird though... after about 4 repositions, the random numbers become smaller and smaller, no longer using 500 as a max. It was very strange and basically the max rand number range became so small that the repositions all ended up being at co-ord: 0,0,0.

Example:

1) 456, 212, 446
2) 300, 170, 387
3) 170, 78, 89
4) 86, 64, 72
5) 46, 48, 34
6) 29, 24, 39
7) 10, 12, 21
8) 4, 5, 7
9) 2, 2, 4
10) 0, 1, 1
11) 0, 0, 0
12) 0, 0, 0
13) 0, 0, 0
etc..

Isn't that weird?

At the end of the day, I don't think I want this kind of effect in my game anyway so this thread is largely moot. However the effect may be of interest to others and also the re-spawn issue for others trying to do the same thing as me.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Respawing a ship and having the sexps still work?
You used Rand not Rand-Multiple. Although I wouldn't have expected that I'm not surprised at seeing weird behaviour when using Rand in repeating events.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline FUBAR-BDHR

  • Self-Propelled Trouble Magnet
  • 212
  • Master Drunk
    • 165th Beer Drinking Hell Raisers
Re: Respawing a ship and having the sexps still work?
Yea it should have been 456, 212, 446 each time as rand is only evaluated at mission load.  Even restarting the mission should have produced the same results unless you went back to the hanger or exited FS2. 
No-one ever listens to Zathras. Quite mad, they say. It is good that Zathras does not mind. He's even grown to like it. Oh yes. -Zathras

 

Offline sausage

  • 24
    • waynejohnson.net
Re: Respawing a ship and having the sexps still work?
Thanks, Guys. Those numbers were made up to illustrate the point and are in no way accurate. I'll use rand-multiple from here on.