SA-MP Forums Archive
"CheckOwner" not working... - 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: "CheckOwner" not working... (/showthread.php?tid=279051)



"CheckOwner" not working... - Jack_Leslie - 25.08.2011

So here's my code..
pawn Code:
public CheckOwner(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        for(new i = 1; i < sizeof(CarInfo); i++)
        {
            new playername[MAX_PLAYER_NAME];
            GetPlayerName(playerid,playername,sizeof(playername));
            if(strcmp(playername,CarInfo[i][vOwner],true)==0)
            {
                PlayerInfo[playerid][pVehicle] = 1;
                return i;
            }
            else if(strcmp(playername,CarInfo[i][vOwner],false)==0)
            {
                PlayerInfo[playerid][pVehicle] = 0;
                return i;
            }
        }
    }
    return 1;
}
It's meant to check if the playersname matches the one in the enum, however, even though the playersname isn't the same as the one in the enum, it still sets it as 1 (when it's meant to set it as 0 if it's not), please help!


Re: "CheckOwner" not working... - PrawkC - 25.08.2011

Look on the wiki about strcmp, and you'll see what you did wrong.


Re: "CheckOwner" not working... - Jack_Leslie - 25.08.2011

I did, and I honestly can't see.


Re: "CheckOwner" not working... - Emmet_ - 25.08.2011

pawn Code:
public CheckOwner(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        for(new i = 1; i < sizeof(CarInfo); i++)
        {
            new playername[MAX_PLAYER_NAME];
            GetPlayerName(playerid,playername,sizeof(playername));
            if(strcmp(playername,CarInfo[i][vOwner],true)==0)
            {
                PlayerInfo[playerid][pVehicle] = 1;
                return i;
            }
            else
            {
                PlayerInfo[playerid][pVehicle] = 0;
                return i;
            }
        }
    }
    return 1;
}
You should use 'else' and not this:

pawn Code:
else if(strcmp(playername,CarInfo[i][vOwner],false)==0)
            {
                PlayerInfo[playerid][pVehicle] = 0;
                return i;
            }
That checks if the player's name IS the owner of the vehicle again!


Re: "CheckOwner" not working... - PrawkC - 25.08.2011

Just saying, if you honestly couldn't tell what you did wrong with your strcmp, you need to give up scripting, because if you're that blind to not be able to read the params, you won't go far.


Re: "CheckOwner" not working... - Jack_Leslie - 25.08.2011

Quote:
Originally Posted by 69Playa
View Post
pawn Code:
public CheckOwner(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        for(new i = 1; i < sizeof(CarInfo); i++)
        {
            new playername[MAX_PLAYER_NAME];
            GetPlayerName(playerid,playername,sizeof(playername));
            if(strcmp(playername,CarInfo[i][vOwner],true)==0)
            {
                PlayerInfo[playerid][pVehicle] = 1;
                return i;
            }
            else
            {
                PlayerInfo[playerid][pVehicle] = 0;
                return i;
            }
        }
    }
    return 1;
}
You should use 'else' and not this:

pawn Code:
else if(strcmp(playername,CarInfo[i][vOwner],false)==0)
            {
                PlayerInfo[playerid][pVehicle] = 0;
                return i;
            }
That checks if the player's name IS the owner of the vehicle again!
Didn't work mate... and PrawkC, if you're not helping, then get out.


Re: "CheckOwner" not working... - jameskmonger - 25.08.2011

Quote:
Originally Posted by Jack_Leslie
View Post
Didn't work mate... and PrawkC, if you're not helping, then get out.
He was helping don't be so ungrateful.


Re: "CheckOwner" not working... - Jack_Leslie - 25.08.2011

Telling me to give up scripting isn't helping.


Re: "CheckOwner" not working... - PrawkC - 25.08.2011

One of the problems is fixed, because your else if was checking the same thing as your original. If you want help with the other thing, show your enum, and also do some debugging to make sure that the value in the enum is even set correctly.


Re: "CheckOwner" not working... - Jack_Leslie - 25.08.2011

