OnPlayerText problem
#1

I have this command for players to disable their global chat

PHP код:
CMD:togchat(playeridparams[])
{
    switch(
chattoggle[playerid])
    {
        case 
truechattoggle[playerid] = falseSendClientMessage(playerid0x00FF00FF"Chat enabled");
        case 
falsechattoggle[playerid] = trueSendClientMessage(playerid0x00FF00FF"Chat disabled");
    }
    return 
1;

OnPlayerText:
PHP код:
public OnPlayerText(playeridtext[])
{
    if(!
chattoggled)
    {
        return 
0;
    }
    else
    {
        return 
0;
    }
        if(
chattoggle[playerid])
    {
        return 
0;
    }
    else
    {
        return 
1;
    }

The problem is that the chat would still be enabled even after toggling the chat off

chattoggled as global var is used here
PHP код:
CMD:disablechat(playerid)
{
    if(
PlayerInfo[playerid][Admin] < 6) return SendClientMessage(playerid0xFF0000AA"You're not authorized to use that command!");
    if(
chattoggled)
    {
        
chattoggled false;
        
SendClientMessageToAll(0x00FFFFFF"AdmCmd: An administrator has disabled the chat");
    }
    else 
SendClientMessage(playerid0xFFFF00FF"Chat is already disabled");
    return 
1;
}
CMD:enablechat(playerid)
{
    if(
PlayerInfo[playerid][Admin] < 6) return SendClientMessage(playerid0xFF0000AA"You're not authorized to use that command!");
    if(!
chattoggled)
    {
        
chattoggled true;
        
SendClientMessageToAll(0x00FFFFFF"AdmCmd: An administrator has enabled the chat");
    }
    else 
SendClientMessage(playerid0xFFFF00FF"Chat is already enabled");
    return 
1;

When /disablechat is used, it disables the chat. but when /togchat is used, it doesn't
Reply
#2

PHP код:
public OnPlayerText(playeridtext[])
{
    if(
chattoggled[playerid] == TRUE)
    {
        return 
0;
    }
    else
    {
        return 
0;
    }

or you could just do this though.

and I'll just fix one command you'll get the rest
PHP код:
CMD:disablechat(playerid)
{
    if(
PlayerInfo[playerid][Admin] < 6) return SendClientMessage(playerid0xFF0000AA"You're not authorized to use that command!");
    if(
chattoggled[playerid] == true)
    {
        
chattoggled[playerid] = false;
        
SendClientMessageToAll(0x00FFFFFF"AdmCmd: An administrator has disabled the chat");
    }
    else 
SendClientMessage(playerid0xFFFF00FF"Chat is already disabled");
    return 
1;

Reply
#3

This

PHP код:
public OnPlayerText(playeridtext[]) 

    if(!
chattoggled
    { 
        return 
0
    } 
    else 
    { 
        return 
0
    } 
        if(
chattoggle[playerid]) 
    { 
        return 
0
    } 
    else 
    { 
        return 
1
    } 

Can be optimized to this

PHP код:
public OnPlayerText(playeridtext[])
{
    if(!
chattoggled || chattoggle[playerid])
        return 
0;
        
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)