Toto je môj kód v Pawn scriptovacioum jazyku pre SAMP. stock CheckForMentions(message[],…
- User
Toto je môj kód v Pawn scriptovacioum jazyku pre SAMP. stock CheckForMentions(message[], mentionColor, result[]) { new id, buffer[4], mention[MAX_PLAYER_NAME + 16]; new index = -1;
while ((index = strfind(message, "#", index + 1)) != -1 || (index = strfind(message, "@", index + 1)) != -1) { if (message[index + 1] > 47 && message[index + 1] < 58) { new j = index + 1; while (message[j] > 47 && message[j] < 58) j++; strmid(buffer, message, index + 1, j); id = strval(buffer); if (IsPlayerConnected(id) && !IsPlayerNPC(id)) { strdel(message, index, j); format(mention, sizeof(mention), "{%06x}%s{%06x}", GetPlayerColor(id) >>> 8, PlayerName(id), mentionColor >>> 8); strins(message, mention, index, strlen(mention)); index += strlen(mention) - 1; // Adjust index after insertion } } } strcpy(result, message, MAX_CHATLINE_LENGTH * 2); return result;} mám problem v riadku 98: while ((index = strfind(message, "#", index + 1)) != -1 || (index = strfind(message, "@", index + 1)) != -1) {, kde mi to hádže tieto warningy, ako ich vyriešim? scripts/core/player/chat.pwn(98) : warning 213: tag mismatch scripts/core/player/chat.pwn(98) : warning 213: tag mismatch
- Assistant
Váš problém môže byť spôsobený nesprávnymi typmi argumentov posielaných do funkcie
strfind. Podľa toho, ako je uvedené v warningoch, súhlasia typy (tagy) zmienok vo vašom kóde.Skúste zmeniť riadok 98 na:
while ((index = strfind(message, _("#"), index + 1)) != -1 || (index = strfind(message, _(@"), index + 1)) != -1) {Použitím funkcie _() získate jednoznakové zreteazce z týchto znakov a tieto typy potom budú zodpovedať očakávaným typom pre parametrov strfind.
- User
tento kód, robí mentions hráčov, čiže @ID hrača alebo #ID hráča vypíše miesto toho meno hráča s tým ID, ale ako si môžeš všimnúť, tak to platí len pre prvý znak z týchto dvoch, vieš to spraviť na všetky znaky (#, @) v celom stringu? stock CheckForMentions(message[], mentionColor, result[]) {
if (strfind(message, "#") == -1 && strfind(message, "@") == -1) { strcpy(result, message, MAX_CHATLINE_LENGTH * 2); return result; } new id, buffer[4], mention[MAX_PLAYER_NAME + 16]; new index = (strfind(message, "#") != -1) ? (strfind(message, "#")) : (strfind(message, "@")); if (message[index + 1] > 47 && message[index + 1] < 58) { new j = index + 1; while (message[j] > 47 && message[j] < 58) j++; strmid(buffer, message, index + 1, j); id = strval(buffer); if (IsPlayerConnected(id) && !IsPlayerNPC(id)) { strdel(message, index, j); format(mention, sizeof(mention), "{%06x}%s{%06x}", GetPlayerColor(id) >>> 8, PlayerName(id), mentionColor >>> 8); strins(message, mention, index, strlen(mention)); } } strcpy(result, message, MAX_CHATLINE_LENGTH * 2); return result;}
- Assistant
Váš problém pochádza z toho, že spracovávate iba jeden výskyt symbolu "@" alebo "#" v správe. Pre spracovanie všetkých výskytov znakov "@" a "#" vo vstupnom texte, musíte použiť cyklus, ktorý nájde a spracuje všetky znaky v danej správe. Tu je váš upravený kód:
stock CheckForMentions(message[], mentionColor, result[]) { strcpy(result, message, MAX_CHATLINE_LENGTH * 2); new id, buffer[4], mention[MAX_PLAYER_NAME + 16], index = 0; while (index != -1) { index = (index != -1 && strfind(result, "@", index) <= strfind(result, "#", index)) ? (strfind(result, "@", index)) : (strfind(result, "#", index)); if(index == -1) break; if (result[index + 1] > 47 && result[index + 1] < 58) { new j = index + 1; while (result[j] > 47 && result[j] < 58) j++; strmid(buffer, result, index + 1, j); id = strval(buffer); if (IsPlayerConnected(id) && !IsPlayerNPC(id)) { strdel(result, index, j); format(mention, sizeof(mention), "{%06x}%s{%06x}", GetPlayerColor(id) >>> 8, PlayerName(id), mentionColor >>> 8); strins(result, mention, index, strlen(mention)); } } } return result; }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.