SA-MP Forums Archive
Problem with OnDialogResponse and (%) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Problem with OnDialogResponse and (%) (/showthread.php?tid=659333)



Problem with OnDialogResponse and (%) - RedGun2015 - 30.09.2018

So, all my gamemode (75%) is modular, every system (almost every system) has his include.
The problem is with hook.

I have a report system (/report - > then I show a dialog and then he need to select 'Report with message')

Then when he write '%s' in the dialog, the server crash (I know i can do that:
Код:
if(strfind(inputtext, "%", true) != -1)  {
        SCM(playerid, -1, "Don't use %%!");
        return 1;
    }
but I already have that in public OnDialogResponse, should I put that code before all OnDialogResponse that i hooked??

EDIT: hook OnDialogResponse is below the public OnDialogResponse...


Re: Problem with OnDialogResponse and (%) - RedGun2015 - 01.10.2018

bump


Re: Problem with OnDialogResponse and (%) - v1k1nG - 01.10.2018

You probably need to post your code to get any help


Re: Problem with OnDialogResponse and (%) - RedGun2015 - 01.10.2018

Quote:
Originally Posted by v1k1nG
Посмотреть сообщение
You probably need to post your code to get any help
Here is the code:

pawn Код:
// in main gamemode
// gamemode.pwn

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
        if(strfind(inputtext, "%", true) != -1)  {
                   SCM(playerid, -1, "Don't use %%!");
                   ShowPlayerDialog(playerid, dialogid, DIALOG_STYLE_INPUT, "Invalid characthers", "Write without restricted characthers", "Continue", "Exit");
                   return 1;
        }
        return 1;
}


// in reports include:
// reports.inc


YCMD:reports(playerid, params[], help)
{

   ShowPlayerDialog(playerid, DIALOG_REPORT_ID, DIALOG_STYLE_LIST, "Choose", "Report with message\nOther", "Select", "Exit");
   return 1;
}

hook OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
        if(dialogid == DIALOG_REPORT_ID) {
               ShowPlayerDialog(playerid, DIALOG_REPORT_ID2, DIALOG_STYLE_INPUT, "Write", "Report message:", "Send", "Cancel");
        }

         if(dialogid == DIALOG_REPORT_ID2)
        {

              format(Report[playerid][reportText], 200, "%s", inputtext);
              SCM(playerid, -1, "Report subbmited!");

             format(gString, sizeof gString, "%s [%d] sended a report with message: %s", GetName(playerid), playerid, inputtext);
             foreach(new i : Admins) SendClientMessage(i, COLOR_RED, gString);


        }
        return 1;
}



Re: Problem with OnDialogResponse and (%) - KinderClans - 01.10.2018

TIP: If you don't wanna use hooks, in your main gamemode do in this way:

pawn Код:
#include "/Custom/system.pwn"
Place your callbacks in your system.pwn, then use them normally in your gamemode.

DON'T compile the system.pwn, just save it in your /gamemodes/Custom folder (or the name you choose).

Also be sure to not include normal callbacks already existent in your main script. (Such as OnPlayerDeath, OnPlayerSpawn etc. etc.)

I use this system to insert custom maps. I do like:

pawn Код:
CreateCustomMap()
{
//Code
}
then in my gm i only add: CreateCustomMap();

Useful if you have a lot of stocks and general publics/functions made by you.


Re: Problem with OnDialogResponse and (%) - v1k1nG - 01.10.2018

Yes put that
Код:
if(strfind(inputtext, "%", true) != -1)  {
        SCM(playerid, -1, "Don't use %%!");
        return 1;
    }
At first lines under OnDialogRes. Also try returning 0 instead of 1, not sure if that'll work tho. Anyways if you have crashdetect plugin you can check its log too.


Re: Problem with OnDialogResponse and (%) - Banditul18 - 01.10.2018

Or take a look at the easyDialog include and see its transform the % into a #


Re: Problem with OnDialogResponse and (%) - d3Pedro - 01.10.2018

Quote:
Originally Posted by RedGun2015
Посмотреть сообщение
So, all my gamemode (75%) is modular, every system (almost every system) has his include.
The problem is with hook.

I have a report system (/report - > then I show a dialog and then he need to select 'Report with message')

Then when he write '%s' in the dialog, the server crash (I know i can do that:
Код:
if(strfind(inputtext, "%", true) != -1)  {
        SCM(playerid, -1, "Don't use %%!");
        return 1;
    }
but I already have that in public OnDialogResponse, should I put that code before all OnDialogResponse that i hooked??

EDIT: hook OnDialogResponse is below the public OnDialogResponse...
PHP код:
    for(new 0strlen(inputtext); l++)
    {
        if(
inputtext[i] == '%') { the rest of the code here }
    } 
EDIT:
Or you can just replace it instead of sending a client message.
PHP код:
    for(new 0strlen(inputtext); l++)
    {
        if(
inputtext[i] == '%')  inputtext[i] = '#';
    }