Home   Help Search Login Register  

Author Topic: Problems respawning into a tank  (Read 1153 times)

0 Members and 4 Guests are viewing this topic.

Rocko Bonaparte

  • Guest
Problems respawning into a tank
« on: 28 Oct 2004, 05:16:53 »
I have a single-player tank that all players will use.  The tanks are locked so they cannot escape.  I am still working on it, but eventually I hope to guarantee that the player goes when the tank goes, and vice versa.  That's not the problem here -- just assume for now that I am able to destroy the tank and the player when I suicide (blow up a gas station point blank).

I need the players to respawn in fresh single-player tanks.  I have gotten that working for the initial spawn, based on some tips I saw in the respawning thread.  The problem seems to be that when a player dies, they are respawned as a copy, and my script doesn't take affect for them.  I haven't proven it comprehensively yet, but you'll see why I think this from my code.

Here's the Init.sqs file:
Code: [Select]
titleCut ["","BLACK IN", 3]
estimatedTimeLeft Param1

flag_scoreable = preprocessFile "flag_scoreable.sqf"
assign_flag_west    = preprocessFile "assign_flag_west.sqf"
assign_flag_east    = preprocessFile "assign_flag_east.sqf"

[E1] exec "assign_vehicle.sqs"

The assign_vehicle script is what actually puts the players into tanks.  E1 is the text for the unit I am using for testing.  Here's the code for assign_vehicle.sqs:
Code: [Select]
? not local Server : exit
_player = _this select 0

_player_pos = getPos _player
_player_dir = getDir _player

; Assign this player a tank
#AssignTank

hint "Player gets a tank!!!!"

_new_tank = "M1A1_1P" createVehicle _player_pos
_player moveInDriver _new_tank
_new_tank lock true

@!alive _player

hint "Player is Dead"

@alive _player
hint "Player is Alive"
goto "AssignTank"
So what happens is I get the "Player is Dead" hint but never the "Player is Alive" hint.  My player respawns at the spawn point with just an M16 and some ammo.  No tank.

So to recap:
- I can initially spawn in the tank.
- I can never spawn in it afterwards.

I think there's a fundamental problem I am missing, and this isn't vehicle-specific.  Any tips would be valueable.

Offline Artak

  • The old beanbag shaker
  • Former Staff
  • ****
  • You want to talk about it, yes?
    • OFP Team Finlanders
Re:Problems respawning into a tank
« Reply #1 on: 28 Oct 2004, 09:47:08 »
I guess the M1A1_1P is somekind of a abrams addon eh? Are you sure the string name is correct?

Anyway, I think what's happening here is that when _player dies it stops being _player. You need to use this method I got from a Toadlife's script, to keep the _player variable usable.

["dude1"] exec ...

_name = _this select 0
_unit = call format["%1",_name]
@!alive _unit
@alive call format["%1",_name]
_unit = call format["%1",_name]

get it? you execute the script with the unit as a string. Then pick up what's in the string to the _unit variable with the call command. You need to do that each time when the unit could have died and before you're starting to check something.


This method is used in weapons_respawn.xsqs by toadlife and Hamdinger. It can be found here in the editors depot. :)
Not all is lost.

Rocko Bonaparte

  • Guest
Re:Problems respawning into a tank
« Reply #2 on: 29 Oct 2004, 04:30:10 »
Ah so I was right about the player object changing upon death.  Thanks for the code snippet -- it seems to work right now!