Color prefix
#1

Hello all!
I have a VIP system on my server and I dont know how to make this

If player types
<red>SA-MP<green>is<blue>the<purple>best
Output:SA-MP is the best

How to make it
Reply
#2

use the str_ireplace function from.the strlib include (on phone, cant open .incs )
https://sampforum.blast.hk/showthread.php?tid=85697
Код:
/*
    str_ireplace:
        Case insensitive string replace

    Arguments:
        sSearch[]    String to search for
        sReplace[]   String to replace with
        sSubject[]   Original string
        (op) &iCount  How many times 'sSearch' has been replaced.

    Returns:
        Replaced string.
*/
native str_ireplace(sSearch[], sReplace[], const sSubject[], &iCount = 0)
Reply
#3

Maybe anyone an example? =)
Reply
#4

With the include above, use this
Код:
if(strfind(text, "<red>", true) != -1) str_replace("<red>", "{FF0000}", text)
under OnPlayerText
Reply
#5

Using strlib and it's fuction str_ireplace you can do this.

Under OnPlayerText callback add this code:
Код:
if(YOUR_VIP_CHECK_HERE)
{
if(strfind(text, "<red>", true) != -1) str_replace("<red>", "{FF0000}", text);
if(strfind(text, "<green>", true) != -1) str_replace("<green>", "{00FF00}", text);
if(strfind(text, "<blue>", true) != -1) str_replace("<blue>", "{0000FF}", text);
if(strfind(text, "<purple>", true) != -1) str_replace("<purple>", "{800080}", text);
}
You can add more codes by yourself.
Credits to JaydenJason.
Reply
#6

Quote:
Originally Posted by Darkwood17
Посмотреть сообщение
Using strlib and it's fuction str_ireplace you can do this.

Under OnPlayerText callback add this code:
Код:
if(YOUR_VIP_CHECK_HERE)
{
if(strfind(text, "<red>", true) != -1) str_replace("<red>", "{FF0000}", text)
if(strfind(text, "<green>", true) != -1) str_replace("<green>", "{00FF00}", text)
if(strfind(text, "<blue>", true) != -1) str_replace("<blue>", "{0000FF}", text)
if(strfind(text, "<purple>", true) != -1) str_replace("<purple>", "{800080}", text)
}
You can add more codes by yourself.
awaiting credits
Reply
#7

Not working!
Reply
#8

This can't be done in the normal chat I believe
Try this, else you have to use dialogs to send colorized messages
Код:
new
sSearch[] = "<red>", "<blue>", "<green>", 
sReplace[] = "{FF0000}", "{0000FF}", "{00FF00}",
sSubject[] = text;

if(strfind(sSubject, sSearch, true) != -1) str_replace(sSearch, sReplace, sSubject);
Reply
#9

It is possible I use it on one of the servers
Reply
#10

I'll have to find a way to do that then, try the code I sent above.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)