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



Dialog problem - NealPeteros - 24.11.2017

I'm kinda in trouble with my dialog right now

Код:
if(dialogid == 2211)
	{
		if(response)
		{
			new moneys = strval(inputtext);
		    //debug
			new string[40];
			format(string, 40, "%i", (0 - moneys));
			ERROR(playerid, string);
			//end of debug
   			if(moneys > GetPlayerMoney(playerid))
			{
   			 	GivePlayerMoney(playerid, (0 - moneys));
			}
			else return ERROR(playerid, "You don't have enough money");
		}
		else
		{
		    ShowActionTD(playerid);
		}
		return 1;
	}
It doesn't do anything, not even the debug. Am I doing something wrong?


Re: Dialog problem - Juvanii - 24.11.2017

Make sure that dialogid 2211 is the dialog which shown to the player.


Re: Dialog problem - NealPeteros - 24.11.2017

Well, the dialog id is of no problem. The dialog shows up. What I'm worried about is the result. It's what's not coming out.


Re: Dialog problem - thefirestate - 24.11.2017

Can you show the ShowPlayerDialog of the id 2211?


Re: Dialog problem - NealPeteros - 24.11.2017

Full code:

Код:
public OnPlayerClickTextDraw(playerid, Text:clickedid)
{
	if(clickedid == ActionChoice[3])
	{
		ShowPlayerDialog(playerid, 2211, DIALOG_STYLE_INPUT, "Give Cash", "Input the amount of cash to give.", "Select", "Back");
		HideActionTD(playerid);
		return 1;
	}
        return 0;
}


public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	if(dialogid == 2211)
	{
		if(response)
		{
			new moneys = strval(inputtext);
		    //debug
			new string[40];
			format(string, 40, "%i", (0 - moneys));
			ERROR(playerid, string);
			//end of debug
   			if(moneys > GetPlayerMoney(playerid))
			{
   			 	GivePlayerMoney(playerid, (0 - moneys));
			}
			else return ERROR(playerid, "You don't have enough money");
		}
		else
		{
		    ShowActionTD(playerid);
		}
		return 1;
	}
	return 0;
}

stock ERROR(playerid,msg[])
{
	new error[128];
	format(error,128,"{FF0000}[ERROR]:{FFFFFF} %s",msg);
	return SendClientMessage(playerid,-1,error);
}
Bit suspicious on
Код:
if(moneys > GetPlayerMoney(playerid))
Should the operation be > or <?


Re: Dialog problem - RedFusion - 24.11.2017

Why do you use (0 - moneys)?
-moneys would do the same thing - invert the value - and look better.


Should the operation be > or <?
If you want the player's money to be greater than "moneys" then it should be

GetPlayerMoney(playerid) > moneys
OR
moneys < GetPlayerMoney(playerid)


Re: Dialog problem - NealPeteros - 24.11.2017

I'm using this as a filterscript. Should the return value of OnDialogResponse in my main gamemode and filterscript be 0 or 1?


Re: Dialog problem - RedFusion - 24.11.2017

Always return 0 in the end of it to make sure it gets called in your filterscripts and gamemode too.
This is probably the reason why nothing's happening.
Make sure to do it like this in all of your filterscripts especially.

Example:
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
    if(dialogid == dialognameid1) {
        return 1; return 1 here to stop calling this callback in other scripts.
    }
    if(dialogid == dialognameid2) {
        return 1; return 1 here to stop calling this callback in other scripts.
    }
    return 0; // return 0 here to pass it on to other scripts
}
Quote:

Returning 0 in this callback will pass the dialog to another script in case no matching code were found in your gamemode's callback.

It is always called first in filterscripts so returning 1 there blocks other filterscripts from seeing it.

https://sampwiki.blast.hk/wiki/OnDialogResponse


Re: Dialog problem - NealPeteros - 24.11.2017

So, I tried debugging the OnDialogResponse code through prints. At first, they didn't show. So I tried print on a cmd, and when I used that cmd, the print worked fine. The problem could only be that OnDialogResponse isn't called.

I roamed around my main gamemode and other filterscripts I'm using, and they're return values on the callback is 0.