Can someone help me with detecting if the player is riding a bike?
#1

i tried some first, i thought it would work, but it ended up giving ALOT of warnings, and a few errors :P

bike id's:
Код:
Horizontal:
581,509,481,462,521,463,510,522,461,448,471,468,586

Vertical:
581
509
481
462
521
436
510
522
461
448
471
468
586
thanks for your help^^
Reply
#2

so I'm pretty sure you got the ID of the vehicle already stored on a variable, didn't you?
To check it with more than one values at the same time, do this:
Код:
if(bikeid == 581 || bikeid == 509 || bikeid == 481 [....] || bikeid == 586)
obviously in the [....] just fulfill the same way with the other ID's.

a little tip:
Код:
== equals
!= differs
|| or
&& and
Reply
#3

it still tries to add nos on my bike :S

pawn Код:
if (!strcmp (cmdtext,"/nos", true))
    {
      if(IsPlayerInAnyVehicle(playerid))
      {
        new vehid;
        vehid = GetPlayerVehicleID(playerid);
        if(vehid != 581 || vehid != 509 || vehid != 481 || vehid != 462 || vehid != 521 || vehid != 436 || vehid != 510 || vehid != 522 || vehid != 461 || vehid != 448 || vehid !=471 || vehid !=468 || vehid != 586)
        {
            AddVehicleComponent(vehid,1010);
            return 1;
        }
        return SendClientMessage(playerid,0xFF0000FF,"Invalid vehicle!(probably a bike)");
        }
        return SendClientMessage(playerid,0xFF0000FF,"Enter a vehicle first!");
    }
can you see the error?
Reply
#4

return it with false, then do 'else' on other vehicles, which aren't bikes.

And none can see the error, you didn't post it.
Reply
#5

the game crashes, that's the error

with the new code now i don't get errors when compiling, but i crash ingame instead(because of the nos on bike)

also, i didn't quite get what you meant with

"return it with false, then do 'else' on other vehicles, which aren't bikes."

didn't i do that already? :P
Reply
#6

Quote:
Originally Posted by Coolman12
can you see the error?
sure, you use vehicleid but you wanted modelid, use GetVehicleModel(vehicleid)
Reply
#7

Yeh you need:

pawn Код:
if (!strcmp (cmdtext,"/nos", true))
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new vehid, modid;
        vehid = GetPlayerVehicleID(playerid);
        modid = GetVehicleModel(vehid);

        if(modid != 581 && modid != 509 && modid != 481 && modid != 462 && modid != 521 && modid != 436 && modid != 510 && modid != 522 && modid != 461 && modid != 448 && modid != 471 && modid != 468 && modid != 586)
        {
            AddVehicleComponent(vehid,1010);
            return 1;
        }
        return SendClientMessage(playerid,0xFF0000FF,"Invalid vehicle!(probably a bike)");
    }
    return SendClientMessage(playerid,0xFF0000FF,"Enter a vehicle first!");
}
Reply
#8

I tried with:

pawn Код:
if (!strcmp (cmdtext,"/nos", true))
    {
      if(IsPlayerInAnyVehicle(playerid))
      {
        new vehid;
        new vehicle;
        vehid = GetVehicleModel(vehicle);
        vehicle = GetPlayerVehicleID(playerid);
        if(vehid != 581 || vehid != 509 || vehid != 481 || vehid != 462 || vehid != 521 || vehid != 436 || vehid != 510 || vehid != 522 || vehid != 461 || vehid != 448 || vehid != 471 || vehid != 468 || vehid != 586)
        {
            AddVehicleComponent(vehid,1010);
            return 1;
        }
        return SendClientMessage(playerid,0xFF0000FF,"Invalid vehicle!(probably a bike)");
        }
        return SendClientMessage(playerid,0xFF0000FF,"Enter a vehicle first!");
    }
Now nothing happens when i'm in a car or on a bike.

Got to sleep now tho, i'll check back tomorrow.
Reply
#9

You're just checking for bikes, and bikes are not the only unsupported vehicles. Here's my command plus a function from somebody I don't really remember. Yeah. It's a full solution.

Command:
Код:
if(strcmp(cmdtext,"/nos",true)==0)
{
  if(IsPlayerInInvalidNosVehicle(playerid)) {
    SendClientMessage(playerid,0xFFFF00FF,"You can't add nitro to this car.");
    return 1;
  }

  if(IsPlayerInAnyVehicle(playerid)) {
    if(GetPlayerState(playerid) == 2) {
      AddVehicleComponent(GetPlayerVehicleID(playerid),1010);
      SendClientMessage(playerid,0x00FF00FF,"Your car now has nitro.");
      return 1;
    }

    else {
      SendClientMessage(playerid,0xFFFF00FF"You must be the driver of the vehicle in order to add nitro.");
      return 1;
    }

  }
  else {
    SendClientMessage(playerid,0xFFFF00FF,"Seriously... you have to be in a vehicle to add nitro.");
    return 1;
  }
}
Now add this to the end of your nice script:
Код:
stock IsPlayerInInvalidNosVehicle(playerid)
{

	new vehicleid = GetPlayerVehicleID(playerid);

	if(IsPlayerInAnyVehicle(playerid))
	{
		for(new i = 0; i < MAX_INVALID_NOS_VEHICLES; i++)
		{
			if(GetVehicleModel(vehicleid) == InvalidNosVehicles[i])
			{
				return true;
			}
		}
	}
	return false;
}
And finally, add this to the top with your defines and shit:
Код:
native IsPlayerInInvalidNosVehicle(playerid);
new InvalidNosVehicles[MAX_INVALID_NOS_VEHICLES] =
{
581,523,462,521,463,522,461,448,468,586,417,425,469,487,512,520,563,593,
509,481,510,472,473,493,520,595,484,430,453,432,476,497,513,533,577,
452,446,447,454,590,569,537,538,570,449,519,460,488,511,519,548,592
};
I use an include, so report any problem with the codes and I'll fix it for you.
Reply
#10

still if you want to detect the bike,

pawn Код:
new bikes[] = { 581, 523, 462, 521, 463, 522, 461, 448, 468, 586, 509, 481, 510, 471, 539};

IsABike(carid)
{
    carid=GetVehicleModel(carid);
    for(new i=0;i<sizeof(bikes);i++)
    {
        if(carid==bikes[i]){return 1;}
    }
    return 0;
}

if(!IsABike(vehid)
{
    // add the shit
}
else
{
    // you kow if it is a bike =)
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)