SA-MP Forums Archive
String problem - 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: String problem (/showthread.php?tid=510032)



String problem - Xenforox - 29.04.2014

Alright, so i've been trying to script this: when a player do /ad, a dialog( Dialog_style_input) appear and the player types in his ad then it would SendClientMessageToAll, i've been looking around the forums but can't find something similar.


Re: String problem - vassilis - 29.04.2014

don't use /ad with dialog it is annoying just use /ad [text]
if you want it like i stated this is the way:
pawn Code:
CMD:ad(playerid,params[])
{
    new text,string[160],gname[MAX_PLAYER_NAME];
    GetPlayerName(playerid,gname,sizeof(gname));
    if(sscanf(params,"s[50]"text)) return SendClientMessage(playerid,-1, "(ERROR): /ad [ text ] " );
    format(string,sizeof(string),"ADVERTISEMENT[ %s ]: %s",gname,text);
    SendClientMessageToAll(COLORHERE,string);
    return 1;
}



Re: String problem - Konstantinos - 29.04.2014

In your /ad command, show the dialog. Look at the 2nd example that uses DIALOG_STYLE_INPUT from the first link.

Then in OnDialogResponse callback, check if the dialogid is same as the dialog ID you used in your dialog and if the response is 1. The only left now is to format a message with the player's name and pass the inputtext as argument and then send that format message to all.

https://sampwiki.blast.hk/wiki/ShowPlayerDialog
https://sampwiki.blast.hk/wiki/OnDialogResponse
https://sampwiki.blast.hk/wiki/GetPlayerName
https://sampwiki.blast.hk/wiki/Format
https://sampwiki.blast.hk/wiki/SendClientMessageToAll


Re: String problem - Xenforox - 29.04.2014

PHP Code:
new string[256];
             
format(stringsizeof(string),"[ADVERTISMENT]:%s"inputtext);
             
SendClientMessageToAll(0x00F250FFstring); 
I've made this but it returns to nothing. After i insert the text in the dialog, nothing appear.


Re: String problem - Konstantinos - 29.04.2014

Post the part you use the above code in OnDialogResponse and the line you use ShowPlayerDialog (so we can make sure the dialog IDs do match).

By the way, change the size of the string to 144 since that's the max lenght of a client message.


Re: String problem - Xenforox - 29.04.2014

PHP Code:
//Under the CMD
ShowPlayerDialog(playerid,1DIALOG_STYLE_INPUT"Advertisment""Please enter your Advertisment:""Enter""Cancel");
//Under OnDialog Responce
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == 1)
    {
             new 
string[256];
             
format(stringsizeof(string),"[ADVERTISMENT]:%s"inputtext);
             
SendClientMessageToAll(0x00F250FFstring);
    }
    return 
1;




Re: String problem - Konstantinos - 29.04.2014

You should always return 0 at the end of the OnDialogResponse callback so it will allow the callback to be called in other scripts too. Use some other number for the dialogid - a bit longer such as 312 so it won't confict with any other. A suggestion too: switch is faster and better in case you add more dialogs.

pawn Code:
//Under the CMD
ShowPlayerDialog(playerid, 312, DIALOG_STYLE_INPUT, "Advertisment", "Please enter your Advertisment:", "Enter", "Cancel");

//Under OnDialog Responce
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch (dialogid)
    {
        case 312:
        {
            if (response)
            {
                new string[144];
                format(string, sizeof(string),"[ADVERTISMENT]:%s", inputtext);
                SendClientMessageToAll(0x00F250FF, string);
            }
        }
    }
    return 0;
}