[HELP] PlayerIntoVehicle
#1

Okay i got this :

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	if(IsPlayerInVehicle(playerid, 462))
	{
	GivePlayerMoney(playerid, -25);
	}
	else
	(
	GameTextForPlayer(playerid, "Not Enough ~g~ Money",1500,5);
	
	}
and i want the player to be ejected from the vehicle when he doesn't got enough money. what code i need to add?

Sorry for my english.
Reply
#2


pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(IsPlayerInVehicle(playerid, 462))
    {
        if(GetPlayerState(playerid) == 2)//checks if player entered as driver
        {
            if(GetPlayerMoney(playerid) >= 25) //25 = the money u want the car to cost.
            {
                GivePlayerMoney(playerid,-25);
                SendClientMessage(playerid,YOUR_COLOR,"You just bought this car.");
            }
            else
            SendClientMessage(playerid,YOUR_COLOR,"You don't have enought money for this car.");
            RemovePlayerFromVehicle(playerid);
        }
        else
        SendClientMessage(playerid,YOUR_COLOR,"You need to enter as driver to buy this car."); //change YOUR_COLOR to the colors you have got and that you want to use
        RemovePlayerFromVehicle(playerid);
    }
}
Reply
#3

thank you but it doesn't work... and i got 0 errors.........

Reply
#4

Quote:
Originally Posted by Smiths
thank you but it doesn't work... and i got 0 errors.........

what errors?
because when i compiled it it gave no errors
and if u didnt have errors
what doesnt work exactly?
Reply
#5

https://sampwiki.blast.hk/wiki/IsPlayerInVehicle
Vehicle ID is not the same as vehicle model.

Change
pawn Код:
if(IsPlayerInVehicle(playerid, 462))
to
pawn Код:
if (GetVehicleModel(vehicleid) == 462)
Reply
#6

Quote:
Originally Posted by ZeeX
https://sampwiki.blast.hk/wiki/IsPlayerInVehicle
Vehicle ID is not the same as vehicle model.

Change
pawn Код:
if(IsPlayerInVehicle(playerid, 462))
to
pawn Код:
if (GetVehicleModel(vehicleid) == 462)
mep i dunno
maybe its just his vehid^^
Reply
#7

OnPlayerEnterVehicle callback is called when someone presses _vehicle_enter_key_ (ENTER or F, ..), so you can't remove him if he is entering (he's not in), it's better if you set his position like this:
pawn Код:
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerPos(playerid, x, y, z);
Reply
#8

Quote:
Originally Posted by Don Correlli
OnPlayerEnterVehicle callback is called when someone presses _vehicle_enter_key_ (ENTER or F, ..), so you can't remove him if he is entering (he's not in), it's better if you set his position like this:
pawn Код:
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
SetPlayerPos(playerid, x, y, z);
hm right don but then best is i guess to use it on OnPlayerStateChange
then u dont to get the playerstate tho XD
just newstate
Reply
#9

Using OnPlayerStateChange is better beacause
Quote:

OnPlayerEnterVehicle callback is called when someone presses _vehicle_enter_key_ (ENTER or F, ..), so you can't remove him if he is entering (he's not in)

Here you go:

pawn Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER) //checks if player enters car as driver
    {
        if(IsPlayerInVehicle(playerid, 462)) //checks if player is in vehicle n°462
        {
            if(GetPlayerMoney(playerid) >= 25) // check if player got $25 or more
            {
                GivePlayerMoney(playerid, -25);
            }  
            else //(if player got less than $25)
            (
                RemovePlayerFromVehicle(playerid);
                GameTextForPlayer(playerid, "Not Enough ~g~ Money",1500,5);
            }
        }  
    }
    return 1;
}
Reply
#10

Quote:
Originally Posted by Coicatak
Using OnPlayerStateChange is better beacause
Quote:

OnPlayerEnterVehicle callback is called when someone presses _vehicle_enter_key_ (ENTER or F, ..), so you can't remove him if he is entering (he's not in)

Here you go:

