ZCMD string problem
#1

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;}
Reply
#2

strval = valor of string = number.

Use strcmp.

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

Код:
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.
Reply
#4

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?
Reply
#5

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");
Reply
#6

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;

Reply
#7

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;}
Reply
#8

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
Reply
#9

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)