Little strcmp problem - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Little strcmp problem (
/showthread.php?tid=242745)
Little strcmp problem -
Gforcez - 20.03.2011
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
Re: Little strcmp problem -
JaTochNietDan - 20.03.2011
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))
Re: Little strcmp problem -
ricardo178 - 20.03.2011
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
Re: Little strcmp problem -
Gforcez - 20.03.2011
Thanks Both for your help, JaTochNietDan's way works.
Re: Little strcmp problem -
Mike Garber - 20.03.2011
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.
Re: Little strcmp problem -
admantis - 20.03.2011
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.
Re: Little strcmp problem -
maramizo - 20.03.2011
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?
Re: Little strcmp problem -
Mike Garber - 20.03.2011
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)