OnPlayerText
#1

Hi, can someone explain me 'bout OnPlayerText,

what I want is this:

when a player types Justin bieber
there comes, error: this server is not gay!

I don't know how to use this callback... is it the same as OnPlayerCommandText with sctrcmp?
Reply
#2

You could check the wiki for more info
But yes you can use strcmp but then it will only check if the player types "Justin Beiber". If you use strfind it would check if the text has any "Justin Bieber" in it.
Example with strcmp:
pawn Код:
if(strcmp(text, "Justin Biber", true) == 0)
{
    //Do stuff here!
    return 0;
}

//With strfind:
if (strfind(text, "Justin Bieber") != -1)
{
    //Do stuff here!
    return 0;
}
Reply
#3

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(strfind(text, "Justin bieber", true) != -1)
    {
        return SendClientMessage(playerid, 0xFF0000FF, "This server is not gay!");
    }
}
Reply
#4

Here you go:
pawn Код:
public OnPlayerText(playerid, text[])
{
    if(strfind(text, "Justin Bieber", true) != -1)
    {
        return SendClientMessage(playerid, 0xFF0000FF, "ERROR: This server is not gay!"), 0;
    }
    return 1;
}
EDIT: Too late
Reply
#5

:O thanks buddies!
never got helped so far xD


PS: To mister winnie the Poo, what's diffrence between both of your examples? does it have a diffrend effect? the sctrcmp and strfind?
Reply
#6

Quote:
Originally Posted by knackworst
Посмотреть сообщение
:O thanks buddies!
never got helped so far xD


PS: To mister winnie the Poo, what's diffrence between both of your examples? does it have a diffrend effect? the sctrcmp and strfind?
If you use strcmp it will only work if the player types "Justin Bieber" and nothing more. If you use strfind it will work when the text has Justin Bieber in it, like: "Hello. Im Justin Bieber lover<3" hope you understand what I mean
Reply
#7

It is also possible to set the player health to 1 when he say Justin Bieber?
Reply
#8

You can, just add SetPlayerHealth and add a return 0.
Reply
#9

Yeah I think this would work but not sure :P

Код:
public OnPlayerText(playerid, text[])
{
if(strfind(text, "Justin bieber", true) != -1)
{
SetPlayerHealth(playerid, 1);
return SendClientMessage(playerid, 0xFF0000FF, "This server is not gay!");
}
return 1;
}
Reply
#10

Yep, it would work like that too.
Reply
#11

First i want to say Thanks, then

If you change
pawn Код:
return SendClientMessage(playerid, 0xFF0000FF, "This server is not gay!");
to
pawn Код:
return SendClientMessage(playerid, 0xFF0000FF, "This server is not gay!"), 0;
Then it works better :P
Reply
#12

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(strfind(text, "Justin Bieber", true) != -1)
    {
        return SendClientMessage(playerid, 0xFF0000FF, "You suck dick"), 0;
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)