SA-MP Forums Archive
Server crashes while trying to execute command - 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: Server crashes while trying to execute command (/showthread.php?tid=570022)



Server crashes while trying to execute command - Nika1010 - 04.04.2015

Hello, I am new to pawn, so I made a command "/job" and I was getting numerous weird errors, so I set string to "Unemployed" and insert it to SendClientMessage with %s (see examples below) but every time I get in game and type /job, server stops responding, and when I alt tab server is crashed. here is an example from my code.

Here is function for command.
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
	if (strcmp("/job", cmdtext, true, 10) == 0)
	{
		// Do something here
        SendClientMessage(playerid, 0x00FF00FF, "Current job: %s", currentJob);
		return 1;
	}
	return 0;
}
I am not sure what is happening, but I've been struggling to fix this for hours, help would be appreciated .

I get no compiler errors, just two warnings, and one is pretty relevant, and it points to Send Client message thing, it is "warning 202: number of arguments does not match definition".

I am probably making really stupid mistake

oh right, also this is where I declare variable for currentJob:
Код:
new currentJob[30] = "Unemployed";
Just below includes and defines.


Re: Server crashes while trying to execute command - Ritzy2K - 04.04.2015

i dont see any problem above try to remove it and see server crashes anyhow?


Re: Server crashes while trying to execute command - JaydenJason - 04.04.2015

if (strcmp("/job", cmdtext, true, 10) == 0)

I think the problem is there, you set the length to 10 when there's a total length of 4

Try changing 10 to 4 and see if it works

Also try removing [30] from the variable if it still does not work


Re: Server crashes while trying to execute command - Konstantinos - 04.04.2015

pawn Код:
SendClientMessage(playerid, 0x00FF00FF, "Current job: %s", currentJob);
You cannot format a text like that, use format instead: https://sampwiki.blast.hk/wiki/Format


Re: Server crashes while trying to execute command - Nika1010 - 04.04.2015

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
SendClientMessage(playerid, 0x00FF00FF, "Current job: %s", currentJob);
You cannot format a text like that, use format instead: https://sampwiki.blast.hk/wiki/Format
Its little confusing for me xD, can you give me example on how to use it in this occasion? I tried something, but /job had no response, server wasn't crashing though.


Re: Server crashes while trying to execute command - Konstantinos - 04.04.2015

pawn Код:
new szText[50];
format(szText, sizeof (szText), "Current job: %s", currentJob);
SendClientMessage(playerid, 0x00FF00FF, szText);



Re: Server crashes while trying to execute command - JaydenJason - 04.04.2015

Quote:
Originally Posted by Nika1010
Посмотреть сообщение
Its little confusing for me xD, can you give me example on how to use it in this occasion? I tried something, but /job had no response, server wasn't crashing though.
pawn Код:
new string[100];
format(string, sizeof(string), "Your current job is: %s.", currentJob);
SendClientMessage(playerid, -1, string);



Re: Server crashes while trying to execute command - BreakStore - 05.04.2015

Hi,

You can also reduce the value of the index in the string.
You can put 32 instead of 100.
This can make a memory saving.


Re: Server crashes while trying to execute command - Nika1010 - 05.04.2015

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
new szText[50];
format(szText, sizeof (szText), "Current job: %s", currentJob);
SendClientMessage(playerid, 0x00FF00FF, szText);
Quote:
Originally Posted by JaydenJason
Посмотреть сообщение
pawn Код:
new string[100];
format(string, sizeof(string), "Your current job is: %s.", currentJob);
SendClientMessage(playerid, -1, string);
Thank you, it worked.