SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 10/02/2017, 10:29 AM   #1
Ahmed21
Big Clucker
 
Join Date: Jul 2016
Posts: 158
Reputation: 3
Default Strlen and sscanf

Hello everyone,

So, I've made a command, to store text, here's the usage: /addhit [TEXT].

I want to store the text in "hInfo[hintid][hText]", and I want to add a condition "if the text length is more than 'HINT_LEN' then send an error to the player.

I've made it, but unfortunately it's completely bugged, help:

PHP Code:
CMD:addhint(playeridparams[])
{
    if(!
IsPlayerAdmin(playerid)) return 0;

    if(
sscanf(params"s[50]"params)) return SendUsageMSG(playerid"/addhint [TEXT]");
    if(
strlen(params) >= HINT_LEN) return SendErrorMSG(playerid"The text you entered is too long.");

    new 
hintid = -1;
    for(new 
0MAX_HINTSi++)
    {
        if(
hInfo[i][hID] == -1)
        {
            
hintid i;
            break;
        }
    }
    if(
hintid == -1) return SendErrorMSG(playerid"Amount of hints has reached the maximum.");

    
hInfo[hintid][hID] = hintid;
    
hInfo[hintid][hText] = params[50];
    
SendAdminMSG(playerid"Hint has been added.");
    return 
1;

Ahmed21 is offline   Reply With Quote
Old 10/02/2017, 10:51 AM   #2
AmigaBlizzard
Huge Clucker
 
Join Date: Jul 2012
Posts: 319
Reputation: 60
Default Re: Strlen and sscanf

First of all, using sscanf to extract the full text inside params and copy it back into params is quite useless.
Just delete that line as it won't do anything, except check if params is empty.

Replace the sscanf line by
PHP Code:
if (strlen(params) == 0) return SendUsageMSG(playerid"/addhint [TEXT]"); 
For storing the entered text into your enum, use format:
PHP Code:
format(hInfo[hintid][hText], 50params); 
Using "hInfo[hintid][hText] = params[50]", you were only copying the 51st character into your hText variable (or the text starting from the 51st character till the end, which would never be anything because the length of your text is limited by 50 characters.
AmigaBlizzard is offline   Reply With Quote
Old 10/02/2017, 11:10 AM   #3
Ahmed21
Big Clucker
 
Join Date: Jul 2016
Posts: 158
Reputation: 3
Default Re: Strlen and sscanf

Quote:
Originally Posted by AmigaBlizzard View Post
First of all, using sscanf to extract the full text inside params and copy it back into params is quite useless.
Just delete that line as it won't do anything, except check if params is empty.

Replace the sscanf line by
PHP Code:
if (strlen(params) == 0) return SendUsageMSG(playerid"/addhint [TEXT]"); 
For storing the entered text into your enum, use format:
PHP Code:
format(hInfo[hintid][hText], 50params); 
Using "hInfo[hintid][hText] = params[50]", you were only copying the 51st character into your hText variable (or the text starting from the 51st character till the end, which would never be anything because the length of your text is limited by 50 characters.
Worked, thank you so much!
Ahmed21 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
[Ajuda] STRLEN para SSCANF jefrens Português/Portuguese 3 26/11/2015 11:10 PM
Strlen TiXz0r Scripting Help 4 10/05/2015 02:22 PM
Converting strlen to sscanf RedFusion Server Support 2 01/07/2012 11:41 PM
Strlen help? sekol Help Archive 3 30/09/2010 09:54 AM
Strlen O_O SoeH Help Archive 1 19/10/2009 10:08 AM


All times are GMT. The time now is 03:20 PM.


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