question about compare - 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: question about compare (
/showthread.php?tid=421368)
question about compare -
mineralo - 09.03.2013
what is more faster then strcmp?
and please show me an exemple on my loading system
pawn Код:
if(!strcmp(temp[0], "Score", true))
{
PlayerInfo[playerid][pScore] = strval(temp[1]);
SetPlayerScore(playerid,PlayerInfo[playerid][pScore]);
}
else if(!strcmp(temp[0], "Admin", true))
{
SetPlayerAdminLevel(playerid,strval(temp[1]));
}
else if(!strcmp(temp[0], "Job", true))
{
SetPlayerJobID(playerid, strval(temp[1]));
}
else if(!strcmp(temp[0], "Cash", true))
{
SetPlayerCash(playerid,strval(temp[1]));
}
else if(!strcmp(temp[0], "health", true))
{
PlayerInfo[playerid][healthP] = strval(temp[1]);
}
else if(!strcmp(temp[0], "x", true))
{
PlayerInfo[playerid][PosX] = strval(temp[1]);
}
else if(!strcmp(temp[0], "y", true))
{
PlayerInfo[playerid][PosY] = strval(temp[1]);
}
else if(!strcmp(temp[0], "z", true))
{
PlayerInfo[playerid][PosZ] = strval(temp[1]);
}
else if(!strcmp(temp[0], "Interior", true))
{
PlayerInfo[playerid][Inter] = strval(temp[1]);
}
AW: question about compare -
Nero_3D - 09.03.2013
You could hash the string and compare the outputs inside a switch statment
Or you use CallLocalFunction like zcmd, y_cmd does it
pawn Код:
//
new
func[32]
;
format(func, sizeof func, "Loading_%s", temp[0]);
CallLocalFunction(func, "is", playerid, temp[1]); // if temp[1] is empty this part will crash
pawn Код:
#define function%0(%1) forward%0(%1);public%0(%1)
function Loading_Score(playerid, params[]) {
PlayerInfo[playerid][pScore] = strval(params);
SetPlayerScore(playerid, PlayerInfo[playerid][pScore]);
}
function Loading_Admin(playerid, params[]) {
SetPlayerAdminLevel(playerid,strval(params));
}
But I cant tell you how efficient this is for only ~10 strcmp
Re: question about compare -
mineralo - 09.03.2013
well, I have a long list of players stuff, I need one fast and easy to use a compare, the strcmp a bit slow for me