[SOLVED] Vehicles in array - then in if(){
#1

Hello.
I'm using this code:
Код:
enum CARS_DATA
{
  MODELID,
  Float:X,
  Float:Y,
  Float:Z,
  Float:A,
  C1,
  C2
};
new CopCars[][CARS_DATA] =
{
  {523,-215.9483,984.5226,18.9468,271.7301,0,0},
  {523,-215.9859,987.1728,19.0048,270.5827,0,0},
  {598,-228.1274,991.1447,19.2631,269.0867,0,1},
  {599,-228.6810,996.4469,19.7480,268.6263,0,1},
  {598,-214.6644,973.0877,19.0327,271.4312,0,1}
};
Then this in OnGameModeInIt()

Код:
for(new a=0; a< sizeof CopCars; a++)
{
	CreateVehicle
  (
    CopCars[a][MODELID],
    CopCars[a][X],
    CopCars[a][Y],
    CopCars[a][Z],
    CopCars[a][A],
    CopCars[a][C1],
    CopCars[a][C2],
    1000
  );
}
And How can i use CopCars in if?
For example, if player try to use the vehicle, and his pInfo[playerid][Job] is not 1, he gets removed from the vehicle. I'm trying to use this:
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	new CarID = GetPlayerVehicleID(playerid);
	if(newstate == PLAYER_STATE_DRIVER) {

	  if(CarID == CopCars) {
	  if(pInfo[playerid][Darbas] == 1) {
	  } else {
	  RemovePlayerFromVehicle(playerid);
	  }
	  }
	  }
	return 1;
}
But i Get:
Код:
C:\Documents and Settings\Simas\Desktop\RL\gamemodes\RL0.1.pwn(206) : error 033: array must be indexed (variable "CopCars")
Line 206:
Код:
	  if(CarID == CopCars) {
What's wrong? :/
Reply
#2

pawn Код:
for(new c; c < sizeof(CopCars); c++) if(CarID == CopCars[copcarloop]) {
Reply
#3

Quote:
Originally Posted by //exora
pawn Код:
for(new c; c < sizeof(CopCars); c++) if(CarID == CopCars[copcarloop]) {
I don't see this working, as he never actually saves the vehicle ID.
Reply
#4

Add in enum
Код:
Vecid
then
Код:
CopCars[a][Vecid] = CreateVehicle//bla bla.
Use loop to find.
Код:
new
 bool:samevec;
for(new i,j=sizeof CopCars;i < j;i++){
  if(CopCars[i][Vecid] == playervecid){
    samevec = true;
    break;
  }
}
//then bla
Reply
#5

Alternatively, dump it in a stock.

pawn Код:
stock IsListedCar(vehicleid)
{
  for(new i,j=sizeof(CopCars); i<j; i++)
  {
    if(CopCars[i][Vecid] == vehicleid) return 1;
  }
  return 0;
}
Example:

if(IsListedCar(CarID)) //player is in a listed car
if(!IsListedCar(CarID)) //Player isn't in a listed car

NOTE: You need to save the vehicle ID, as yezizhu showed.
Reply
#6

Omg,
Very fast response..
And everything works..

Thanks guys.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)