Home   Help Search Login Register  

Author Topic: Respawning  (Read 27719 times)

0 Members and 1 Guest are viewing this topic.

Offline dr. seltsam

  • Members
  • *
Re: Respawning
« Reply #90 on: 21 Feb 2010, 18:54:33 »
If you write a name for a human playable soldier in the unit box where it says name, the game engine will transfer the new body as the new content to that variable after respawning. It seems like that these variables (in the box) always behave like a function that will find the actual body that is representing that variable.

You run into problems with the following cases:

If you give that soldier a name: player1
And you duplicate the variable, like for example: hero1=player1
player1 will contain the new body after respawn, but hero1 not (hero1 is a dead body then)

If you start a script: [player1] exec "Whatever.sqs"
_soldier=_this select 0
After the death of player1 also _soldier is a dead body, it won't get updated automatically
You have to execute "Whatever.sqs" again, and make sure that the old script ends (to save performance)

If you build an array: soldier_array=[player1,player2,..]
After a while some player die... and you want to get the actual respawned bodies from that array.. won't work
soldier_array will only contain dead bodies after a while

Here is a trick for arrays:

soldier_array = ["player1","player2",...]                 <-- check out the strings
_string         = soldier_array select 0
_soldier        = call _string

With the call command the game engine treats strings like code. The script is forced to find out what "player1" really is in that moment, and _soldier will contain the actual body of player1 (dead or alive does not matter).

If you want to have an always running client process, that only needs to know your actual body independent from how often you respawned... then you can use the inbuilt ofp function: player

? alive player : player groupchat "I feel good"

player always contains the actual body controlled by your game. On a dedicated server the content of player is always objNull.

http://community.bistudio.com/wiki/objNull

:D
« Last Edit: 21 Feb 2010, 22:48:48 by dr. seltsam »

Offline Clayborne

  • Members
  • *
Re: Respawning
« Reply #91 on: 23 Feb 2010, 12:31:58 »
Thanks, that's helpful!

I do tend to use arrays like that for ending triggers and such, and in this particular mission there will be a point where all players have to be in a certain zone for the mission to progress.

So in init.sqs I usually have something like

Code: [Select]
group_array = []

"if (alive _x) then {group_array = group_array + [_x]}" foreach [player1,player2]

So when one of the players enters the trigger, I can execute a script like this (?)

Code: [Select]
_string1         = group_array select 0
_string2         = group_array select 1

_soldier        = call _string1
_soldier2        = call _string2

I'm not sure where to go from there. Normally I would use a trigger with the condition

Code: [Select]
"_x in thislist" count group_array == "alive _x" count group_array AND "alive _x" count group_array > 0"
But how do I use that with the strings?


(Actually I could just do this by having the players in the same group and grouping them to the trigger, right? But I would like to know this in case I ever have to do something similar with players in different groups  :) )

« Last Edit: 23 Feb 2010, 12:34:07 by Clayborne »

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: Respawning
« Reply #92 on: 24 Feb 2010, 03:37:29 »
Forgive me If I am misunderstanding but couldn't you attach a killed eventhandler to each respawning soldier that runs a script, that creates them and then set positions them precisely where yuo need them? At the same time of creation, you could add the same weapons that they died with by using the weapons command, they would all be in the same group and any triggers that require activation by all or any of the members could actually be set in the tirggers activation type (by any member OR by the whole group, etc.) This would also allow you to avoid global variables if need be.

Offline Clayborne

  • Members
  • *
Re: Respawning
« Reply #93 on: 24 Feb 2010, 20:54:20 »
Well I've already got the updating respawn script that does that. The bit in the mission where they will be setpos'd is right at the end, and to detect the players in the trigger zone I was going to use an array, which dr. seltsam has just informed me might not work after the players have respawned.

I know if they're in the same group I can just group them to the trigger and use that to detect them, but I'd still like to know how it would be done using the array.

Offline dr. seltsam

  • Members
  • *
Re: Respawning
« Reply #94 on: 25 Feb 2010, 00:51:14 »
I think it also depends how you use the array:

If you build that group_array, and only use that variable for checking in triggers and scripts, then you only check for dead bodies after a while.

The alternative would be to always use the explicit form of that array: [player1,player2,...]
That will force the engine to check what player1,player2,... is in the moment when a calculation is done. But, that array can contain undefined values, if for example nobody chooses to be player2...