Small help
#1

Hello,i got this score check for every vehicles, means if you dont have the required score, you can't drive a certain vehicle.It works but there is a problem, even if i have the required score, it keeps saying "You need XX score etc" but i can drive it.

Any tip?

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(GetVehicleModel(vehicleid) == 520) //Hydra
    {
        if(GetPlayerScore(playerid) <= 1500) RemovePlayerFromVehicle(playerid);
        SendClientMessage(playerid,0xAA3333AA,"You need 1500 score to drive this Hydra.");
        return 1;
    }
   
    if(GetVehicleModel(vehicleid) == 432) //Rhino
    {
        if(GetPlayerScore(playerid) <= 300) RemovePlayerFromVehicle(playerid);
        SendClientMessage(playerid,0xAA3333AA,"You need 300 score to drive this Rhino.");
        return 1;
    }
   
    if(GetVehicleModel(vehicleid) == 425) //Hunter
    {
        if(GetPlayerScore(playerid) <= 1000) RemovePlayerFromVehicle(playerid);
        SendClientMessage(playerid,0xAA3333AA,"You need 1000 score to drive this Hunter.");
        return 1;
    }
    else return 1;
}
Reply
#2

I'm not sure but, maybe it is because you didn't call the return.

Return always stops the rest of the code (Below).

try doing this

PHP код:
if(GetPlayerScore(playerid) >= YourScore)
{

}
else
{


Reply
#3

Umh nothing, still the same.
Reply
#4

nah, you simply forgot to place some {} braces:
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	new vehicleid = GetPlayerVehicleID(playerid);
	if(GetVehicleModel(vehicleid) == 520) //Hydra
	{
		if(GetPlayerScore(playerid) < 1500)
		{
			RemovePlayerFromVehicle(playerid);
			SendClientMessage(playerid,0xAA3333AA,"You need 1500 score to drive this Hydra.");
			return 1;
		}
	}
	if(GetVehicleModel(vehicleid) == 432) //Rhino
	{
		if(GetPlayerScore(playerid) < 300) 
		{
			RemovePlayerFromVehicle(playerid);
			SendClientMessage(playerid,0xAA3333AA,"You need 300 score to drive this Rhino.");
			return 1;
		}
	}
	if(GetVehicleModel(vehicleid) == 425) //Hunter
	{
		if(GetPlayerScore(playerid) < 1000)
		{
			RemovePlayerFromVehicle(playerid);
			SendClientMessage(playerid,0xAA3333AA,"You need 1000 score to drive this Hunter.");
			return 1;
		}
	}
	return 1;
}
edit: oops, now i changed the <= to just < so the score check wont remove a player at the certain score to drive/fly.
Reply
#5

Quote:
Originally Posted by Babul
Посмотреть сообщение
nah, you simply forgot to place some {} braces:
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
	new vehicleid = GetPlayerVehicleID(playerid);
	if(GetVehicleModel(vehicleid) == 520) //Hydra
	{
		if(GetPlayerScore(playerid) < 1500)
		{
			RemovePlayerFromVehicle(playerid);
			SendClientMessage(playerid,0xAA3333AA,"You need 1500 score to drive this Hydra.");
			return 1;
		}
	}
	if(GetVehicleModel(vehicleid) == 432) //Rhino
	{
		if(GetPlayerScore(playerid) < 300) 
		{
			RemovePlayerFromVehicle(playerid);
			SendClientMessage(playerid,0xAA3333AA,"You need 300 score to drive this Rhino.");
			return 1;
		}
	}
	if(GetVehicleModel(vehicleid) == 425) //Hunter
	{
		if(GetPlayerScore(playerid) < 1000)
		{
			RemovePlayerFromVehicle(playerid);
			SendClientMessage(playerid,0xAA3333AA,"You need 1000 score to drive this Hunter.");
			return 1;
		}
	}
	return 1;
}
Aaaaand it works, thank you

edit: oops, now i changed the <= to just < so the score check wont remove a player at the certain score to drive/fly.
Quote:
Originally Posted by ******
Посмотреть сообщение
THIS is EXACTLY the reason why we tell people to ALWAYS use braces and ALWAYS use proper indentation and proper new lines. While your code in the first post is technically valid, using good practice can reduce bugs.
Yeah, my mistake while adding braces.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)