pawn Code:
public CheckOwner(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        for(new i = 1; i < sizeof(CarInfo); i++)
        {
            new playername[MAX_PLAYER_NAME];
            GetPlayerName(playerid, playername, sizeof(playername));
            if(!strcmp(playername, CarInfo[i][vOwner], true))
            {
                PlayerInfo[playerid][pVehicle] = 1;
                return i;
            }
            else
            {
                PlayerInfo[playerid][pVehicle] = 0;
                return i;
            }
        }
    }
    return 1;
}
pawn Code:
enum vInfo
{
    vModel,
    Float:vLocationx,
    Float:vLocationy,
    Float:vLocationz,
    Float:vAngle,
    vColorOne,
    vColorTwo,
    vOwner[MAX_PLAYER_NAME],
    vDescription[MAX_PLAYER_NAME],
    vValue,
    vLicense,
    vRegistration,
    vOwned,
    vLock,
    ownedvehicle,
    vMod1,
    vMod2,
    vMod3,
    vMod4,
    vMod5,
    vMod6,
    vMod7,
    vMod8,
    vMod9,
    vMod10,
    vMod11,
    vMod12,
    vMod13,
    vMod14,
    vMod15,
    vMod16,
    vMod17

};
new CarInfo[200][vInfo];
Similar code to this one that works:
pawn Code:
stock GetCarIDFromPlayer_Enum(PlayerID)
{
    new PlayersName[MAX_PLAYER_NAME];
    GetPlayerName(PlayerID, PlayersName, MAX_PLAYER_NAME);
    for(new i=0; i<sizeof(CarInfo); i++)
    {
        if(!strcmp(CarInfo[i][vOwner], PlayersName)) return i; //Returns the ID of the Ownership
    }
    return -1;
}
Finds the vehid that has the players name and returns the ID, kinda need the opposite to that...
Cheers


Re: "CheckOwner" not working... - PrawkC - 25.08.2011

Debug your CarInfo[vehicleid][vOwner] and make sure that its set correctly
so do like

pawn Code:
public CheckOwner(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        for(new i = 1; i < sizeof(CarInfo); i++)
        {
            printf("Car %d owner %s", i, CarInfo[i][vOwner]);
            new playername[MAX_PLAYER_NAME];
            GetPlayerName(playerid, playername, sizeof(playername));
            if(!strcmp(playername, CarInfo[i][vOwner], true))
            {
                PlayerInfo[playerid][pVehicle] = 1;
                return i;
            }
            else
            {
                PlayerInfo[playerid][pVehicle] = 0;
                return i;
            }
        }
    }
    return 1;
}



Re: "CheckOwner" not working... - Jack_Leslie - 25.08.2011

Quote:
Originally Posted by PrawkC
View Post
Debug your CarInfo[vehicleid][vOwner] and make sure that its set correctly
so do like

pawn Code:
public CheckOwner(playerid)
{
    if(IsPlayerConnected(playerid))
    {
        for(new i = 1; i < sizeof(CarInfo); i++)
        {
            printf("Car %d owner %s", i, CarInfo[i][vOwner]);
            new playername[MAX_PLAYER_NAME];
            GetPlayerName(playerid, playername, sizeof(playername));
            if(!strcmp(playername, CarInfo[i][vOwner], true))
            {
                PlayerInfo[playerid][pVehicle] = 1;
                return i;
            }
            else
            {
                PlayerInfo[playerid][pVehicle] = 0;
                return i;
            }
        }
    }
    return 1;
}
Done it, and it prints out "Car 1 owner " (nothing after owner), I have a debug command as well,
pawn Code:
if(strcmp(cmd,"/vtest",true) == 0)
    {
        new pveh = PlayerInfo[playerid][pVehicle];
        format(string, sizeof(string), "Debug: %d.", pveh);
        SendClientMessage(playerid, COLOR_GREY, string);
        return 1;
    }
And I have CheckOwner(playerid); under my OnPlayerLogin call, but when I do /vtest it says it's 1, but should be 0. >.>


Re: "CheckOwner" not working... - PrawkC - 25.08.2011

Well, I don't understand fully.. but I think you need to
for(new i = 1; i < sizeof(CarInfo); i++)
to
for(new i = 0; i < sizeof(CarInfo); i++)
..


Re: "CheckOwner" not working... - Jack_Leslie - 25.08.2011

Quote:
Originally Posted by PrawkC
View Post
Well, I don't understand fully.. but I think you need to
for(new i = 1; i < sizeof(CarInfo); i++)
to
for(new i = 0; i < sizeof(CarInfo); i++)
..
EDIT:

Fixed it,
Code:
if(!strcmp(playername, CarInfo[i][vOwner], true))
("!" means it would ask if it was actually false, but I needed to ask if it was true)

was meant to be
Code:
if(strcmp(playername, CarInfo[i][vOwner], true))
Thankyou for the help prawk.


Re: "CheckOwner" not working... - jameskmonger - 25.08.2011

Quote:
Originally Posted by Jack_Leslie
View Post
Telling me to give up scripting isn't helping.
It is helping, it stops you from wasting time on a pointless goal.