SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 16/12/2019, 01:50 AM   #1
gui13
Little Clucker
 
Join Date: Jun 2018
Location: Venezuela
Posts: 17
Reputation: 1
Default problem with strins

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}")
  }
}
gui13 is offline   Reply With Quote
Old 16/12/2019, 12:08 PM   #2
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,176
Reputation: 73
Default Re: problem with strins

can u show us a whole log?
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is offline   Reply With Quote
Old 16/12/2019, 04:12 PM   #3
gui13
Little Clucker
 
Join Date: Jun 2018
Location: Venezuela
Posts: 17
Reputation: 1
Default Re: problem with strins

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;
}
gui13 is offline   Reply With Quote
Old 16/12/2019, 04:23 PM   #4
Joe Staff
High-roller
 
Join Date: Aug 2007
Posts: 2,593
Reputation: 379
Default Re: problem with strins

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.
Joe Staff is offline   Reply With Quote
Old 16/12/2019, 05:42 PM   #5
gui13
Little Clucker
 
Join Date: Jun 2018
Location: Venezuela
Posts: 17
Reputation: 1
Default Re: problem with strins

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
gui13 is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use `Strins` Lunoxx Scripting Help 11 17/02/2016 09:27 PM
SQL strins querry problem TwinkiDaBoss Scripting Help 2 12/07/2015 06:17 PM
strins help :( Kapupc Scripting Help 2 05/11/2014 12:48 AM
Problem with STRINS Quickie Scripting Help 4 02/11/2014 05:46 AM
[HELP] strins Kaczmi Scripting Help 0 18/03/2012 11:42 AM


All times are GMT. The time now is 04:47 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.