SA-MP Forums Archive
OnPlayerText problem - 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: OnPlayerText problem (/showthread.php?tid=647256)



OnPlayerText problem - NealPeteros - 02.01.2018

I have this command for players to disable their global chat

PHP код:
CMD:togchat(playerid, params[])
{
    switch(
chattoggle[playerid])
    {
        case 
true: chattoggle[playerid] = false, SendClientMessage(playerid, 0x00FF00FF, "Chat enabled");
        case 
false: chattoggle[playerid] = true, SendClientMessage(playerid, 0x00FF00FF, "Chat disabled");
    }
    return 
1;
} 
OnPlayerText:
PHP код:
public OnPlayerText(playerid, text[])
{
    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(playerid, 0xFF0000AA, "You're not authorized to use that command!");
    if(
chattoggled)
    {
        
chattoggled = false;
        
SendClientMessageToAll(0x00FFFFFF, "AdmCmd: An administrator has disabled the chat");
    }
    else 
SendClientMessage(playerid, 0xFFFF00FF, "Chat is already disabled");
    return 
1;
}
CMD:enablechat(playerid)
{
    if(
PlayerInfo[playerid][Admin] < 6) return SendClientMessage(playerid, 0xFF0000AA, "You're not authorized to use that command!");
    if(!
chattoggled)
    {
        
chattoggled = true;
        
SendClientMessageToAll(0x00FFFFFF, "AdmCmd: An administrator has enabled the chat");
    }
    else 
SendClientMessage(playerid, 0xFFFF00FF, "Chat is already enabled");
    return 
1;
} 
When /disablechat is used, it disables the chat. but when /togchat is used, it doesn't


Re: OnPlayerText problem - JesterlJoker - 02.01.2018

PHP код:
public OnPlayerText(playerid, text[])
{
    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(playerid, 0xFF0000AA, "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(playerid, 0xFFFF00FF, "Chat is already disabled");
    return 
1;
} 



Re: OnPlayerText problem - JaKe Elite - 02.01.2018

This

PHP код:
public OnPlayerText(playerid, text[]) 
{ 
    if(!
chattoggled) 
    { 
        return 
0; 
    } 
    else 
    { 
        return 
0; 
    } 
        if(
chattoggle[playerid]) 
    { 
        return 
0; 
    } 
    else 
    { 
        return 
1; 
    } 
} 
Can be optimized to this

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