How do I check if a string Equals a certain word?
#1

pawn Код:
COMMAND:gender(playerid,params[])
{
    SetPVarString(playerid,"Gender",params);
    new strz[38];
    format(strz,sizeof(strz), "Your gender is now set to: %s.",params);
    SendClientMessage(playerid, blue, strz);
    return 1;
}
I want to check if 'params' doesn't equal Male or Female (and if possible ignoring the case, so fEmAle still equals Female).
and if it doesn't then stops the command and sends a Invalid gender message.
Well heres how I would do it in java..
Код:
if(!params.equalsIgnoreCase("male") || params.equalsIgnoreCase("Female"))
But I have no idea how pawn strings work, I just learned about the lengths being how many characters are in it +1 for the null character ending the string...

Thanks for reading.


Bonus question :
Is 12 characters long enough for an Accent?
And should it be >= 14 because of the null characters on strings?
Код:
COMMAND:accent(playerid,params[])
{
    if(strlen(params) >= 13)
    {
        SendClientMessage(playerid, blue, "[LENGTH ERROR] Accent cannot be over 12 characters long.");
        return 1;
    }
	SetPVarString(playerid,"Accent",params);
	new strz[44];
	format(strz,sizeof(strz), "Your accent is now set to: %s.",params);
	SendClientMessage(playerid, blue, strz);
	return 1;
}
Reply
#2

Can we answer the bonus question only after answering the main question?
Reply
#3

Quote:
Originally Posted by Macluawn
Посмотреть сообщение
Can we answer the bonus question only after answering the main question?
Yeah, sorry.
Reply
#4

I looked through Wiki and found strcmp, I'm about to test it to see if its correct for what I'm wanting..
Код:
COMMAND:gender(playerid,params[])
{
	if(!strcmp(params, "female", true, 6) || !strcmp(params, "male", true, 4))
	{
		SetPVarString(playerid,"Gender",params);
		new strz[38];
		format(strz,sizeof(strz), "Your gender is now set to: %s.",params);
		SendClientMessage(playerid, blue, strz);
	} else {
        SendClientMessage(playerid, blue, "INVALID GENDER, Male or Female.");
	}
	return 1;
}
Correct or Incorrect..

Edit: Oops sorry..

Edit (2):
Ok, that kind of works, but i can do /gender femaleanything /gender maleanything
Reply
#5

pawn Код:
COMMAND:gender(playerid,params[])
{
    if(!sscanf(params)) return SendClientMessage(playerid,-1,"You need to select a gender!");
    new strz[38];
    format(strz,sizeof(strz), "Your gender is now set to: %s.",params);
    SetPVarString(playerid,"Gender",params);
    SendClientMessage(playerid, blue, strz);
    return 1;
}
Reply
#6

Quote:
Originally Posted by [FU]Victious
Посмотреть сообщение
pawn Код:
COMMAND:gender(playerid,params[])
{
    if(!sscanf(params)) return SendClientMessage(playerid,-1,"You need to select a gender!");
    new strz[38];
    format(strz,sizeof(strz), "Your gender is now set to: %s.",params);
    SetPVarString(playerid,"Gender",params);
    SendClientMessage(playerid, blue, strz);
    return 1;
}
Hmm, By looking at that I'm guessing
if(!sscanf(params)) return SendClientMessage(playerid,-1,"You need to select a gender!");
Is checking if theres no value
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)