/try command help
#1

This is my question when the server using the command''/try''nothing happens''/try smoke'' nothing happens D:

Whats the error?


Quote:

if (strcmp(cmd, "/try", true)==0)
{
if(cmdtext[4] == ' ')
{
new plyName[MAX_PLAYER_NAME];
new buffer[255];
new rand = random(20);
new message[256];

strdel(cmdtext, 0, 4);
if(rand >= 10)
{
format(buffer, sizeof(buffer), "* %s intenta %s y lo consigue", plyName, message);
}else
{
format(buffer, sizeof(buffer), "* %s intenta %s pero falla", plyName, message);
}

for(new ply; ply != MAX_PLAYERS; ply++)
{
{
SendClientMessage(ply, 0x00FFFF, buffer);
}
}
}else
{
SendClientMessage(playerid, 0xFF0000FF, "USA: /try [accion]");
}
return 1;
}
Reply
#2

pawn Код:
if (strcmp(cmd, "/try", true)==0)
        {
        new plyName[MAX_PLAYER_NAME];
        new buffer[128];
        new rand = random(2);
        new message[256];
        tmp = strtok(cmdtext, idx);
        new option[128];
        option = strtok(cmdtext, idx);
        if(!strlen(option))
        {
            SendClientMessage(playerid, COLOR_LIGHTYELLOW2, "USA: /try [accion]");
            return 1;
        }
        GetPlayerName(playerid, plyName, sizeof(plyName));
        if(strcmp(option,"smoke",true) == 0)
            {
          if(rand == 2)
            {
                format(buffer, sizeof(buffer), "* %s intenta %s y lo consigue", plyName, message);
       }
            else
            {
            format(buffer, sizeof(buffer), "* %s intenta %s pero falla", plyName, message);
            }
          SendClientMessage(playerid, 0x00FFFF, buffer);
                }
            }
    return 1;
}
Try that, took me a while you had a lot of errors, by default you can use the variable playerid which is the ID that is executing the command, then use the GETPLAYERNAME command to get the players name for the string, go read on the wiki for more info.
Note:Not tested, might not work 100%, if it doesn't work tell me.

What I changed: I changed your random count from 20 to 2, since it has the same effect, just uses less memory,
added GetPlayerName.
You need STRTOK to use this.

I recommend you look through this:
https://sampwiki.blast.hk/wiki/GetPlayerName


- Paladin
Reply
#3

What is STRTOK?

_______________________
Quote:

C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(1175) : error 017: undefined symbol "tmp"

Quote:

if (strcmp(cmd, "/try", true)==0)
{
if(cmdtext[4] == ' ')
{
new plyName[MAX_PLAYER_NAME];
new buffer[255];
new rand = random(2);
new message[256];

strdel(cmdtext, 0, 4);
if(rand >= 10)
{
format(buffer, sizeof(buffer), "* %s intenta %s y lo consigue", plyName, message);
}else
{
format(buffer, sizeof(buffer), "* %s intenta %s pero falla", plyName, message);
}

for(new ply; ply != MAX_PLAYERS; ply++)
{
{
SendClientMessage(ply, 0x00FFFF, buffer);
}
}
}else
{
SendClientMessage(playerid, 0xFF0000FF, "USA: /try [accion]");
}
return 1;
}
Reply
#4

pawn Код:
strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= &#39; '))
    {
        index++;
    }
 
    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > &#39; ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}
Put it at the bottom of your script.

More Info on it at:
https://sampwiki.blast.hk/wiki/Strtok
Reply
#5

pawn Код:
if(!strcmp(cmdtext,"/try",true))
{
  if(cmdtext[idx++]!=32||cmdtext[idx]==EOS) return SendClientMessage(playerid,color,"/try [action]");
  format(string,sizeof(string),"* %s attempts to %s",name,cmdtext[idx]);
  switch(random(2))
  {
    case 0: format(string,sizeof(string),"%s, and succeeds.",string);
    default: format(string,sizeof(string),"%s, but fails.",string);
  }
  SendClientMessageToAll(color,string);
  return 1;
}
Reply
#6

Quote:

C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(1175) : error 017: undefined symbol "tmp"

Reply
#7

Use my code...
Reply
#8

Quote:
Originally Posted by MenaceX^
Use my code...
C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(1145) : warning 217: loose indentation
C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(1147) : error 017: undefined symbol "color"
C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(114 : error 017: undefined symbol "string"
C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(114 : error 017: undefined symbol "string"
C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(114 : error 029: invalid expression, assumed zero
C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(114 : fatal error 107: too many error messages on one line
Reply
#9

Quote:
Originally Posted by pablodc
Quote:
Originally Posted by MenaceX^
Use my code...
C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(1145) : warning 217: loose indentation
C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(1147) : error 017: undefined symbol "color"
C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(114 : error 017: undefined symbol "string"
C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(114 : error 017: undefined symbol "string"
C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(114 : error 029: invalid expression, assumed zero
C:\Users\Pablo\Desktop\Sona GM\gamemodes\Sona.pwn(114 : fatal error 107: too many error messages on one line
I suggest you to learn to script first.
Reply
#10

Im learning
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)