OnVehicleDeath - Place car on random position
#1

Hello.

I have been trying to figure this out, but it all got worse and worse.

I need a solution to place a car at a random position when the car gets destroyed.
I have some positions in an area that the car shall spawn at - but randomly.

Something like
OnVehicleDeath - Spawn car at one of these coordinates.
Everything i've tried has failed on way or another.

I would appreciate if there is one here, that could help me out.

Thanks.
Reply
#2

Try this:
Код:
#define MAX_RANDOM_POSITIONS 2
new Float:rPos[MAX_RANDOM_POSITIONS][3]={
  {123.456,123.456,12.45},
  {456.789,456.789,45.67}};

public OnVehicleDeath(vehicleid, killerid)
{
  SetVehicleToRespawn(vehicleid);
  return 1;
}

public OnVehicleSpawn(vehicleid)
{
  new r = random(MAX_RANDOM_POSITIONS-1);
  SetVehiclePos(vehicleid, rPos[r][0], rPos[r][1], rPos[r][2]);
  return 1;
}
Reply
#3

I appreciate your quick reply.
However, this makes it spawn at a specific position.
But i have several coords for it to spawn at (randomly).

Any ideas how such code could be?


Thanks.
Reply
#4

No, you got it wrong. He said the right thing.

he said this bit

Quote:

new Float:rpos[MAX_RANDOM_POSITIONS][3]={
{123.456,123.456,12.45},
{456.789,456.789,45.67}}

which are two random pos's.

So he was correct
Reply
#5

Ye, i edited it.
Reply
#6

I believe you could do

Код:
{123.456,123.456,12.45},
  {456.789,456.789,45.67},{another Pos},{AnotherPos}}
Reply
#7

Quote:
Originally Posted by campkz
I believe you could do

Код:
{123.456,123.456,12.45},
  {456.789,456.789,45.67},{another Pos},{AnotherPos}}
Yes, but don't forget to change the MAX_RANDOM_POSITIONS.
Reply
#8

Thanks guys!
Reply
#9

I tried this out, but apparantly the OnVehicleSpawn(vehicleid)
makes all the vehicles on server to spawn at these locations that i have when the server starts up.

Is it possible to change that?
Reply
#10

Quote:
Originally Posted by Faith
I tried this out, but apparantly the OnVehicleSpawn(vehicleid)
makes all the vehicles on server to spawn at these locations that i have when the server starts up.

Is it possible to change that?
Isn't it supposed to do that ?

This code spawns the vehicleid's 1,2 and 5-55 to the random positions. All others aren't touched.
Код:
public OnVehicleSpawn(vehicleid)
{
  switch(vehicleid)
  {
   case 1,2,5..55:
   {
     new r = random(MAX_RANDOM_POSITIONS-1);
     SetVehiclePos(vehicleid, rPos[r][0], rPos[r][1], rPos[r][2]);
   }
  }
  return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)