Raised This Month: $51 Target: $400
 12% 

Toggle command not working


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
maxolahird
Veteran Member
Join Date: Dec 2012
Old 12-24-2016 , 12:41   Toggle command not working
Reply With Quote #1

I'm trying to add a command in this plugin to make players able to toggle "show bullet damage".

At least for me it seems everything is correct but still it wont toggle properly/make damage not show up.

What's wrong?

PHP Code:
#include <amxmodx>
#include <engine>

new g_hudmsg1g_hudmsg2,g_typeg_enabled;
new 
bool:gOnOff[33] = { true, ... };

public 
plugin_init() {
    
register_plugin("Bullet Damage with Spec""1.3""Sn!ff3r, modded by mforce")
    
register_event("Damage""on_damage""b""2!0""3=0""4!0")    
    
    
register_clcmd("amx_dmg""toggleDmg"0"");  
    
register_clcmd("amx_showdmg""toggleDmg"0""); 
    
    
g_type register_cvar("amx_bulletdamage","1")
    
    
g_hudmsg1 CreateHudSyncObj()
    
g_hudmsg2 CreateHudSyncObj()
}

public 
toggleDmg(id)
{
    if( 
gOnOff[id] )
    {
        
client_print_color(idid"OFF");
        
gOnOff[id] = false;
    }
    else
    {
        
client_print_color(idid"ON");
        
gOnOff[id] = true;
    }
}

public 
on_damage(id) {    
    static 
attackerattacker get_user_attacker(id)
    if(
is_user_connected(attacker)) {
        static 
damagedamage read_data(2)
        
g_enabled get_pcvar_num(g_type)    
        
        if(
g_enabled && gOnOff[id] == true)
        {    

            
set_hudmessage(255000.450.5020.14.00.10.1, -1)
            
ShowSyncHudMsg(idg_hudmsg2"%i^n"damage)
            
            
set_hudmessage(0100200, -1.00.5520.14.00.020.02, -1)
            
ShowSyncHudMsg(attackerg_hudmsg1"%i^n"damage)
            

            static 
iPlayers[32], iNum;
            
get_players(iPlayersiNum"bch")

            for(new 
0Spectator iPlayers[0]; iNumSpectator iPlayers[i++]) {
                if(
entity_get_int(SpectatorEV_INT_iuser2) == attacker) {
                    
set_hudmessage(0100200, -1.00.5520.14.00.020.02, -1)
                    
ShowSyncHudMsg(Spectatorg_hudmsg1"%i^n"damage)
                }
                if(
entity_get_int(SpectatorEV_INT_iuser2) == id) {
                    
set_hudmessage(255000.450.5020.14.00.10.1, -1)
                    
ShowSyncHudMsg(Spectatorg_hudmsg2"%i^n"damage)
                }
            }
        }
    }
}  

public 
client_connect(id)
{
    
gOnOff[id] = true;
}

public 
client_disconnect(id)
{
    
gOnOff[id] = true;

maxolahird is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-24-2016 , 13:20   Re: Toggle command not working
Reply With Quote #2

Why are you checking "id" in the damage event? You should check both id and attacker when displaying the message to either one of them.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 12-24-2016 , 14:20   Re: Toggle command not working
Reply With Quote #3

Code:
public toggleDmg(id) {     gOnOff[ id ] = !gOnOff[ id ];     client_print( id , print_chat, gOnOff[ id ] ? "OFF" : "ON" );     return PLUGIN_HANDLED; }
__________________
Project: Among Us

Last edited by Craxor; 12-24-2016 at 14:21.
Craxor is offline
Send a message via ICQ to Craxor
maxolahird
Veteran Member
Join Date: Dec 2012
Old 12-24-2016 , 21:17   Re: Toggle command not working
Reply With Quote #4

Quote:
Originally Posted by OciXCrom View Post
Why are you checking "id" in the damage event? You should check both id and attacker when displaying the message to either one of them.
Hey, I'm not sure, I didn't write that code, Sn!ff3r did. I just added (or tried) toggle stuff.
https://forums.alliedmods.net/showthread.php?t=88577

Quote:
Originally Posted by Craxor View Post
Code:
public toggleDmg(id) {     gOnOff[ id ] = !gOnOff[ id ];     client_print( id , print_chat, gOnOff[ id ] ? "OFF" : "ON" );     return PLUGIN_HANDLED; }

Hey, That and the original code for some reason only disables damage received HUD, not damage dealt.. really weird

It's just not checking the toggle command properly.

I tought anything inside if(g_enabled && gOnOff[id] == true), should not show up if gOnOff[id] = false.. I probably did something wrong

Last edited by maxolahird; 12-25-2016 at 01:17.
maxolahird is offline
maxolahird
Veteran Member
Join Date: Dec 2012
Old 12-26-2016 , 22:14   Re: Toggle command not working
Reply With Quote #5

Guys how can I make it enable/disable properly according to cvar or chat command?
maxolahird is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:46.


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