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



removed - TracerX - 13.07.2016

removed


Re: Dialog Response - Stinged - 13.07.2016

Are you using sscanf in your script?
If you are, use this:
Код:
new weaponid;
if (sscanf(inputtext, "i", weaponid)) return // Inputtext is not a number
And then use weaponid instead of strval(inputtext).

Also, you shouldn't use functions that much in an if statement. Use switch instead:
Код:
switch (weaponid)
{
    case 0..5: // If weaponid = 0 or 1 or 2 to 5
    {

    }
}
If you aren't using sscanf, search for a function called "IsNumeric" to check if it's an actual number.


Re: Dialog Response - Sjn - 13.07.2016

Wouldn't doing new weaponid = strval(inputtext); just work fine? I've been doing this directly and have no issues. Though, sscanf could be a better choice.


Re: Dialog Response - Konstantinos - 13.07.2016

Quote:
Originally Posted by Sjn
Посмотреть сообщение
Wouldn't doing new weaponid = strval(inputtext); just work fine? I've been doing this directly and have no issues. Though, sscanf could be a better choice.
strval will return 0 if the text doesn't contain only numbers. Checking if the index 0 and 1 are equal to '0' and '\0' respectively is not something people would do and sscanf is really much easier to use.


Re: Dialog Response - Sjn - 13.07.2016

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
strval will return 0 if the text doesn't contain only numbers. Checking if the index 0 and 1 are equal to '0' and '\0' respectively is not something people would do and sscanf is really much easier to use.
Oh, never knew this. Something new I got to know today, might as well change mine also.


Re: Dialog Response - NaS - 13.07.2016

strval is also unsecure if you use it on user-input without further checks.
If the input contains a very large number or is too long (no matter what it contains) it will or might crash the server, so at least check for the length first.

Or just use sscanf as already suggested.