SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 19/06/2019, 02:14 AM   #1
nbx2000
Big Clucker
 
Join Date: Dec 2016
Posts: 153
Reputation: 5
Default question

how can I modify to be able to choose 2 options SELECTION 1 OR 2 In only commands
CMD:admin(playerid,params[]) {
#pragma unused params
if(PlayerInfo[playerid][admin] >= 1){
SetPlayerSkin(playerid, 287);
}
else {
SendClientMessage(playerid,red,"ERROR: You need to be [A] Member to use this command");
}
return 1;
}
nbx2000 is offline   Reply With Quote
Old 19/06/2019, 02:36 AM   #2
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,202
Reputation: 390
Default Re: question

Maybe you can put the 'params' to use?

Or use a dialog.

Either could work, but i do wanna let you know of 2 things that are making your code look like absolute shit.

1- Indentation, read this post please: https://forum.sa-mp.com/showthread.php?t=256961

2- The use of #pragma

Now if you're not using the second parameter why put it in the first place then tell your compiler to ignore it??

This is what your command SHOULD look
pawn Code:
CMD:admin(playerid)
{
    if(PlayerInfo[playerid][admin] >= 1)
    {
        SetPlayerSkin(playerid, 287);
    }
   
    else
    {
        SendClientMessage(playerid,red,"ERROR: You need to be [A] Member to use this command");
    }
    return 1;
}

Now, back to the point, to make it give you an 'option' to choose skins, you can either show a dialog, read about it here: https://wiki.sa-mp.com/wiki/ShowPlayerDialog

Or use a parameter and combine it with the use of sscanf, like so:
pawn Code:
CMD:admin(playerid, params[])
{
    new skinID;//The variable we will assign the parameter value to we will use
   
    //Using sscanf to take the parameter entered and we use the specifier 'i' because its going to be an integer.
   
    if(sscanf(params, "i", skinID)) return SendClientMessage(playerid, -1, "Please specify the skin number (1 or 2) that you want!");
    //The above just checks if the player only typed /admin without a number afterwards, so you need to type either /admin 1 or /admin 2 to choose a skin
   
    if(skinID != 1 && skinID != 2) return SendClientMessage(playerid, -1, "Please choose either 1 or 2 to get a skin!");
    //The above makes sure the player entered either 1 or 2 after admin to choose a skin
   
    if(PlayerInfo[playerid][admin] >= 1)    
    { //If the player is an admin
        if(skinID == 1)
            SetPlayerSkin(playerid, 287);//If the player typed /admin 1 give them skin id 287
           
        else if(skinID == 2)
            SetPlayerSkin(playerid, 311);//If the player typed /admin 2 give them skin id 311
    }
   
    else
    {//If the player isn't an admin
        SendClientMessage(playerid,red,"ERROR: You need to be [A] Member to use this command");
    }
    return 1;
}

Reminder: YOU WILL NEED TO INCLUDE BOTH THE SSCANF INCLUDE AND PLUGIN TO USE THE EXAMPLE ABOVE!
__________________
Quote:
Originally Posted by Andy
I offer paid scripting services, I can do anything except mapping because fuck mapping.

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link
RogueDrifter is offline   Reply With Quote
Old 19/06/2019, 02:42 AM   #3
nbx2000
Big Clucker
 
Join Date: Dec 2016
Posts: 153
Reputation: 5
Default Re: question

