←  Gotowe funkcje

AMXX.pl: Support AMX Mod X i SourceMod

»

CS:GO
PrintColorChat (z przejściem do nowych lin...

  • +
  • -
Droso - zdjęcie Droso 26.10.2015

stock PrintColorChat(id, String:string2[192], any:...)
{
    decl String:string[192]
    VFormat(string, 192, string2, 3);
    
    ReplaceString(string, sizeof(string), "{white}", " \x01");
    
    ReplaceString(string, sizeof(string), "{strongred}", " \x02");
    
    ReplaceString(string, sizeof(string), "{purple}", " \x03");
    
    ReplaceString(string, sizeof(string), "{red}", " \x0F");
    
    ReplaceString(string, sizeof(string), "{ct}", " \x0B");
    ReplaceString(string, sizeof(string), "{blue}", " \x0B");    

    ReplaceString(string, sizeof(string), "{darkblue}", " \x0C");
    
    ReplaceString(string, sizeof(string), "{grey}", " \x0A");
    
    ReplaceString(string, sizeof(string), "{green}", " \x04");
    
    ReplaceString(string, sizeof(string), "{yellow}", " \x10");
    
    ReplaceString(string, sizeof(string), "{tt}", " \x09");
    
    
    if(StrContains(string, " ", false) == 0)
    {            
        ReplaceStringEx(string, 192, " ", "", _, _, false);
    }
    
    if(id)
    PrintToChat(id, " \x01%s", string);
    else
    PrintToChatAll(" \x01%s", string);
}


stock PrintColorChat2(id, String:string2[512], any:...)
{
    decl String:string[512]
    VFormat(string, 512, string2, 3);
    
    ReplaceString(string, sizeof(string), "{white}", " \x01");
    
    ReplaceString(string, sizeof(string), "{strongred}", " \x02");
    
    ReplaceString(string, sizeof(string), "{purple}", " \x03");
    
    ReplaceString(string, sizeof(string), "{red}", " \x0F");
    
    ReplaceString(string, sizeof(string), "{blue}", " \x0B");
    ReplaceString(string, sizeof(string), "{ct}", " \x0B");
    
    ReplaceString(string, sizeof(string), "{darkblue}", " \x0C");
    
    ReplaceString(string, sizeof(string), "{grey}", " \x0A");
    
    ReplaceString(string, sizeof(string), "{green}", " \x04");
    
    ReplaceString(string, sizeof(string), "{tt}", " \x09");

    ReplaceString(string, sizeof(string), "{yellow}", " \x10");
    
    if(StrContains(string, " ", false) == 0)
    {            
        ReplaceStringEx(string, 192, " ", "", _, _, false);
    }
    
    
    new String:buffer[10][192];
    ExplodeString(string, "^n", buffer, 10, 192);
    
    for(new i=0; i<10; i++)
    {
        if(strlen(buffer[i]) > 1)
        {
            if(id)
            {
                PrintToChat(id, " \x01%s", buffer[i]);
            }
                else
            {
                PrintToChatAll(" \x01%s", buffer[i]);
            }
        }
    }
}



Okej teraz użycie:

Okej pierwszy parametr to ID. Jeżeli id == 0, wiadomość zostanie wysłana do wszystkich, jeżeli nie to do określonego przez ID gracza.

 

Drugi parametr to tekst. Aby tekst był w kolorze np. czerwonym robimy tak "{red}Tutaj jest tekst czerwony".

Co da nam wynik.

Tutaj jest tekst czerwony

Oczywiście kolory można mieszać, co trzeba wziąć pod uwagę? Każdy kolor {xxx} robi spację!

Więc tekst musi wyglądać tak "tekst{red}tekst2" inaczej miałbyś podwójne spacje :).

 

 

Kolejna sprawa to PrintColorChat2.

Funkcja jest prawie identyczna co PrintColorChat, ale ma wsparcie 'enterów'.

(rozbiłem to na 2 funkcje, żeby to było bardziej optymalne, bo przejście do następnej linii to jakby drukowanie kolejnej wiadomości).

Aby przejść do następnej linii należy użyć ^n

UWAGA: Tekst po ^n traci kolor! Wiec nalezy to robić tak: {red}tekst^n{red}tekst

Co da nam wynik:

tekst

tekst

 

 

Obie funkcje oczywiście wspierają formatowanie tekstu.

Więc używanie %s, %d, %f itd. i dopisywanie zmiennych w 3 parametrze oczywiście działa.

 

 

PS Czekam na pomysły jakby to można było jeszcze zooptymalizować :D

 


Użytkownik Droso edytował ten post 12.03.2016 13:11
Odpowiedz

  • +
  • -
Linux' - zdjęcie Linux' 26.10.2015

Nawet fajnie wymyślone :D

Odpowiedz