/try help ASAP
#1

Okay I made a /try command for my FS and it does not let me type a action, Example Luis_Foxx Tries to turn on the Computer but fails

Code;
pawn Code:
if(!strcmp("/try", cmdtext, true, 5))
    {
        new getplayer[128];
        new str[128];
        new str1[128];
        GetPlayerName(playerid, getplayer, sizeof(getplayer));
        format(str, sizeof(str), "%s Tries to: %s and succeeds", getplayer, str[0]);
        format(str1, sizeof(str1), "%s Tries to %s but fails", getplayer, str1[0]);
        switch(random(3))
        {
            case 1:
            {
                SendClientMessage(playerid, COLOR_PURPLE, str);
            }
            case 2:
            {
                SendClientMessage(playerid, COLOR_PURPLE, str1);
            }
        }
        return 1;
    }
Reply
#2

Read about statements here: https://sampwiki.blast.hk/wiki/For

Your switch case is a flaw, try with case 0:,case 1:,case 2:
Reply
#3

The switch should also be Random (1). and the cases 0 and 1.

Also your playername variable "getplayer" is 122 cells too big make it 26 long or use MAX_PLAYER_NAME (both are the same).
Reply
#4

pawn Code:
if(!strcmp("/try", cmdtext, true, 5))
{
    new name[25], string[64];
     GetPlayerName(playerid, name, 25);
      switch(random(3))
       {
        case 0:
         {
             format(string, 64, "%s Tries to: %s and succeeds", name);
              SendClientMessage(playerid, COLOR_PURPLE, string);
          }
           case 2:
           {
               format(string, 64, "%s Tries to %s but fails", name);
            SendClientMessage(playerid, COLOR_PURPLE, str1);
           }
           case 3:
           {
               format(string, 64, "%s Tries to %s but fails", name);
            SendClientMessage(playerid, COLOR_PURPLE, str1);
           }
    }
     return 1;
}
1st- Watch out your string sizes.. max player name is 24+null character = 25.
2nd- Don't use sizeof it uses prossesor..
3nd- You didn't made a case, random 3 has 0, 1 or 2.
Reply
#5

Okay.., It don't let me type an Action? I do /try Test and it says that the command is Unknown?
Reply
#6

Lol i always thought it was max name 26 (i was adamant) hell knows where i got that from
Reply
#7

Quote:
Originally Posted by iggy1
View Post
Lol i always thought it was max name 26 (i was adamant) hell knows where i got that from
I always thought it was 20.. but printf("%d", MAX_PLAYER_NAME); showed me i were wrong..


Quote:
Originally Posted by -Luis
View Post
Okay.., It don't let me type an Action? I do /try Test and it says that the command is Unknown?
Use sscanf
Reply
#8

pawn Code:
if(strcmp("/try", cmdtext, true, 4) == 0)
    {
        if(strlen(cmdtext) == 0) return SendClientMessage(playerid, 0xFFFFFFFF, "Ussage: /try [text]");
        {
            new name[25], string[64];
             GetPlayerName(playerid, name, 25);
               switch(random(3))
             {
                  case 0:
                {
                    format(string, 64, "%s Tries to: %s and succeeds", name, cmdtext);
                    SendClientMessage(playerid, 0xF9B7FFAA, string);
                }
                case 2:
                {
                    format(string, 64, "%s Tries to %s but fails", name, cmdtext);
                    SendClientMessage(playerid, 0xF9B7FFAA, string);
                }
                case 3:
                {
                    format(string, 64, "%s Tries to %s but fails", name, cmdtext);
                    SendClientMessage(playerid, 0xF9B7FFAA, string);
                }
             }
        }
        return 1;
    }
This will work, but only will appear "yourname Tries to /try but fails".. or "yourname Tries to /try and succeeds"

Modify it with sscanf.. or better use zcmd and there is no need of sscanf for this.
Reply
#9

Quote:
Originally Posted by TheCrazyKiller
View Post
just use isnull and zcmd.. no need for sscanf? lol
SScanf makes it easier to script if your not familiar with arrays / splitting strings.
Reply
#10

Again your missing case 1. And random(3) will give 4 cases not 3 (cases 0, 1, 2, 3). If he is comfortable using sscanf there is no problem using that for null checks its not exactly insanely inefficient. Nor is it slow.
Reply
#11

Quote:
Originally Posted by TheCrazyKiller
Посмотреть сообщение
no point.. for a cmd like this..

isnull and zcmd is the fastest way i see it
Actually, it ain't noticeable at all... test yourself, gives the same result's.

Quote:
Originally Posted by iggy1
Посмотреть сообщение
Again your missing case 1. And random(3) will give 4 cases not 3 (cases 0, 1, 2, 3). If he is comfortable using sscanf there is no problem using that for null checks its not exactly insanely inefficient. Nor is it slow.
Like i just mentioned, you wont notice it at all.

pawn Код:
// With SSCANF

new Cmdstring[30] = "imastringok?testingsomeshit";

public OnGameModeInit()
{
    new Tick = GetTickCount();
    new sscanfstring[30];
    sscanf(Cmdstring, "s[30]", sscanfstring);
    switch(random(3))
    {
        case 0: { printf("1"); }
        case 1: { printf("2"); }
        case 2: { printf("3"); }
    }
    printf("%d", GetTickCount()-Tick);
    printf("%s", sscanfstring);
    return 1;
}
pawn Код:
// Without SScanf

new Cmdstring[30] = "imastringok?testingsomeshit";

public OnGameModeInit()
{
    new Tick = GetTickCount();
    switch(random(3))
    {
        case 0: { printf("1"); }
        case 1: { printf("2"); }
        case 2: { printf("3"); }
    }
    printf("%d", GetTickCount()-Tick);
    printf("%s", Cmdstring);
    return 1;
}
pawn Код:
//SScanf 1-1-0
//W/O SScanf 0-1-1
Reply
#12

Quote:
Originally Posted by TheCrazyKiller
Посмотреть сообщение
just use isnull and zcmd.. no need for sscanf? lol
If you know how to do it you don't need SSCANF.

Ugh.. I missed a case..
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)