Respawning Characters in GTA 2 Coding
First of all, you need to reserve a place for a character with the CHAR_DATA uniquename command before the level start. Once you get to the place you want them, call them up with the usual routine:
uniquename = CREATE_CHAR ( X , Y , Z ) remap rotation occupation
END
Now, you have a character who does nothing, and when shot, will stay dead. Here’s the catch. I made a counter before hand (call it whatever you like) and set the value to 1. Now, we call up a WHILE_EXEC command.
To show you, I have taken a part of my old Battle Zone script and details will be at the bottom. This has four characters in this for this example:
CHAR_DATA p1_killer
CHAR_DATA p2_killer
CHAR_DATA p3_killer
CHAR_DATA p4_killer
COUNTER regenerating_characters = 1
LEVELSTART
p1_killer = CREATE_CHAR ( 6.5 , 7.5 , 6.0 ) 0 315 CRIMINAL_TYPE2 END
p2_killer = CREATE_CHAR ( 7.5 , 7.5 , 6.0 ) 0 045 CRIMINAL_TYPE2 END
p3_killer = CREATE_CHAR ( 6.5 , 6.5 , 6.0 ) 0 225 CRIMINAL_TYPE2 END
p4_killer = CREATE_CHAR ( 7.5 , 6.5 , 6.0 ) 0 135 CRIMINAL_TYPE2 END
GIVE_WEAPON ( p1_killer , machine_gun )
GIVE_WEAPON ( p2_killer , machine_gun )
GIVE_WEAPON ( p3_killer , machine_gun )
GIVE_WEAPON ( p4_killer , machine_gun )
SET_CHAR_THREAT_SEARCH ( p1_killer , AREA_PLAYER_ONLY )
SET_CHAR_THREAT_SEARCH ( p2_killer , AREA_PLAYER_ONLY )
SET_CHAR_THREAT_SEARCH ( p3_killer , AREA_PLAYER_ONLY )
SET_CHAR_THREAT_SEARCH ( p4_killer , AREA_PLAYER_ONLY )
SET_CHAR_THREAT_REACTION ( p1_killer , REACT_AS_NORMAL )
SET_CHAR_THREAT_REACTION ( p2_killer , REACT_AS_NORMAL )
SET_CHAR_THREAT_REACTION ( p3_killer , REACT_AS_NORMAL )
SET_CHAR_THREAT_REACTION ( p4_killer , REACT_AS_NORMAL )
SET_CHAR_OBJECTIVE ( p1_killer , KILL_CHAR_ON_FOOT , p1 )
SET_CHAR_OBJECTIVE ( p2_killer , KILL_CHAR_ON_FOOT , p2 )
SET_CHAR_OBJECTIVE ( p3_killer , KILL_CHAR_ON_FOOT , p3 )
SET_CHAR_OBJECTIVE ( p4_killer , KILL_CHAR_ON_FOOT , p4 )
WHILE_EXEC( regenerating_characters = 1 )
IF ( ( HAS_CHARACTER_DIED ( p1_killer ) ) OR ( HAS_CHARACTER_DIED ( p4_killer ) ) )
p1_killer = CREATE_CHAR ( 6.5 , 7.5 , 6.0 ) 0 0 CRIMINAL_TYPE2 END
GIVE_WEAPON ( p1_killer , machine_gun )
SET_CHAR_THREAT_SEARCH ( p1_killer , AREA_PLAYER_ONLY )
SET_CHAR_THREAT_REACTION ( p1_killer , REACT_AS_NORMAL )
SET_CHAR_OBJECTIVE ( p1_killer , KILL_CHAR_ON_FOOT , p1 )
p2_killer = CREATE_CHAR ( 7.5 , 7.5 , 6.0 ) 0 45 CRIMINAL_TYPE2 END
GIVE_WEAPON ( p2_killer , machine_gun )
SET_CHAR_THREAT_SEARCH ( p2_killer , AREA_PLAYER_ONLY )
SET_CHAR_THREAT_REACTION ( p2_killer , REACT_AS_NORMAL )
SET_CHAR_OBJECTIVE ( p2_killer , KILL_CHAR_ON_FOOT , p2 )
p3_killer = CREATE_CHAR ( 6.5 , 6.5 , 6.0 ) 0 225 CRIMINAL_TYPE2 END
GIVE_WEAPON ( p3_killer , machine_gun )
SET_CHAR_THREAT_SEARCH ( p3_killer , AREA_PLAYER_ONLY )
SET_CHAR_THREAT_REACTION ( p3_killer , REACT_AS_NORMAL )
SET_CHAR_OBJECTIVE ( p3_killer , KILL_CHAR_ON_FOOT , p3 )
p4_killer = CREATE_CHAR ( 7.5 , 6.5 , 6.0 ) 0 135 CRIMINAL_TYPE2 END
GIVE_WEAPON ( p4_killer , machine_gun )
SET_CHAR_THREAT_SEARCH ( p4_killer , AREA_PLAYER_ONLY )
SET_CHAR_THREAT_REACTION ( p4_killer , REACT_AS_NORMAL )
SET_CHAR_OBJECTIVE ( p4_killer , KILL_CHAR_ON_FOOT , p4 )
ENDIF
ENDWHILE
Don’t understand any of it? I’ll try to explain most of it for you. The counter is self explanitory. When we call up the WHILE_EXEC command, it checks to see if the counter is set at 1 (in which case it is) and then proceeds with executing the rest of the script. The IF function looks for either the character p1_killer or the other character, p4_killer. Notice it’s an OR command, so only one of them has to be shot to make the characters regenerate. As a note, make sure all brackets add up!
Now, we do the create character again, but with the original names. So, we can keep using p1_killer as many times as we like, even in different missions or whatever. Then, we give the characters some guns, objectives and reactions to follow (you should try and keep them the same as when you first made the characters.) etc, and it will keep doing this forever until you switch the value of the counter to another value. And there are respawning characters for you! Experiment with your own characters, scenarios etc and you can make a better mission too!
(Originally written by Chris “Pyro” Hockley and formatted by Ben “Cerbera” Millard with full permission.)