Colour in purple word in **
#1

Hi all, I'm trying to make a function in OnPlayerText where if the player says like 'Hello! *waving his hand*' the 'waving his hand' in purple.
I dunno what function should I use, with strfind the entire Onplayertext stopped working.
Reply
#2

try this:

PHP код:
public OnPlayerText(playeridtext[]) {
    if(
strfind(text"hello"true) != -1strcat(text"{ff8ed7} *Waving his hand*"sizeof(text));
    
    return 
0;

Reply
#3

Quote:
Originally Posted by Vennox
Посмотреть сообщение
try this:

PHP код:
public OnPlayerText(playeridtext[]) {
    if(
strfind(text"hello"true) != -1strcat(text"{ff8ed7} *Waving his hand*"sizeof(text));
    
    return 
0;

Are you serious? Then it will only work with "Hello *waving his hand*" lol??

I believe strfind would work, Learn how to do it from here..
Reply
#4

Quote:
Originally Posted by JasonRiggs
Посмотреть сообщение
Are you serious? Then it will only work with "Hello *waving his hand*" lol??

I believe strfind would work, Learn how to do it from here..
idk what are you trying to say.
look closer at my code, the second time i used strcat, not strfind
Код:
public OnPlayerText(playerid, text[]) {
    if(strfind(text, "hello", true) != -1) strcat(text, "{ff8ed7} *Waving his hand*", sizeof(text));
    
    return 0;
}
if it detects the word "hello" in your phrase (for example: "hello dude"), it will attach "{ff8ed7} *Waving his hand*" to your text.

so when you text "hello dude", your message will be shown as "Player says: hello dude *Waving his hand*"


https://sampwiki.blast.hk/wiki/Strcat
https://sampwiki.blast.hk/wiki/Strfind
Reply
#5

Quote:
Originally Posted by Vennox
Посмотреть сообщение
idk what are you trying to say.
look closer at my code, the second time i used strcat, not strfind
Код:
public OnPlayerText(playerid, text[]) {
    if(strfind(text, "hello", true) != -1) strcat(text, "{ff8ed7} *Waving his hand*", sizeof(text));
    
    return 0;
}
if it detects the word "hello" in your phrase (for example: "hello dude"), it will attach "{ff8ed7} *Waving his hand*" to your text.

so when you text "hello dude", your message will be shown as "Player says: hello dude *Waving his hand*"
https://sampwiki.blast.hk/wiki/Strcat
https://sampwiki.blast.hk/wiki/Strfind

He doesn't want it like that mate, look I'll explain it a bit deeper..

He doesn't want anything from "Hello" or "Waving his hand"

Alllll what he wants to do is to detect a " * STRING HERE * " he wants two stars with text in between, if that was detected, remove the stars and send the string in purple color which is not like the other text, So not just "Hello"

But if -FOR EXAMPLE- I said "Fuck you *shows his middle finger*" I want to send the "Fuck you" in white color, and "shows his middle finger" in purple color but without "*" got it? ALL what you need in it is finding "*" in the player text then omit it and send message to nearby people with color purple(of the text surrounded by stars) easy.
Reply
#6

Quote:
Originally Posted by JasonRiggs
Посмотреть сообщение
He doesn't want it like that mate, look I'll explain it a bit deeper..

He doesn't want anything from "Hello" or "Waving his hand"

Alllll what he wants to do is to detect a " * STRING HERE * " he wants two stars with text in between, if that was detected, remove the stars and send the string in purple color which is not like the other text, So not just "Hello"

But if -FOR EXAMPLE- I said "Fuck you *shows his middle finger*" I want to send the "Fuck you" in white color, and "shows his middle finger" in purple color but without "*" got it? ALL what you need in it is finding "*" in the player text then omit it and send message to nearby people with color purple(of the text surrounded by stars) easy.
ty for explaining.

You can use strreplace from strlib.inc, by Slice: https://sampforum.blast.hk/showthread.php?tid=362764
But the problem is that the variable text[] from OnPlayerText cannot be formated.
So you have to return 0 OnPlayerText and send the message by yourself to the nearby players.
PHP код:
public OnPlayerText(playeridtext[]){
     new 
string[256];
     new 
name[25]; 
     
GetPlayerName(playeridname25);
     
format(string256"%s says: %s"nametext);
     if(
strfind(string"*")) strreplace(string"*""{ff00ff}"false0, -1256);
     for(new 
iMAX_PLAYERSi++){
        new 
Float:xFloat:yFloat:z;
        
GetPlayerPos(playeridxyz);
        if(
IsPlayerInRangeOfPoint(i20xyz)) SendClientMessage(i, -1string);
     }
     return 
0;
}
// extracted from strlib.inc
stock strreplace(string[], const search[], const replacement[], bool:ignorecase falsepos 0limit = -1maxlength sizeof(string)) {
    if (
limit == 0)
        return 
0;
    new
             
sublen strlen(search),
             
replen strlen(replacement),
        
bool:packed ispacked(string),
             
maxlen maxlength,
             
len strlen(string),
             
count 0
    
;
    if (
packed)
        
maxlen *= 4;
    if (!
sublen)
        return 
0;
    while (-
!= (pos strfind(stringsearchignorecasepos))) {
        
strdel(stringpospos sublen);
        
len -= sublen;
        if (
replen && len replen maxlen) {
            
strins(stringreplacementposmaxlength);  
            
pos += replen;
            
len += replen;
        }
        if (
limit != -&& ++count >= limit)
            break;
    } 
    return 
count;

Here is a preview:
Reply
#7

Your testing should be able to prove your code wrong at some point (Your code should be falsifiable), if there isn't then your code will work as you wanted. Many people don't think how their code can malfunction.

What if I type "something * hey", what do you expect here to be purple? I think sscanf would do the trick here as:
New highlight[20];
Sscanf(text, "{S}'*'s[20]'*'", highlight))

There can be a way to write my code with a different method as well.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)