SA-MP Forums Archive
odd function behavor - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: odd function behavor (/showthread.php?tid=306408)



odd function behavor - Unknown123 - 26.12.2011

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if(!IsVehicleOwner(plyerid, vehicleid))
        {
            SendClientMessage(playerid, 0xFF0000FF, "this is not your vehicle");
            print("not yours");
            //eject
        }
        printf("Name lenght: %i | Awesome ID: %i | Owner: %s", strlen(GetVehicleOwner(vehicleid)), AwesomeVehicleID(vehicleid), GetVehicleOwner(vehicleid));
    }
    return 1;
}

stock IsVehicleOwner(playerid, vehicleid)
{
    new awesomeid = AwesomeVehicleID(vehicleid);
    if((awesomeid != 0)
    && (strmatch(PlayerName(playerid), VehicleData[awesomeid][VehicleOwner]))) return 1; // if "awesomeid is not 0 && player name match with vehicle name then return true (yes)
    return 0; // else return false (no)
}
Код:
not yours
Name lenght: 0 | Awesome ID: 0 | Owner:
i get ejected when the "Awesome ID" is 0, but im not supposed to do that (read the function)


Re: odd function behavor - FireCat - 26.12.2011

Quote:
Originally Posted by Unknown123
Посмотреть сообщение
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if(!IsVehicleOwner(plyerid, vehicleid))
        {
            SendClientMessage(playerid, 0xFF0000FF, "this is not your vehicle");
            print("not yours");
            //eject
        }
        printf("Name lenght: %i | Awesome ID: %i | Owner: %s", strlen(GetVehicleOwner(vehicleid)), AwesomeVehicleID(vehicleid), GetVehicleOwner(vehicleid));
    }
    return 1;
}

stock IsVehicleOwner(playerid, vehicleid)
{
    new awesomeid = AwesomeVehicleID(vehicleid);
    if((awesomeid != 0)
    && (strmatch(PlayerName(playerid), VehicleData[awesomeid][VehicleOwner]))) return 1; // if "awesomeid is not 0 && player name match with vehicle name then return true (yes)
    return 0; // else return false (no)
}
Код:
not yours
Name lenght: 0 | Awesome ID: 0 | Owner:
i get ejected when the "Awesome ID" is 0, but im not supposed to do that (read the function)
Dont you mean:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if(!IsVehicleOwner(playerid, vehicleid))//<- You had plyerid
        {
            SendClientMessage(playerid, 0xFF0000FF, "this is not your vehicle");
            print("not yours");
            //eject
        }
        printf("Name lenght: %i | Awesome ID: %i | Owner: %s", strlen(GetVehicleOwner(vehicleid)), AwesomeVehicleID(vehicleid), GetVehicleOwner(vehicleid));
    }
    return 1;
}
And I would do it like this:
pawn Код:
stock IsVehicleOwner(playerid, vehicleid)
{
    if(AwesomeVehicleID(vehicleid) != 0 && strmatch(PlayerName(playerid), VehicleData[awesomeid][VehicleOwner])) return 1;
    return 0;
}



Re: odd function behavor - [MG]Dimi - 26.12.2011

I don't understand this line
pawn Код:
new awesomeid = AwesomeVehicleID(vehicleid)
What does it do exactly? I'm sure something is wrong here.

EDIT:SLOOOOOW xD


Re: odd function behavor - Unknown123 - 26.12.2011

dont work, same problem

i enter a taxi (it have AwesomeID = 0, and i get ejected, but since the awesome id = 0 i shouldent be ejected


Re: odd function behavor - Laronic - 26.12.2011

I had a similar problem like this once too.

Try this
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
    {
        if(!IsVehicleOwner(plyerid, vehicleid) && AwesomeVehicleID(vehicleid) != 0)
        {
            SendClientMessage(playerid, 0xFF0000FF, "this is not your vehicle");
            print("not yours");
            //eject
        }
        printf("Name lenght: %i | Awesome ID: %i | Owner: %s", strlen(GetVehicleOwner(vehicleid)), AwesomeVehicleID(vehicleid), GetVehicleOwner(vehicleid));
    }
    return 1;
}

stock IsVehicleOwner(playerid, vehicleid)
{
    if(strmatch(PlayerName(playerid), VehicleData[awesomeid][VehicleOwner])) return true:
    return false;
}