SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 16/08/2009, 01:23 PM   #1
introzen
Gangsta
 
introzen's Avatar
 
Join Date: Aug 2008
Posts: 788
Reputation: 34
Default /set [sex] [male/female] Help please...

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 =)
__________________
"No problem can be solved from the same level of consciousness that created it." - Albert Einstein
introzen is offline  
Old 16/08/2009, 04:50 PM   #2
dice7
High-roller
 
Join Date: Apr 2009
Location: Slovenia
Posts: 2,200
Reputation: 22
Default Re: /set [sex] [male/female] Help please...

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"))
dice7 is offline  
Old 16/08/2009, 04:58 PM   #3
Google63
Big Clucker
 
Join Date: Jun 2008
Posts: 113
Reputation: 0
Default Re: /set [sex] [male/female] Help please...

It will be better to use sscanf; it is much more secure & better
Google63 is offline  
Old 16/08/2009, 05:00 PM   #4
introzen
Gangsta
 
introzen's Avatar
 
Join Date: Aug 2008
Posts: 788
Reputation: 34
Default Re: /set [sex] [male/female] Help please...

I didn't think sscanf would work :O

I'll try it... xD
__________________
"No problem can be solved from the same level of consciousness that created it." - Albert Einstein
introzen is offline  
Old 16/08/2009, 05:04 PM   #5
iLinx
High-roller
 
Join Date: Jun 2009
Location: Toronto
Posts: 1,498
Reputation: 157
Default Re: /set [sex] [male/female] Help please...

yea once you go sscanf you never go back ^^
__________________
Servers in Arizona, Virginia, Quebec (Canada), United Kingdom, Netherlands. Over 12,000 served. Free cPanel web hosting is included with ALL servers. ********. *******.
iLinx is offline  
Old 16/08/2009, 05:04 PM   #6
introzen
Gangsta
 
introzen's Avatar
 
Join Date: Aug 2008
Posts: 788
Reputation: 34
Default Re: /set [sex] [male/female] Help please...

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-")
__________________
"No problem can be solved from the same level of consciousness that created it." - Albert Einstein
introzen is offline  
Old 16/08/2009, 05:30 PM   #7
dice7
High-roller
 
Join Date: Apr 2009
Location: Slovenia
Posts: 2,200
Reputation: 22
Default Re: /set [sex] [male/female] Help please...

You declared value as an integer. Declare it as a string and then compare using strcmp
dice7 is offline  
Old 16/08/2009, 05:34 PM   #8
introzen
Gangsta
 
introzen's Avatar
 
Join Date: Aug 2008
Posts: 788
Reputation: 34
Default Re: /set [sex] [male/female] Help please...

Quote:
Originally Posted by dice7
You declared value as an integer. Declare it as a string and then compare using strcmp
__________________
"No problem can be solved from the same level of consciousness that created it." - Albert Einstein
introzen is offline  
Old 16/08/2009, 05:36 PM   #9
Google63
Big Clucker
 
Join Date: Jun 2008
Posts: 113
Reputation: 0
Default Re: /set [sex] [male/female] Help please...

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[]...
Google63 is offline  
Old 16/08/2009, 05:38 PM   #10
dice7
High-roller
 
Join Date: Apr 2009
Location: Slovenia
Posts: 2,200
Reputation: 22
Default Re: /set [sex] [male/female] Help please...

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
dice7 is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hello i have problem with dialog male female and years mata014 Help Archive 0 07/07/2010 02:26 PM


All times are GMT. The time now is 07:26 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.