How will I make this spawning system work? -
jameskmonger - 05.10.2010
I have a plan where I want to make it so that to buy a car you go into the car shop, type a command, and the car will be spawned outside. How can I make it only spawn the car if there is no car in that spot, and if there is, spawn it somewhere else?
Re: How will I make this spawning system work? -
boelie - 05.10.2010
hmm i think you need something like IsPlayerInRangeOfPoint but then for vehicles... let me check if i have something usefull for you. I will edit it in this post
here it is;
Код:
stock IsVehicleInRangeOfPoint(vehicleid, Float:range, Float:x, Float:y, Float:z)
{
new Float:px, Float:py, Float:pz;
GetVehiclePos(vehicleid, px, py, pz);
px -= x; py -= y; pz -= z;
return ((px * px) + (py * py) + (pz * pz)) < (range * range);
}
its not the sollution for your problem yet but i guess it could help you further
Re: How will I make this spawning system work? -
jameskmonger - 06.10.2010
If I wanted to see if a vehicle was 5 metres away from 3, 5, 7, I would do this:
Код:
IsVehicleInRangeOfPoint(vehicleid, 5, 3, 5, 7)
But what would I put in vehicleid?
Re: How will I make this spawning system work? -
boelie - 06.10.2010
put this above
Код:
for(new v=0;v<MAX_VEHICLES; v++)
then it could look something like this;
Код:
for(new v=0;v<MAX_VEHICLES; v++)
if(IsVehicleInRangeOfPoint(v,5.0,x,y,z)) //xyz location wherever you want
{
//your stuff here
}
Re: How will I make this spawning system work? -
jameskmonger - 06.10.2010
Код:
stock IsVehicleInRangeOfPoint(vehicleid, Float:range, Float:x, Float:y, Float:z)
{
new Float:px, Float:py, Float:pz;
GetVehiclePos(vehicleid, px, py, pz);
px -= x; py -= y; pz -= z;
return ((px * px) + (py * py) + (pz * pz)) < (range * range);
}
stock IsAnyVehicleInRange(Float:range, Float:x, Float:y, Float:z) {
for(new v=0;v<MAX_VEHICLES; v++)
if(IsVehicleInRangeOfPoint(range,x,y,z)) //xyz location wherever you want
{
return true;
}
}
Would that work?
Re: How will I make this spawning system work? -
boelie - 06.10.2010
omg no totaly wrong what were you trying to do there?
Re: How will I make this spawning system work? -
jameskmonger - 06.10.2010
I want to see if ANY vehicle is in the range of the point.
Re: How will I make this spawning system work? -
boelie - 06.10.2010
if you buy the car while you are inside an interior then i guess you can use it under OnVehicleStreamin
heres an example of how that would look like;
Код:
public OnVehicleStreamIn(vehicleid, forplayerid)
{
for(new v=0;v<MAX_VEHICLES; v++)
if(IsVehicleInRangeOfPoint(v,5.0,x,y,z)) //xyz location of where the vehicle that you bought should be
{
SendClientMessage(forplayerid,COLOR_RED,"a vehicle is already on this position");
//other stuff
}
else
{
//put here what should happen if theres no vehicle there yet
}
return 1;
}
just leave this;
Код:
stock IsVehicleInRangeOfPoint(vehicleid, Float:range, Float:x, Float:y, Float:z)
{
new Float:px, Float:py, Float:pz;
GetVehiclePos(vehicleid, px, py, pz);
px -= x; py -= y; pz -= z;
return ((px * px) + (py * py) + (pz * pz)) < (range * range);
}
above ongamemodeinit or elsewhere underneath your script just out of the callbacks
Re: How will I make this spawning system work? -
Bessensap - 06.10.2010
Area works better.
pawn Код:
stock IsVehicleInArea(vehicleid,minx, maxx, miny, maxy)
{
new Float:px, Float:py, Float:pz;
GetVehiclePos(vehicleid, px, py, pz);
if(px < maxx && px > minx && py < maxy && py > miny)
{
return true;
}
}
Re: How will I make this spawning system work? -
Mike_Peterson - 06.10.2010
Quote:
Originally Posted by Bessensap
Area works better.
pawn Код:
stock IsVehicleInArea(vehicleid,minx, maxx, miny, maxy) { new Float:px, Float:py, Float:pz; GetVehiclePos(vehicleid, px, py, pz); if(px < maxx && px > minx && py < maxy && py > miny) { return true; } }
|
that maybe true but not for this....
Quote:
Originally Posted by jameskmonger
I want to see if ANY vehicle is in the range of the point.
|
first vehicleid u have to make a loop MAX VEHICLES and then you have to walk a square around the vehicle were it spawned else it will find too much vehicles...
if you do vehicle in range of point it will go to that co-ordinates and make a circle as the range you want...
and check if the vehicle is in that "circle" and you can modify the range easy