Check if player is on bike or not
#1

Hi i am trying to make a function that checks if the player is on a bike or not
i had on top of script this

Код:
stock IsBike(vehicle1)
	{
 	 	new vmodel = GetVehicleModel(vehicle1);
		if(vmodel== 509 || vmodel == 481 || vmodel == 462 || vmodel == 522 || vmodel == 471 || vmodel == 586)
    return true;
  else
    return false;
	}
and at the spawn block that runs by timer

Код:
new vehicle1;
	vehicle1 = GetPlayerVehicleID(playerid);
	if(IsBike(vehicle1))	SendClientMessage(playerid, 0x3333FFFF, "[Server] Bike test!");
Now if i am on a bike it should give that tekst but it doesnt work, does anybody have an idea why not?

thanks in advance!
Reply
#2

There's already a function created by Andre, and it works.
(The IsBike Function)

http://forum.sa-mp.com/index.php?top...9011#msg409011

Reply
#3

Quote:

PAWN Code:
stock IsBike(carid)
{
new Bikes[] = { 509, 481, 510 };
for(new i = 0; i < sizeof(Bikes); i++)
{
if(GetVehicleModel(carid) == Bikes[i]) return 1;
}
return 0;
}

How can i omplant that then ? do i do the command at the place of return 1?
like

Код:
PAWN Code:
stock IsBike(carid)
{
  new Bikes[] = { 509, 481, 510 };
  for(new i = 0; i < sizeof(Bikes); i++)
  {
    if(GetVehicleModel(carid) == Bikes[i]) bike[playerid] = 1 return 1;
  }
  return 0;
}
Reply
#4

pawn Код:
stock IsABike(veh)
{
  new Bike = GetVehicleModel(veh);
  if(bike == 509 || bike == 510 || bike == 481) return 1;
  return 0; // if is another model
}


if(!strcmp(cmd,"/test",true))
{
  new car = GetPlayerVehicleID(playerid);
  if(IsABike(car) && GetPlayerState(playerid) == 2)
  {
     SendClientMessage(playerid,0xFF,"You are on a bike.");
     return 1;
  }
  else return SendClientMessage(playerid,0xC1,"You are not on a bike.");
}
Reply
#5

Here's an example, the function is called when the player enters any vehicle. It kicks them out if they dont have skin 110 when entering a bike.

pawn Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
    new carid;
    carid = GetVehicleModel(GetPlayerVehicleID(playerid));
    new skin = GetPlayerSkin(playerid);
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        if(IsBike(carid))
        {
            if(skin == 110)
            {
                SendClientMessage(playerid, 0x48FF48FF, "== You can use this Bike");
            }
            else
            {
                SendClientMessage(playerid, 0xFF0000AA, "== You cannot use this Bike - Ejected");
                RemovePlayerFromVehicle(playerid);
            }
        }
    }
    return 1;
}

stock IsBike(carid)
{
  new Bikes[] = { 509, 481, 510 };
  for(new i = 0; i < sizeof(Bikes); i++)
  {
    if(GetVehicleModel(carid) == Bikes[i]) return 1;
  }
  return 0;
}
If yo uwant to use it for something else tell me what you want to the the function for, and i'll try and help.
This is untested, and might be wrong somewhere (havn't been using pawn cos of exams lately )
Reply
#6

i did it like this

Код:
new car1 = GetPlayerVehicleID(playerid); <- the function GetPlayerVehicleModel doesnt exist. 
  if(IsBike(car1))
  {
     SendClientMessage(playerid,0xFF,"You are on a bike.");
     return 1;
  }
Код:
stock IsBike(veh)
	{
 	 	new Bike = GetVehicleModel(veh);
		if(Bike== 509 || Bike == 481 || Bike == 462 || Bike == 522 || Bike == 471 || Bike == 586) return 1;
    return 0;
 	}
i need the vehicle model not the vehicle id, any body idea?
nothing happens tough
Reply
#7

anybody?
Reply
#8

quote:
and at the spawn block that runs by timer

I find no problem in your code
Maybe is your timer problem.
Put your timer code(forward,public,etc),thx
Reply


Forum Jump:


Users browsing this thread: