/set [sex] [male/female] Help please...
#1

Hello everyone =)

I've tried to make a command witch sets the Sex for a person.

/set [sex] [male/female]

I will add more then /set sex soon... it will be like:

/set [sex/age/city]

I want so when you type /set sex, it shows: ".: Usage: /set [sex] [male/female] :."
but when you only type /set, it shows: ".: Usage: /set [sex] :."

Here is the command:

pawn Code:
dcmd_set(playerid,params[])
{
  new pName[MAX_PLAYER_NAME], File[256];
    GetPlayerName(playerid,pName,sizeof(pName));
  format(File,sizeof(File),"CLRP/Players/%s.ini",pName);
  if(params[0] == 0) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] :.");
    if(!strcmp(params[0],"sex"))
    {
      if(params[1] == 0) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] [male/female] :.");
      if(!strcmp(params[1],"male"))
        {
          dini_IntSet(File,"Sex",1);
          PlayerInfo[playerid][pSex] = 1;
            SendClientMessage(playerid,COLOR_GREENLIGHT,".: Info: Gender set to Male :.");
        }
        if(!strcmp(params[1],"female"))
        {
          dini_IntSet(File,"Sex",2);
          PlayerInfo[playerid][pSex] = 2;
            SendClientMessage(playerid,COLOR_GREENLIGHT,".: Info: Gender set to Female :.");
        }
    }
    return 1;
}
Thank you =)
Reply
#2

pawn Code:
if(params[0] == 0) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] :.");
Change this line i guess

Also, from what I'm seeing here, you're comparing a character with a string ? This will never work. Just use sscanf
pawn Code:
if(!strcmp(params[0],"sex"))
Reply
#3

It will be better to use sscanf; it is much more secure & better
Reply
#4

I didn't think sscanf would work :O

I'll try it... xD
Reply
#5

yea once you go sscanf you never go back ^^
Reply
#6

pawn Code:
dcmd_set(playerid,params[])
{
  new pName[MAX_PLAYER_NAME], File[256],thing,value;
    GetPlayerName(playerid,pName,sizeof(pName));
  format(File,sizeof(File),"CLRP/Players/%s.ini",pName);
  if(sscanf(params,"ss",thing,value)) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] :.");
    if(!strcmp(params[0],"sex"))
    {
      if(sscanf(params,"ss",thing,value)) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] [male/female] :.");
      if(value == "male") //2643
        {
          dini_IntSet(File,"Sex",1);
          PlayerInfo[playerid][pSex] = 1;
            SendClientMessage(playerid,COLOR_GREENLIGHT,".: Info: Gender set to Male :.");
        }
        if(value == "female") //2649
        {
          dini_IntSet(File,"Sex",2);
          PlayerInfo[playerid][pSex] = 2;
            SendClientMessage(playerid,COLOR_GREENLIGHT,".: Info: Gender set to Female :.");
        }
    }
    return 1;
}
doesn't work =/

I get those errors:

Code:
C:\Documents and Settings\IntrozeN\Desktop\SAMP\Copy of samp server\gamemodes\CLRP.pwn(2643) : error 033: array must be indexed (variable "-unknown-")
C:\Documents and Settings\IntrozeN\Desktop\SAMP\Copy of samp server\gamemodes\CLRP.pwn(2649) : error 033: array must be indexed (variable "-unknown-")
Reply
#7

You declared value as an integer. Declare it as a string and then compare using strcmp
Reply
#8

Quote:
Originally Posted by dice7
You declared value as an integer. Declare it as a string and then compare using strcmp
Reply
#9

of course people do wrong when they dont know how & what "sscanf" do; processing & SAVING; so you must saved values with what you want; eg: if(!strcmp(thing, "male")) { ... } and not params[]...
Reply
#10

pawn Code:
dcmd_set(playerid,params[])
{
  new pName[MAX_PLAYER_NAME], File[256],thing[3],value[6]; /*thing has 3, because "sex" has 3 chars, value has 6 becase "female" has 6 chars, "male has 4*/
    GetPlayerName(playerid,pName,sizeof(pName));
  format(File,sizeof(File),"CLRP/Players/%s.ini",pName);

  if(sscanf(params,"ss",thing,value)) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] [male/female] :.");

  if(!strcmp(thing, "sex")) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex]

      if(!strcmp(value, "
male"))
      {
          dini_IntSet(File,"
Sex",1);
          PlayerInfo[playerid][pSex] = 1;
            SendClientMessage(playerid,COLOR_GREENLIGHT,"
.: Info: Gender set to Male :.");
      }

      else if(!strcmp(value, "
female")
      {
          dini_IntSet(File,"
Sex",2);
          PlayerInfo[playerid][pSex] = 2;
            SendClientMessage(playerid,COLOR_GREENLIGHT,"
.: Info: Gender set to Female :.");
      }
      else SendClientMessage(playerid,COLOR_GREY,"
.: Usage: /set [sex] [male/female] :.");

    return 1;
}
edited
Reply
#11

Quote:
Originally Posted by dice7
pawn Код:
dcmd_set(playerid,params[])
{
  new pName[MAX_PLAYER_NAME], File[256],thing[3],value[6]; /*thing has 3, because "sex" has 3 chars, value has 6 becase "female" has 6 chars, "male has 4*/
    GetPlayerName(playerid,pName,sizeof(pName));
  format(File,sizeof(File),"CLRP/Players/%s.ini",pName);

  if(sscanf(params,"ss",thing,value)) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] [male/female] :.");

  if(!strcmp(thing, "sex")) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex]

      if(!strcmp(value, "
male"))
      {
          dini_IntSet(File,"
Sex",1);
          PlayerInfo[playerid][pSex] = 1;
            SendClientMessage(playerid,COLOR_GREENLIGHT,"
.: Info: Gender set to Male :.");
      }

      else if(!strcmp(value, "
female")
      {
          dini_IntSet(File,"
Sex",2);
          PlayerInfo[playerid][pSex] = 2;
            SendClientMessage(playerid,COLOR_GREENLIGHT,"
.: Info: Gender set to Female :.");
      }
      else SendClientMessage(playerid,COLOR_GREY,"
.: Usage: /set [sex] [male/female] :.");

    return 1;
}
edited
Thanks man =)

The only thing that is wrong now is:

if I type "/set" it says: "/set [sex]" with is good
but if I type "/set sex" it says: /set [sex] witch is not good...

I want it to say "/set [sex] [male/female] when I type: "/set sex" and "/set [sex]" when I type "/set" :P

How to fix? xD
Reply
#12

Man that is really easy to get if you look;

just replace:
if(!strcmp(thing, "sex")) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex]

with:
if(!strcmp(thing, "sex")) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] [male/female]

man just look a bit before posting; looking at code is a lot faster then posting
Reply
#13

Quote:
Originally Posted by JoeBullet
Man that is really easy to get if you look;

just replace:
if(!strcmp(thing, "sex")) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex]

with:
if(!strcmp(thing, "sex")) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] [male/female]

man just look a bit before posting; looking at code is a lot faster then posting
Still don't work...
Reply
#14

I tried and tried with many thing and shit but finally I ended up like this:

pawn Код:
dcmd_set(playerid,params[])
{
  new pName[MAX_PLAYER_NAME], File[256],thing[3],value[6];
    GetPlayerName(playerid,pName,sizeof(pName));
  format(File,sizeof(File),"CLRP/Players/%s.ini",pName);
  if(params[0] == 0) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] :.");
  if(sscanf(params,"ss",thing,value))
  if(strcmp(thing, "sex")) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] :.");
    if(!strcmp(thing, "sex") && value[0] == 0) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] [male/female] :.");
    if(!strcmp(value, "male"))
    {
        dini_IntSet(File,"Sex",1);
        PlayerInfo[playerid][pSex] = 1;
        SendClientMessage(playerid,COLOR_GREENLIGHT,".: Info: Gender set to Male :.");
    }
    else if(!strcmp(value, "female"))
    {
        dini_IntSet(File,"Sex",2);
    PlayerInfo[playerid][pSex] = 2;
        SendClientMessage(playerid,COLOR_GREENLIGHT,".: Info: Gender set to Female :.");
    }
    else if(strcmp(value, "female") || strcmp(value, "male")) return SendClientMessage(playerid,COLOR_GREY,".: Usage: /set [sex] [male/female] :.");
    return 1;
}
works exactly how I want it xD

Problem Solved, thanks
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)