pawn Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER) //checks if player enters car as driver
    {
        if(IsPlayerInVehicle(playerid, 462)) //checks if player is in vehicle n°462
        {
            if(GetPlayerMoney(playerid) >= 25) // check if player got $25 or more
            {
                GivePlayerMoney(playerid, -25);
            }  
            else //(if player got less than $25)
            (
                RemovePlayerFromVehicle(playerid);
                GameTextForPlayer(playerid, "Not Enough ~g~ Money",1500,5);
            }
        }  
    }
    return 1;
}
or just use mine which is better than this actually because it checks more stuff n gives infos about what just happened

pawn Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{  
if(IsPlayerInVehicle(playerid, 462))
    {
        if(newstate == 2)//checks if player entered as driver
        {
            if(GetPlayerMoney(playerid) >= 25) //25 = the money u want the car to cost.
            {
                GivePlayerMoney(playerid,-25);
                SendClientMessage(playerid,YOUR_COLOR,"You just bought this car.");
            }
            else
            SendClientMessage(playerid,YOUR_COLOR,"You don't have enought money for this car.");
            RemovePlayerFromVehicle(playerid);
        }
        else
        SendClientMessage(playerid,YOUR_COLOR,"You need to enter as driver to buy this car."); //change YOUR_COLOR to the colors you have got and that you want to use
        RemovePlayerFromVehicle(playerid);
    }
}
Reply
#11

Quote:
Originally Posted by SaiBerFun
or just use mine which is better than this actually because it checks more stuff n gives infos about what just happened

pawn Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{  
if(IsPlayerInVehicle(playerid, 462))
    {
        if(newstate == 2)//checks if player entered as driver
        {
            if(GetPlayerMoney(playerid) >= 25) //25 = the money u want the car to cost.
            {
                GivePlayerMoney(playerid,-25);
                SendClientMessage(playerid,YOUR_COLOR,"You just bought this car.");
            }
            else
            SendClientMessage(playerid,YOUR_COLOR,"You don't have enought money for this car.");
            RemovePlayerFromVehicle(playerid);
        }
        else
        SendClientMessage(playerid,YOUR_COLOR,"You need to enter as driver to buy this car."); //change YOUR_COLOR to the colors you have got and that you want to use
        RemovePlayerFromVehicle(playerid);
    }
}
Yes it gives information, but it wasn't asked, and I don't see any check that i haven't done.
Btw, you should check if newstate = 2 before checking if the vehicle ID is 462. OnPlayerStateChange is also called when you exit a vehicle or spawn for example.
Also use braces for your esle statments.
Reply
#12

thank you for helping me but it doesnt work... when i go into a Faggio nothing happen...

this is my code :

Код:
public OnPlayerStateChange(playerid,newstate,oldstate)
{
if(IsPlayerInVehicle(playerid, 462))
	{
		if(newstate == 2)//checks if player entered as driver
		{
			if(GetPlayerMoney(playerid) >= 25) //25 = the money u want the car to cost.
			{
				GivePlayerMoney(playerid,-25);
				SendClientMessage(playerid,0xFFFF00AA,"You just bought this car.");
			}
			else
			SendClientMessage(playerid,0xFFFF00AA,"You don't have enought money for this car.");
			RemovePlayerFromVehicle(playerid);
		}
		else
		SendClientMessage(playerid,0xFFFF00AA,"You need to enter as driver to buy this car."); //change YOUR_COLOR to the colors you have got and that you want to use
		RemovePlayerFromVehicle(playerid);
	}
}
Reply
#13

Use this. But ensure that 462 is the ID of the car you want to cost $25.

pawn Код:
#define YOUR_COLOR 0xFFFF00AA
public OnPlayerStateChange(playerid,newstate,oldstate)
{  
    if(newstate == PLAYER_STATE_DRIVER)//checks if player entered as driver
    {
        if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 462) //You have to check Model ID not vehicle id.
        {
            if(GetPlayerMoney(playerid) >= 25) //25 = the money u want the car to cost.
            {
                GivePlayerMoney(playerid,-25);
                SendClientMessage(playerid,YOUR_COLOR,"You just bought this car.");
            }
            else
            {
                SendClientMessage(playerid,YOUR_COLOR,"You don't have enought money for this car.");
                RemovePlayerFromVehicle(playerid);
            }
        }
        else
        {
            SendClientMessage(playerid,YOUR_COLOR,"You need to enter as driver to buy this car.");
            RemovePlayerFromVehicle(playerid);
        }
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)