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}") } }
[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
strins(message, "{FFFFFF}", iColorEndPos + 8, sizeof(message));
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; }
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. |