strcmp problem... -
knackworst - 16.10.2011
hello folks
I'm making a business system, and I got pretty far whitout any errors until now...
pawn Код:
dcmd_enter(playerid, params[])
{
#pragma unused params
new DialogTitle[50],
string[1000];
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if (GetPlayerVehicleSeat(playerid) == 1) return SendClientMessage(playerid,COLOR_RED,"*You enter businesses in a vehicle!");
for(new u;u<sizeof(bInfo);u++)
{
if (IsPlayerInRangeOfPoint(playerid, 2.5, bInfo[u][bus_x], bInfo[u][bus_y], bInfo[u][bus_z]))
{
if(bInfo[u][bus_owned] == true)
{
if(strcmp(bInfo[u][bus_owner], name, false))
{
pInBus[playerid] = true;
SetPlayerCameraPos(playerid, bInfo[u][bus_x], bInfo[u][bus_y], bInfo[u][bus_z]+59);
SetPlayerCameraLookAt(playerid, bInfo[u][bus_x], bInfo[u][bus_y], bInfo[u][bus_z]);
format(DialogTitle, sizeof(DialogTitle), "%s", bInfo[u][bus_name]);
format(string, sizeof(string), "%sUpgrade business\n", string);
format(string, sizeof(string), "%sSell business\n", string);
format(string, sizeof(string), "%sExit menu\n", string);
ShowPlayerDialog(playerid, 100, DIALOG_STYLE_LIST, DialogTitle, string, "Select", "Cancel");
}
else
SendClientMessage(playerid,COLOR_RED,"*You do not own this business!");
}
}
else
SendClientMessage(playerid,COLOR_RED,"*You are not near any business!");
}
return 1;
}
ok so this is a command to enter your business
and here is a part of the command to buy a business:
pawn Код:
format(bInfo[u][bus_owner], MAX_PLAYER_NAME, name);
this works
now when I go ingame it should give an error message when u tried to enter the business
there for this line in the Enter command:
pawn Код:
if(strcmp(bInfo[u][bus_owner], name, false))
{
but when I go ingame it does the opposite of what I ask...
I get the message when the player is the owner, but not when the player isn't owner...
I know I can just solve this by adding ! infront of the strcmp
but then I didn't learn anything...
Thanks in advance
Re: strcmp problem... -
DaRkAnGeL[NBK] - 16.10.2011
have you tryed true?
Re: strcmp problem... -
Wesley221 - 16.10.2011
If the 2 strings match with eachother, strcmp returns 0. And when they dont match, it returns 1.
This is an useful tutorial, with some information on how it really works:
https://sampforum.blast.hk/showthread.php?tid=199796
Re: strcmp problem... -
knackworst - 16.10.2011
Thanks both
1: false is necesaiy otherwise u can very easly hack businesses by changin ur name into sometin thats vey similr to the owners name
2: i still dont really understand what i did wrong...?
Re: strcmp problem... -
Wesley221 - 16.10.2011
You didnt do anything wrong.
pawn Код:
strcmp("text1", "text1") // this will return 0 (the 2 strings compare)
strcmp("text1", "text2") // this will return 1 (the 2 strings arent the same)
!strcmp("text1", "text1") // this will return 1 (NOTE the '!')
!strcmp("text1", "text2") // this will return 0 (NOTE the '!')
Re: strcmp problem... -
SuperViper - 16.10.2011
pawn Код:
if(strcmp(bInfo[u][bus_owner], name, false) == 0)
{