SA-MP Forums Archive
ZCMD string 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)
+--- Thread: ZCMD string problem (/showthread.php?tid=573172)



ZCMD string problem - Lirbo - 05.05.2015

In the both cases it's says "Invite"

pawn Код:
CMD:clan(playerid,params[]){
if(sscanf(params,"s",TinyString)) return MSG(playerid,C_RED,"/Clan [Invite/Kick/Join/Leave/SetRank/SetTag]");
if(strval(TinyString) == strval("Invite")) return MSG(playerid,C_RED,"Invite");
if(strval(TinyString) == strval("Kick")) return MSG(playerid,C_RED,"Kick");
return 1;}



Re: ZCMD string problem - DarkLouis - 05.05.2015

strval = valor of string = number.

Use strcmp.

Example: if(strcmp(s, "Invite")) return MSG(playerid,C_RED,"Invite");


Re: ZCMD string problem - Airman123 - 05.05.2015

Код:
CMD:clan(playerid,params[]){
if(sscanf(params,"s",TinyString)) return MSG(playerid,C_RED,"/Clan [Invite/Kick/Join/Leave/SetRank/SetTag]");
if(strval(TinyString) == strval("Invite")) return MSG(playerid,C_RED,"Invite");
else if(strval(TinyString) == strval("Kick")) return MSG(playerid,C_RED,"Kick");
return 1;}
this may work, i just used "else" in 2nd case.


Re: ZCMD string problem - Lirbo - 05.05.2015

Quote:
Originally Posted by Airman123
Посмотреть сообщение
Код:
CMD:clan(playerid,params[]){
if(sscanf(params,"s",TinyString)) return MSG(playerid,C_RED,"/Clan [Invite/Kick/Join/Leave/SetRank/SetTag]");
if(strval(TinyString) == strval("Invite")) return MSG(playerid,C_RED,"Invite");
else if(strval(TinyString) == strval("Kick")) return MSG(playerid,C_RED,"Kick");
return 1;}
this may work, i just used "else" in 2nd case.
okay so i need to add else after every if(TinyString) etc?


Re: ZCMD string problem - DarkLouis - 05.05.2015

It will not work. You try to check NUMBER with letters!

You need STRCMP. Ex: if(strcmp(s, "Invite")) return MSG(playerid,C_RED,"Invite");


Re: ZCMD string problem - DarkLouis - 05.05.2015

PHP код:

CMD
:clan(playerid,params[])
{
    new 
string[50];
    if(
sscanf(params,"s[50]",string)) return MSG(playerid,C_RED,"/Clan [Invite/Kick/Join/Leave/SetRank/SetTag]");
    
    if(
strcmp(string"Invite")) return MSG(playerid,C_RED,"Invite");
    else if(
strcmp(string"Kick")) return MSG(playerid,C_RED,"Kick");
    
    return 
1;




Re: ZCMD string problem - Lirbo - 05.05.2015

Quote:
Originally Posted by Airman123
Посмотреть сообщение
Код:
CMD:clan(playerid,params[]){
if(sscanf(params,"s",TinyString)) return MSG(playerid,C_RED,"/Clan [Invite/Kick/Join/Leave/SetRank/SetTag]");
if(strval(TinyString) == strval("Invite")) return MSG(playerid,C_RED,"Invite");
else if(strval(TinyString) == strval("Kick")) return MSG(playerid,C_RED,"Kick");
return 1;}
this may work, i just used "else" in 2nd case.
Quote:
Originally Posted by DarkLouis
Посмотреть сообщение
It will not work. You try to check NUMBER with letters!

You need STRCMP. Ex: if(strcmp(s, "Invite")) return MSG(playerid,C_RED,"Invite");
Still not working

pawn Код:
CMD:clan(playerid,params[]){
if(sscanf(params,"s",TinyString)) return MSG(playerid,C_RED,"/Clan [Invite/Kick/Join/Leave/SetRank/SetTag]");
if(strcmp(TinyString, "Invite")) return MSG(playerid,C_RED,"Invite");
if(strcmp(TinyString, "Kick")) return MSG(playerid,C_RED,"Kick");
return 1;}



Re: ZCMD string problem - Misiur - 05.05.2015

Almost.

https://sampwiki.blast.hk/wiki/Strcmp

This function returns difference between two strings. If the return is 0, it means they are equal (might be case insensitive). So, you need to check for !strcmp(s, "Invite"), or strcmp(s, "Invite") == 0.

If you want to work with numbers, use y_stringhash


Re: ZCMD string problem - Lirbo - 05.05.2015

Quote:
Originally Posted by Misiur
Посмотреть сообщение
Almost.

https://sampwiki.blast.hk/wiki/Strcmp

This function returns difference between two strings. If the return is 0, it means they are equal (might be case insensitive). So, you need to check for !strcmp(s, "Invite"), or strcmp(s, "Invite") == 0.

If you want to work with numbers, use y_stringhash
:* <3