Bug with printing a string
#1

So here's the thing i made a few commands that format a message written by the player and sends that message around him or to every player on the server but there's a bug where it doesn't send the whole message or cuts it off. It just return unknown command and prints the message at about idk 20 chars but i set the string at 128 chars so i don't know how to fix this if you can help me i would appreciate it

Here's an example command:
pawn Код:
if(strcmp(cmd, "/b", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            GetPlayerName(playerid, sendername, sizeof(sendername));
            new length = strlen(cmdtext);
            while ((idx < length) && (cmdtext[idx] <= ' '))
            {
                idx++;
            }
            new offset = idx;
            new result[64];
            new string[128];
            while ((idx < length) && ((idx - offset) < (sizeof(result) - 1)))
            {
                result[idx - offset] = cmdtext[idx];
                idx++;
            }
            result[idx - offset] = EOS;
            if(!strlen(result))
            {
                SendClientMessage(playerid, COLOR_WHITE, "KORISTI: (/b) [ooc chat]");
                return 1;
            }
            format(string, sizeof(string), "[OOC]%s: (( %s ))", sendername, result);
            ProxDetector(7.0, playerid, string, COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN);
        }
        return 1;
    }
And here's what happens:

http://www.zaslike.com/files/0ezfan40y4um0t0i6ih.png
Reply
#2

Quote:
Originally Posted by ChrisMorasco
Посмотреть сообщение
Hi, i'm still a beginner at scripting
And yet you start with the most difficult script and the most obsolete methods. The length of the output is 64 characters (probably, couldn't be bothered to count), as is specified in that strtok code.

https://sampforum.blast.hk/showthread.php?tid=91354
https://sampforum.blast.hk/showthread.php?tid=120356
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
And yet you start with the most difficult script and the most obsolete methods. The length of the output is 64 characters (probably, couldn't be bothered to count), as is specified in that strtok code.
I know i'm a failure and i don't care if i use difficult scripting methods that's how i learn and if you can help me i will appreciate it.

PS: I don't use ZCMD and i never want to.
Reply
#4

And with that mentality you'll never be a good scripter. There's no point dwelling on the past.
Furthermore, I think it'll be pretty hard to find someone around here to help you with strtok. And neither will I.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
And with that mentality you'll never be a good scripter. There's no point dwelling on the past.
Furthermore, I think it'll be pretty hard to find someone around here to help you with strtok. And neither will I.
Ok, anyone else?
Reply
#6

If you're a beginner you might aswel learn the modern techniques from the start instead of using outdated and very inefficient code (strcmp, strtok).

You'll need the following for this:
- sscanf
- zcmd (or equivalent)

pawn Код:
COMMAND:b(playerid, params[]) {
    new text[128];
    if(sscanf(params, "s[128]", text)) return SendClientMessage(playerid, 0xFF0000, "Usage: /b <message>");
   
    new string[128 + MAX_PLAYER_NAME];
    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
   
    format(string, sizeof(string), "[OOC]%s: (( %s ))", pname, text);
    ProxDetector(7.0, playerid, string, COLOR_LIGHTGREEN, COLOR_LIGHTGREEN, COLOR_LIGHTGREEN, COLOR_LIGHTGREEN, COLOR_LIGHTGREEN);
    return 1;
}
EDIT:
Quote:

PS: I don't use ZCMD and i never want to.

That's like saying you will only use Assembly and refuse to use Java because it's more evolved. With that attitude you will not (read:never) be able to make good scripts.

Scripting is NOT about copying other people's code and adding your text. I can asume that the script you have uses strcmp -- newsflash! strcmp is outdated so either convert it to a better alternative or stop scripting all together. Asking people to improve on your already horrible code and refusing to take perfectly valid modern techniques as the solution just makes us not want to help you again.
Reply
#7

delete
Reply
#8

Quote:
Originally Posted by Sinner
Посмотреть сообщение
If you're a beginner you might aswel learn the modern techniques from the start instead of using outdated and very inefficient code (strcmp, strtok).

You'll need the following for this:
- sscanf
- zcmd (or equivalent)

pawn Код:
COMMAND:b(playerid, params[]) {
    new text[128];
    if(sscanf(params, "s[128]", text)) return SendClientMessage(playerid, 0xFF0000, "Usage: /b <message>");
   
    new string[128 + MAX_PLAYER_NAME];
    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
   
    format(string, sizeof(string), "[OOC]%s: (( %s ))", pname, text);
    ProxDetector(7.0, playerid, string, COLOR_LIGHTGREEN, COLOR_LIGHTGREEN, COLOR_LIGHTGREEN, COLOR_LIGHTGREEN, COLOR_LIGHTGREEN);
    return 1;
}
EDIT:


That's like saying you will only use Assembly and refuse to use Java because it's more evolved. With that attitude you will not (read:never) be able to make good scripts.

Scripting is NOT about copying other people's code and adding your text. I can asume that the script you have uses strcmp -- newsflash! strcmp is outdated so either convert it to a better alternative or stop scripting all together. Asking people to improve on your already horrible code and refusing to take perfectly valid modern techniques as the solution just makes us not want to help you again.
I know that scripting is not about copying other people's code and i do understand that strcmp and strtok are outdated but that's how i learned how to script to where i am. And also i couldn't be bothered converting 7,000 lines of code into zcmd and sscanf that's like starting over for me at 0.
Reply
#9

Quote:
Originally Posted by ChrisMorasco
Посмотреть сообщение
And also i couldn't be bothered converting 7,000 lines of code into zcmd and sscanf that's like starting over for me at 0.
In the time your problem took to be solved you could have converted them all and avoided the problem in the first place. Clearly you don't want to invest any sort of time or effort in your script, let alone making it the least bit efficient since you (likely) took an already existing script and whine about how converting the command would take some time.

As a beginning scripter you shouldn't take rubbish code from someone else and build on it like so many beginners here do. I posted the most efficient solution available and you chose to abandone it for a technique that is likely 99% slower. You really don't deserve to be helped here -- and the only person who posted here who was actually capable of understanding your problem (Vince) apperantly shares my thoughts.
Reply
#10

Quote:
Originally Posted by Sinner
Посмотреть сообщение
In the time your problem took to be solved you could have converted them all and avoided the problem in the first place. Clearly you don't want to invest any sort of time or effort in your script, let alone making it the least bit efficient since you (likely) took an already existing script and whine about how converting the command would take some time.

As a beginning scripter you shouldn't take rubbish code from someone else and build on it like so many beginners here do. I posted the most efficient solution available and you chose to abandone it for a technique that is likely 99% slower. You really don't deserve to be helped here -- and the only person who posted here who was actually capable of understanding your problem (Vince) apperantly shares my thoughts.
LOL. Dude calm down it's just a hobby if you don't want to help me don't spam btw i converted all of them into zcmd and sscanf into a different script and it's pretty fucking stupid to say that i don't care about my scripts if i don't use modern methods example: zcmd, sscanf...
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)