SA-MP Forums Archive
Color prefix - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Color prefix (/showthread.php?tid=576929)



Color prefix - kalanerik99 - 07.06.2015

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


Re: Color prefix - JaydenJason - 07.06.2015

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)



Re: Color prefix - kalanerik99 - 07.06.2015

Maybe anyone an example? =)


Re: Color prefix - JaydenJason - 07.06.2015

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


Re: Color prefix - Darkwood17 - 07.06.2015

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.


Re: Color prefix - JaydenJason - 07.06.2015

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


Re: Color prefix - kalanerik99 - 07.06.2015

Not working!


Re: Color prefix - JaydenJason - 07.06.2015

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);



Re: Color prefix - kalanerik99 - 07.06.2015

It is possible I use it on one of the servers


Re: Color prefix - JaydenJason - 07.06.2015

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