problem with strins
#1

Hello, a friend passed me a script using strins but when executing it in the console it shows an error "[debug] Run time error 10:" Native function failed "", can you help me?
HTML Code:
new 
    szMessage[256] = "Hello @Player, how are you today?",
    szMentionColor[] = "{FF0000}"
;
for (new i = 0, j = sizeof(szMessage); i != j; ++i)
{
  if (szMessage[i] == '@')
  {
    new iColorEndPos;
    for (new x = i; x != j; ++x)
    { 
      if (szMessage[x] == ' ' || szMessage[x] == ',')
      {
        iColorEndPos = x;
      }
      else if (x == j - 1)
      {
        iColorEndPos = j;
      }
    }
    strins(szMessage, szMentionColor, i, 256); // 256 = sizeof (szMessage)
    strins(szMessage, "{FFFFFF}", iColorEndPos + 8, 256); // 256 = sizeof (szMessage), iColorEndPos + 8 = iColorEndPos + sizeof ("{FFFFFF}")
  }
}
Reply
#2

can u show us a whole log?
Reply
#3

Quote:
Originally Posted by Mugala
View Post
can u show us a whole log?
Code:
[12:11:28] [debug] Run time error 10: "Native function failed"
[12:11:28] [debug]  strins
[12:11:28] [debug] AMX backtrace:
[12:11:28] [debug] #0 000798dc in public pc_cmd_doubt (playerid=0, params[]=@00f74bc8 "@Hello") at C:\Users\AUK\Desktop\Samp\gamemodes\GM.pwn:6864
Line 6864
Code:
strins(message, "{FFFFFF}", iColorEndPos + 8, sizeof(message));
CMD
Code:
CMD:doubt(playerid, params[])
{
	new message[128];
	if(sscanf(params, "s[128]", message)) return SendClientMessage(playerid, -1, "Usage: {C4FF66}/doubt {FFFFFF}[DOUBT]");

	new szMentionColor[] = "{FF0000}";
	for (new i = 0, j = sizeof(message); i != j; ++i)
	{
	  if (message[i] == '@')
	  {
	    new iColorEndPos;
	    for (new x = i; x != j; ++x)
	    { 
	      if (message[x] == ' ' || message[x] == ',')
	      {
	        iColorEndPos = x;
	      }
	      else if (x == j - 1)
	      {
	        iColorEndPos = j;
	      }
	    }
	    strins(message, szMentionColor, i, sizeof(message));
	    strins(message, "{FFFFFF}", iColorEndPos + 8, sizeof(message));
	  }
	}

	new str[145], pName[MAX_PLAYER_NAME+1];
	GetPlayerName(playerid, pName, MAX_PLAYER_NAME);
	format(str, 145, "{187298}[Doudt] {FFFFFF}Player %s: %s", pName, message);

	for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++)
	{
		if(IsPlayerConnected(i))
		{
			SendClientMessage(i, 0xFFFFFFFFF, str);
		}
	}
	return 1;
}
Reply
#4

You're placing the hex code in before your @ character. So when it hits the @, it adds the hex code before, sending the @ further down the string, so then it comes across it again over and over.

I think you need to either put your color code after the @, or be sure to increase your index variable (i) by +8 to skip over it.
Reply
#5

Quote:
Originally Posted by Joe Staff
View Post
You're placing the hex code in before your @ character. So when it hits the @, it adds the hex code before, sending the @ further down the string, so then it comes across it again over and over.

I think you need to either put your color code after the @, or be sure to increase your index variable (i) by +8 to skip over it.
as? explain or show me
Reply


Forum Jump:


Users browsing this thread: