AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Normal Chat not working (https://forums.alliedmods.net/showthread.php?t=307315)

instinctpt1 05-05-2018 00:51

Normal Chat not working
 
Here is my code ( Totally Hardcoded not for public use )
PHP Code:

#include <amxmodx>
#include <amxmisc>

#define OWNER(%0) (get_user_flags(%0) & ADMIN_RCON)
#define HEADMIN(%0) (get_user_flags(%0) & ADMIN_IMMUNITY)
#define ADMIN(%0) (get_user_flags(%0) & ADMIN_BAN)
#define VIP(%0) (get_user_flags(%0) & ADMIN_RESERVATION)

#define xOWNER "^1[^4OWNER^1]"
#define xHEADMIN "^1[^4HEAD ADMIN^1]"
#define xADMIN "^1[^4ADMIN^1]"
#define xVIP "^1[^4VIP^1]"

#define ALIVE(%0) is_user_alive(%0)

public plugin_init()
{
    
register_plugin("Simple Chat Prefixes""1.1 - BETA""DiGiTaL")
    
register_clcmd("say""handleSay")
    
register_clcmd("say_team""handleTeamSay")
}

public 
handleSay(id) return checkMsg(idfalse)
public 
handleTeamSay(id) return checkMsg(idtrue)

public 
checkMsg(idbool:teamSay)
{
    if(
OWNER(id)) ALIVE(id) ? setMsg(idtruexOWNERtrueteamSay) : setMsg(idtruexOWNERfalseteamSay)
    else if(
HEADMIN(id)) ALIVE(id) ? setMsg(idtruexHEADMINtrueteamSay) : setMsg(idtruexHEADMINfalseteamSay)
    else if(
ADMIN(id)) ALIVE(id) ? setMsg(idtruexADMINtrueteamSay) : setMsg(idtruexADMINfalseteamSay)
    else if(
VIP(id)) ALIVE(id) ? setMsg(idtruexVIPtrueteamSay) : setMsg(idtruexVIPfalseteamSay)
    else if(!
is_user_admin(id)) ALIVE(id) ? setMsg(idfalse""trueteamSay) : setMsg(idfalse""falseteamSay)
    return 
PLUGIN_HANDLED
}

stock setMsg(indexbool:is_admintype[], bool:is_alivebool:is_teamSay)
{
    new 
nMsg[192],szArg[192], szName[32], szTeam[32], players[32], num
    get_user_name
(indexszNamecharsmax(szName))
    
get_user_team(indexszTeamcharsmax(szTeam))

    
read_args(szArgcharsmax(szArg))
    
remove_quotes(szArg)

    if (!
szArg[0] || szArg[0] == '/') return PLUGIN_HANDLED_MAIN

    
if(is_alive)
    {
        if(
is_teamSay)
        {
            
is_admin formatex(nMsgcharsmax(nMsg), "^1(%s) %s ^3%s ^1: ^4%s"szTeamtypeszNameszArg) : formatex(nMsgcharsmax(nMsg), "^1(%s) ^3%s ^1: %s"szTeamszNameszArg)
            
get_players(playersnum"ae"szTeam)
            for(new 
i;numi++) client_print_color(players[i], 0nMsg)
        }
        else
        {
            (
is_admin) ? formatex(nMsgcharsmax(nMsg), "%s ^3%s ^1: ^4%s"typeszNameszArg) : formatex(nMsgcharsmax(nMsg), "^3%s ^1: %s"szNameszArg)
            
client_print_color(00nMsg)
        }
    } 
    else
    {
        if(
is_teamSay)
        {
            (
is_admin) ? formatex(nMsgcharsmax(nMsg), "^1*DEAD* (%s) %s ^3%s ^1: ^4%s"szTeamtypeszNameszArg) : formatex(nMsgcharsmax(nMsg), "^1*DEAD* (%s) ^3%s ^1: %s"szTeamszNameszArg)
            
get_players(playersnum"be"szTeam)
            for(new 
i;numi++) client_print_color(players[i], 0nMsg)
        }
        else 
        {
            (
is_admin) ? formatex(nMsgcharsmax(nMsg), "^1*DEAD* %s ^3%s ^1: ^4%s"typeszNameszArg) : formatex(nMsgcharsmax(nMsg), "^1*DEAD* ^3%s ^1: %s"szNameszArg)
            
get_players(playersnum"b")
            for(new 
i;numi++) client_print_color(players[i], 0nMsg)
        }
    } 
    return 
PLUGIN_HANDLED


I have returned the original say handler to my say func. and added cases in that ...
Now here is problem i m facing :

- Admin chat ( Acc to cases ) working perfect
- Normal player ( Non admin) chat not showing up :/

I have added case to handle normal chat but still not working ...
Most probably i think its the return stopping to use normal chat ..

Help Pro people ..

CrAzY MaN 05-05-2018 07:25

Re: Normal Chat not working
 
Just use !(is_admin) and format for that!

instinctpt1 05-05-2018 09:21

Re: Normal Chat not working
 
Quote:

Originally Posted by CrAzY MaN (Post 2590788)
Just use !(is_admin) and format for that!

Its the same ...

Natsheh 05-05-2018 10:54

Re: Normal Chat not working
 
Try using my tag user prefix you can set tags by flags

instinctpt1 05-05-2018 12:12

Re: Normal Chat not working
 
Natsheh i know there are many seriously better options
But i just want to know wht is wrong in my shit scripting to learn and have knwledge

As i wrote it under 10-15 mins and cant spot my mistakes for hours .. thats my talent :(

Natsheh 05-05-2018 12:40

Re: Normal Chat not working
 
Quote:

Originally Posted by instinctpt1 (Post 2590836)
Natsheh i know there are many seriously better options
But i just want to know wht is wrong in my shit scripting to learn and have knwledge

As i wrote it under 10-15 mins and cant spot my mistakes for hours .. thats my talent :(

Try to decrease calling the natives many times inside the function by saving the values inside variables, like is user alive get user flags...

Try to read my user tag prefix also its not perfectly optimized due careless.

fysiks 05-05-2018 13:45

Re: Normal Chat not working
 
You have a lot of redundant code and it is poorly organized. This makes it easier to make mistakes and harder to find and fix those mistakes.

Here is a much better way to organize the code:
PHP Code:

public checkMsg(idbool:teamSay)
{
    static 
tags[][] = {""xOWNERxHEADMINxADMINxVIP}
    new 
type
    
if( OWNER(id) )
        
type 1
    
else if( HEADMIN(id) )
        
type 2
    
else if( ADMIN(id) )
        
type 3
    
else if( VIP(id) )
        
type 4
    
else
        
type 0
    
    setMsg
(idis_user_admin(id), tags[type], is_user_alive(id), teamSay)
    
    return 
PLUGIN_HANDLED


Also note that returning PLUGIN_HANDLED or PLUGIN_HANDLED_MAIN in a subfunction doesn't actually do anything. Only the top-level function matters. I.e. returning different values in setMsg() doesn't do anything unless you actually use that return value (which you don't).

Also, if you are meaning to not do anything (and let the message continue like normal) when they are not one of the ones that needs a tag then you can simply return PLUGIN_CONTINUE if type == 0 instead of PLUGIN_HANDLED in checkMsg().

instinctpt1 05-05-2018 14:04

Re: Normal Chat not working
 
Thanks fysiks ☺️

Natsheh 05-05-2018 14:25

Re: Normal Chat not working
 
Quote:

Originally Posted by instinctpt1 (Post 2590850)
Thanks fysiks ☺️

Also hook saytext message and modifie the message instead of blocking the say/team clcmd other plugins chat commands will be blocked/ignored

instinctpt1 05-06-2018 10:09

Re: Normal Chat not working
 
Quote:

Originally Posted by Natsheh (Post 2590853)
Also hook saytext message and modifie the message instead of blocking the say/team clcmd other plugins chat commands will be blocked/ignored

But whats wrong in blocking Natsheh as i said i m going to return the chat again to normal if user is not admin :)


All times are GMT -4. The time now is 04:42.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.