How can i make it stop searching when it finds 1 unoccupied vehicle - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How can i make it stop searching when it finds 1 unoccupied vehicle (
/showthread.php?tid=188639)
How can i make it stop searching when it finds 1 unoccupied vehicle -
iTorran - 08.11.2010
Well i have this script and what its supposed to do is when u spawn it will find a unocupied vehicle and put u in it.
well it works kind of as i can move the wheels of a car when i spawn. But my player isnt sat in the seat, And a few secs later i die, I think its trying to put me in all the vehicles. So i need to make it stop searching when it finds 1 unoccpued vehicle. How?
pawn Код:
public OnPlayerRequestSpawn(playerid)
{
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(IsVehicleOccupied(i))
{
GameTextForPlayer(playerid, "There are no more cars left.", 2500, 3);
}
else if(!IsVehicleOccupied(i))
{
PutPlayerInVehicle(playerid, i, 0);
}
}
return 1;
}
stock IsVehicleOccupied(vehicleid)
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(GetPlayerState(i) == PLAYER_STATE_DRIVER || GetPlayerState(i) == PLAYER_STATE_PASSENGER)
{
if(GetPlayerVehicleID(i) == vehicleid)
{
return 1;
}
}
}
return 0;
}
Re: How can i make it stop searching when it finds 1 unoccupied vehicle -
Cameltoe - 08.11.2010
Try this:
pawn Код:
public OnPlayerRequestSpawn(playerid)
{
new vehicleid = INVALID_VEHICLE_ID;
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(!IsVehicleOccupied(i))
{
vehicleid = i;
break;
}
}
if(vehicleid != INVALID_VEHICLE_ID)
{
PutPlayerInVehicle(playerid, vehicleid, 0);
}
else
{
GameTextForPlayer(playerid, "There are no more cars left.", 2500, 3);
}
return 1;
}
Re: How can i make it stop searching when it finds 1 unoccupied vehicle -
iTorran - 08.11.2010
Not putting me in vehicle at all
Re: How can i make it stop searching when it finds 1 unoccupied vehicle -
Cameltoe - 08.11.2010
Quote:
Originally Posted by iTorran
Not putting me in vehicle at all
|
Working, tested:
pawn Код:
public OnPlayerRequestSpawn(playerid)
{
new vehicleid = INVALID_VEHICLE_ID;
for(new i = 0; i < MAX_VEHICLES; i++)
{
if(!IsVehicleOccupied(i) && IsVehicleConnected(i))
{
vehicleid = i;
break;
}
}
if(vehicleid != INVALID_VEHICLE_ID)
{
PutPlayerInVehicle(playerid, vehicleid, 0);
}
else
{
GameTextForPlayer(playerid, "There are no more cars left.", 2500, 3);
}
return 1;
}
stock IsVehicleConnected(vehicleid)
{
new Float:x1,Float:y1,Float:z1;
GetVehiclePos(vehicleid,x1,y1,z1);
if(x1==0.0 && y1==0.0 && z1==0.0)
{
return 0;
}
return 1;
}
Re: How can i make it stop searching when it finds 1 unoccupied vehicle -
iTorran - 08.11.2010
Fixed!!!!!!!!!