"CheckOwner" not working...
#1

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!
Reply
#2

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

I did, and I honestly can't see.
Reply
#4

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!
Reply
#5

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.
Reply
#6

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.
Reply
#7

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.
Reply
#8

Telling me to give up scripting isn't helping.
Reply
#9

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.
Reply
#10

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
Reply
#11

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;
}
Reply
#12

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. >.>
Reply
#13

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++)
..
Reply
#14

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.
Reply
#15

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)