I have the old sscanff will it work?
stock sscanf(string[], format[], {Float,_}:...)
{
#if defined isnull
if (isnull(string))
#else
if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
#endif
{
return format[0];
}
#pragma tabsize 4
new
formatPos = 0,
stringPos = 0,
paramPos = 2,
paramCount = numargs(),
delim = ' ';
while (string[stringPos] && string[stringPos] <= ' ')
{
stringPos++;
}
while (paramPos < paramCount && string[stringPos])
{
switch (format[formatPos++])
{
case '\0':
{
return 0;
}
case 'i', 'd':
{
new
neg = 1,
num = 0,
ch = string[stringPos];
if (ch == '-')
{
neg = -1;
ch = string[++stringPos];
}
do
{
stringPos++;
if ('0' <= ch <= '9')
{
num = (num * 10) + (ch - '0');
}
else
{
return -1;
}
}
while ((ch = string[stringPos]) > ' ' && ch != delim);
setarg(paramPos, 0, num * neg);
}
case 'h', 'x':
{
new
num = 0,
ch = string[stringPos];
do
{
stringPos++;
switch (ch)
{
case 'x', 'X':
{
num = 0;
continue;
}
case '0' .. '9':
{
num = (num << 4) | (ch - '0');
}
case 'a' .. 'f':
{
num = (num << 4) | (ch - ('a' - 10));
}
case 'A' .. 'F':
{
num = (num << 4) | (ch - ('A' - 10));
}
default:
{
return -1;
}
}
}
while ((ch = string[stringPos]) > ' ' && ch != delim);
setarg(paramPos, 0, num);
}
case 'c':
{
setarg(paramPos, 0, string[stringPos++]);
}
case 'f':
{

new changestr[16], changepos = 0, strpos = stringPos;
while(changepos < 16 && string[strpos] && string[strpos] != delim)
{
changestr[changepos++] = string[strpos++];
}
changestr[changepos] = '\0';
setarg(paramPos,0,_:floatstr(changestr));
}
case 'p':
{
delim = format[formatPos++];
continue;
}
case '\'':
{
new
end = formatPos - 1,
ch;
while ((ch = format[++end]) && ch != '\'') {}
if (!ch)
{
return -1;
}
format[end] = '\0';
if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
{
if (format[end + 1])
{
return -1;
}
return 0;
}
format[end] = '\'';
stringPos = ch + (end - formatPos);
formatPos = end + 1;
}
case 'u':
{
new
end = stringPos - 1,
id = 0,
bool:num = true,
ch;
while ((ch = string[++end]) && ch != delim)
{
if (num)
{
if ('0' <= ch <= '9')
{
id = (id * 10) + (ch - '0');
}
else
{
num = false;
}
}
}
if (num && IsPlayerConnected(id))
{
setarg(paramPos, 0, id);
}
else
{
#if !defined foreach
#define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
#define __SSCANF_FOREACH__
#endif
string[end] = '\0';
num = false;
new
name[MAX_PLAYER_NAME];
id = end - stringPos;
foreach (Player, playerid)
{
GetPlayerName(playerid, name, sizeof (name));
if (!strcmp(name, string[stringPos], true, id))
{
setarg(paramPos, 0, playerid);
num = true;
break;
}
}
if (!num)
{
setarg(paramPos, 0, INVALID_PLAYER_ID);
}
string[end] = ch;
#if defined __SSCANF_FOREACH__
#undef foreach
#undef __SSCANF_FOREACH__
#endif
}
stringPos = end;
}
case 's', 'z':
{
new
i = 0,
ch;
if (format[formatPos])
{
while ((ch = string[stringPos++]) && ch != delim)
{
setarg(paramPos, i++, ch);
}
if (!i)
{
return -1;
}
}
else
{
while ((ch = string[stringPos++]))
{
setarg(paramPos, i++, ch);
}
}
stringPos--;
setarg(paramPos, i, '\0');
}
default:
{
continue;
}
}
while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
{
stringPos++;
}
while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
{
stringPos++;
}
paramPos++;
}
do
{
if ((delim = format[formatPos++]) > ' ')
{
if (delim == '\'')
{
while ((delim = format[formatPos++]) && delim != '\'') {}
}
else if (delim != 'z')
{
return delim;
}
}
}
while (delim > ' ');
return 0;
}
nbx2000 is offline   Reply With Quote
Old 19/06/2019, 02:45 AM   #4
RogueDrifter
High-roller
 
RogueDrifter's Avatar
 
Join Date: Dec 2017
Location: SA-MP Drifting world.
Posts: 1,202
Reputation: 390
Default Re: question

I have no idea what the fuck that is, use this https://github.com/maddinat0r/sscanf/releases

Also read what i said, indentation and proper use of variables.

Keeping yourself in the ignorance shell and not choosing to learn will lead you to NOWHERE
__________________
Quote:
Originally Posted by Andy
I offer paid scripting services, I can do anything except mapping because fuck mapping.

[Github]:Link [Gists]:Link [Forum]:Link [Server]:Link [Discord]:Link
RogueDrifter is offline   Reply With Quote
Reply

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
[QUESTION] Kind a team based question Dirkon Scripting Help 1 24/03/2013 08:05 PM
[QUESTION/HELP] DCMD Question Larsey123IsMe Help Archive 23 18/01/2011 04:30 PM
Question regarding playerid (noob question!) Mattjones17 Help Archive 5 27/10/2010 04:21 PM
Data type question.. (and mac address question) DarrenReeder Help Archive 2 21/10/2010 08:20 PM
Hello all i got one question (very easy to answer J.I.C question) SAMPfan109 General 0 06/03/2010 04:43 PM


All times are GMT. The time now is 09:11 AM.


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