| Post 1 | New | Posted July 6th, 2008 | ||
|---|---|---|---|
| Cerbera Ben 'Cerbera' Millard
| How do you make cars respawn in multiplayer GTA2 levels? Also, are there any desynchronisation problems with doing it? ------------------
|
| Post 2 | New | Posted July 10th, 2008. Updated July 10th, 2008 |
|---|---|
Sektor
| Code: PLAYER_PED p1 = ( 12.5 , 18.5 , 2.0 ) 10 0 car_data car1 COUNTER gameloop = 1 LEVELSTART car1 = CREATE_CAR ( 11.5 , 17.5 ) 28 90 COPCAR END WHILE ( gameloop = 1 ) IF ( is_car_wrecked ( car1 )) car1 = CREATE_CAR ( 11.5 , 17.5 ) 28 90 COPCAR END ENDIF ENDWHILE LEVELEND That could create a chain reaction of explosions if the car is wrecked at the respawn location. You could avoid that by only respawning the car when it's not on the player's screen. Code: IF ( NOT ( IS_ITEM_ONSCREEN ( car1 ) ) ) IF ( is_car_wrecked ( car1 )) // DELETE_ITEM ( car1 ) // I don't think you need this car1 = CREATE_CAR ( 11.5 , 17.5 ) 28 90 COPCAR END ENDIF ENDIF Respawning cars doesn't cause sync problems but a chain reaction of explosions could make the game go out of sync or crash. ------------------ Stealing cars is the easy part |
| Post 3 | New | Posted July 10th, 2008. Updated July 10th, 2008 | ||
|---|---|---|---|
| Cerbera Ben 'Cerbera' Millard
| Thanks for the help! I didn't even know where to start. I only want the car to respawn when you can't see the spawnpoint. I found IS_POINT_ONSCREEN to do that.To avoid chain reactions, the new car must only spawn when the spawnpoint is clear. I found IS_CAR_IN_BLOCK with a width and height of 2.0 does that nicely.Code: // Respawning FBI Car: This works great for nearly all cases. It's currently released in MultiSlayer Ghetto arena.IF (IS_CAR_WRECKED(fbicar)) IF (NOT (IS_POINT_ONSCREEN(184.5,149.5,2.0))) IF (NOT (IS_CAR_IN_BLOCK(fbicar, 184.5,149.5,2.0, 1.0,1.0))) // Cannot see spawnpoint and spawnpoint is clear: fbicar = CREATE_CAR (184.5,149.5) -1 000 EDSELFBI END GIVE_WEAPON (fbicar, CAR_MACHINE_GUN, 99) ENDIF ENDIF ENDIF However, if you wreck the car at the spawnpoint, the wreck never gets cleared. I need to clear the wreck when IS_CAR_IN_BLOCK is TRUE. I tried this:Code: // Respawning FBI Car: If I can clear the wreck from the spawnpoint, this respawn will be perfect!IF (IS_CAR_WRECKED(fbicar)) IF (NOT (IS_POINT_ONSCREEN(184.5,149.5,2.0))) IF (NOT (IS_CAR_IN_BLOCK(fbicar, 184.5,149.5,2.0, 1.0,1.0))) // Cannot see spawnpoint and spawnpoint is clear: fbicar = CREATE_CAR (184.5,149.5) -1 000 EDSELFBI END GIVE_WEAPON (fbicar, CAR_MACHINE_GUN, 99) ELSE // Cannot see spawnpoint but wreck overlaps spawnpoint: DELETE_ITEM (fbicar) // clearing the wreck doesn't work? fbicar = CREATE_CAR (184.5,149.5) -1 000 EDSELFBI END GIVE_WEAPON (fbicar, CAR_MACHINE_GUN, 99) ENDIF ENDIF ENDIF I tried MISSION_HAS_FINISHED, running far away, waiting a long time, then returning but the wreck remained at the spawnpoint.Would using a GENERATOR to create the vehicle as if it were a powerup be more successful?------------------
|
| Post 4 | New | Posted July 11th, 2008. Updated July 13th, 2008 |
|---|---|
Sektor
| DELETE_ITEM doesn't remove wrecks. GENERATOR can't create vehicles. PUT_CAR_ON_TRAILER works great for teleporting a wreck to another location and GTA2 doesn't seem to mind 100+ wrecks being put on the same trailer. Code: PARKED_CAR_DATA parked_trailer_1 = ( 178.1 , 153.0 ) 19 0 truktrns PARKED_CAR_DATA truck1 = ( 178.1 , 154.3 ) 19 0 TRUKCAB1 WHILE_EXEC (loopage = 1) // Respawning FBI Car: IF (IS_CAR_WRECKED(fbicar)) IF (NOT (IS_POINT_ONSCREEN(184.5,149.5,2.0))) PUT_CAR_ON_TRAILER ( fbicar, parked_trailer_1 ) fbicar = CREATE_CAR (184.5,149.5) -1 000 EDSELFBI END GIVE_WEAPON (fbicar, CAR_MACHINE_GUN, 99) ENDIF ENDIF ENDWHILE If you don't want the car to respawn as soon as it's offscreen then you can add a delay: Code: IF (NOT (DELAY (50))) fbicar = CREATE_CAR (184.5,149.5) -1 000 EDSELFBI END ENDIF If a vehicle spawns on top of a player, it will kill them and cause weird results (like turn them into a ped) but IS_POINT_ONSCREEN should prevent that. ------------------ Stealing cars is the easy part |
| Post 5 | New | Posted July 12th, 2008 | ||
|---|---|---|---|
| Cerbera Ben 'Cerbera' Millard
| That's a delightful bit of evil! The relevant parts I've ended with are this: Code: // Cars This seems to work perfectly. You have to be away from the spawnpoint for a few seconds for any of the respawning stuff to happen, which is a nice touch. Thanks for your help!CAR_DATA fbicar PARKED_CAR_DATA trailer = (1.0,1.0) 19 90 TRUKTRNS ... // Respawning FBI Car: IF (IS_CAR_WRECKED(fbicar)) IF (NOT (DELAY (100))) // let explosion happen IF (NOT (IS_POINT_ONSCREEN(184.5,149.5,2.0))) IF (IS_CAR_IN_BLOCK(fbicar, 184.5,149.5,2.0, 1.0,1.0)) // Cannot see spawnpoint but wreck is blocking spawnpoint: PUT_CAR_ON_TRAILER (fbicar, trailer) DELETE_ITEM (fbicar) ENDIF // Cannot see spawnpoint and spawnpoint is clear: fbicar = CREATE_CAR (184.5,149.5) -1 000 EDSELFBI END GIVE_WEAPON (fbicar, CAR_MACHINE_GUN, 99) ENDIF ENDIF ENDIF I created a little piece of land in the top left of the map so the TRUKTRNS is very far away. default.txt says DELETE_ITEM is intended for use with any scripted item, including cars. Even if the item stays in the game world, at least it can recover the scripting resources?If the car is wrecked away from the spawnpoint, I let the wreck remain in the level. ------------------
|
| Post 6 | New | Posted July 13th, 2008. Updated July 14th, 2008 |
|---|---|
Sektor
| Cerbera wrote: If the car is wrecked away from the spawnpoint, I let the wreck remain in the level. Good idea. That's a nice improvement. GTA2 Scripting.doc wrote: DELETE ITEM Orders the game to delete a previously created car/object/character/light. This generic command replaces the DELETE_CAR/CHAR/OBJECT commands Oh yeah, it does say it works with cars but Rockstar didn't use it on any cars (at least not in the Industrial level). I was having problems with delete_item crashing the game but it was probably trying to delete an item that didn't exist. I'll have to check that. You don't have to create land for the trailer, it works fine underwater (although probably not meant to be used that way). I think respawning cars are useful enough to add to your GTA2 scripting tutorials. ------------------ Stealing cars is the easy part |
| Post 7 | New | Posted July 17th, 2008. Updated July 18th, 2008 | ||
|---|---|---|---|
| Cerbera Ben 'Cerbera' Millard
| I have now written Respawning Vehicles in GTA2 Coding. I'm guessing DELETE_ITEM is unused because they usually get released some other way. Such as parking in a garage, going into a DESTUCTOR, changing the driver into a civilian and things like that? Even if it does nothing, it seems like the right thing to do. As you suggested writing the article, I'm guessing you're fine with people redistributing the code. While I was there, I noticed the GTA2 Characters guide was really huge. So I've split a couple of sections from it: ------------------
|
