Server crashes while trying to execute command
#1

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.
Reply
#2

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

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
Reply
#4

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

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.
Reply
#6

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

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);
Reply
#8

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.
Reply
#9

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)