Little strcmp problem
#1

Hello Guys, I have a piece of code, But i doesn't work properly:

pawn Код:
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        SendClientMessage(playerid, -1, "   if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)");  // Tis will be called
        if(strcmp(VehicleInfo[vehicleid][vOwner], PlayerInfo[playerid][pName], false)) // But this Won't
        {
            SendClientMessage(playerid, -1, "strcmp(VehicleInfo[vehicleid][vOwner], PlayerInfo[playerid][pName], false)");
The Problem is in this line:

Код:
        if(strcmp(VehicleInfo[vehicleid][vOwner], PlayerInfo[playerid][pName], false))
it Should check if the playername is equel with the vOwner of the Vehicle.. But it doesn't.
Maybe one of you knows how to fix this.


Greetings,
Gforcez
Reply
#2

strcmp returns 0 when the strings match. So you need to edit your code accordingly, for example:

pawn Код:
if(!strcmp(VehicleInfo[vehicleid][vOwner], PlayerInfo[playerid][pName], false))
Reply
#3

try:
pawn Код:
if(VehicleInfo[vehicleid][vOwner] == PlayerInfo[playerid][pName])
{

}
else return SendClientMessage(playerid, 0x0259EAAA, "This vehicle isn't yours");
not tested! Can have no sence but test...
Coz == means iquals to something
Reply
#4

Thanks Both for your help, JaTochNietDan's way works.
Reply
#5

For better performance I'd suggest to create a "key" system, with variables (integers) instead of comparing strings every time someone enters a vehicle/changes state.

Like Key = vehicleid, and if a player owns that vehicle, his "vKey" is the vehicleid.
Reply
#6

Quote:
Originally Posted by ricardo178
Посмотреть сообщение
try:
pawn Код:
if(VehicleInfo[vehicleid][vOwner] == PlayerInfo[playerid][pName])
{

}
else return SendClientMessage(playerid, 0x0259EAAA, "This vehicle isn't yours");
not tested! Can have no sence but test...
Coz == means iquals to something
Just to point out the '==' operator does only check integers similarity. For strings strcmp is a must.
Reply
#7

Quote:
Originally Posted by Mike Garber
Посмотреть сообщение
For better performance I'd suggest to create a "key" system, with variables (integers) instead of comparing strings every time someone enters a vehicle/changes state.

Like Key = vehicleid, and if a player owns that vehicle, his "vKey" is the vehicleid.
Since you said that.
if the guy owns a banshee for example, won't he be able to enter ALL banshees?
Reply
#8

Quote:
Originally Posted by maramizo
Посмотреть сообщение
Since you said that.
if the guy owns a banshee for example, won't he be able to enter ALL banshees?
vehicleid (e.g 1 = first created vehicle etc.) is not the same as modelid (e.g 425 for Hunter)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)