AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Using the plugin with variables (https://forums.alliedmods.net/showthread.php?t=159052)

bibu 06-12-2011 11:31

Using the plugin with variables
 
I am trying to change this plugin with variables individual for each player. So it doesn't have to use any cvars at all. I created a menu for it and now I need to check the variables. But as the original plugin is with enums, I don't have any idea how I can here check for example for the variable of the player:

PHP Code:

public Event_ResetHUD(id)
{
    if 
//which variable
    
{
           
//do what?
    
}
    if 
//which variable
    
{
           
//do what else?
    
}


The same for "Event_HideWeapon".

Here is the list of the variables and the whole plugin:

PHP Code:

new bool:hud_money[33]
new 
bool:hud_timer[33]
new 
bool:hud_flashlight[33]
new 
bool:hud_radar_hp_ap[33]
new 
bool:hud_crosshair[33]
new 
bool:hud_wpnlist[33

PHP Code:

#include <amxmodx> 
#include <fakemeta>
#include <hamsandwich>

#define VERSION "0.6" 

const HUD_HIDE_CAL 1<<0
const HUD_HIDE_FLASH 1<<1
const HUD_HIDE_ALL 1<<2    
const HUD_HIDE_RHA 1<<3
const HUD_HIDE_TIMER 1<<4
const HUD_HIDE_MONEY 1<<5
const HUD_HIDE_CROSS 1<<6
const HUD_DRAW_CROSS 1<<7

const HIDE_GENERATE_CROSSHAIR HUD_HIDE_FLASH|HUD_HIDE_RHA|HUD_HIDE_TIMER|HUD_HIDE_MONEY|HUD_DRAW_CROSS

#define    m_iHideHUD            361
#define    m_iClientHideHUD        362
#define    m_pClientActiveItem        374

enum _:Hide_Hud {
    
Hide_Cal,
    
Hide_Flash,
    
Hide_All,
    
Hide_Rha,
    
Hide_Timer,
    
Hide_Money,
    
Hide_Cross,
    
Draw_Cross
}

new 
g_bitHudFlags

new g_pCvars[Hide_Hud]

public 
plugin_init() 

    
register_plugin("HUD Customizer"VERSION"Igoreso/ConnorMcLeod"
    
    
g_pCvars[Hide_Cal] = register_cvar("amx_hud_hide_cross_ammo_weaponlist""0")
    
g_pCvars[Hide_Flash] = register_cvar("amx_hud_hide_flashlight""1")
    
g_pCvars[Hide_All] = register_cvar("amx_hud_hide_all""1")
    
g_pCvars[Hide_Rha] = register_cvar("amx_hud_hide_radar_health_armor""1")
    
g_pCvars[Hide_Timer] = register_cvar("amx_hud_hide_timer""1")
    
g_pCvars[Hide_Money] = register_cvar("amx_hud_hide_money""0")
    
g_pCvars[Hide_Cross] = register_cvar("amx_hud_hide_crosshair""0")
    
g_pCvars[Draw_Cross] = register_cvar("amx_hud_draw_crosshair""0")

    
register_event("HLTV""Event_HLTV_New_Round""a""1=0""2=0")

    
register_event("ResetHUD""Event_ResetHUD""b")
    
register_event("HideWeapon""Event_HideWeapon""b")

    
Event_HLTV_New_Round()
}

public 
Event_HLTV_New_Round()
{
    for(new 
ii<Hide_Hudi++)
    {
        if( 
get_pcvar_numg_pCvars[i] ) )
        {
            
g_bitHudFlags |= 1<<i
        
}
    }
}

public 
Event_ResetHUD(id)
{
    if( 
g_bitHudFlags )
    {
        
set_pdata_int(idm_iClientHideHUD0)
        
set_pdata_int(idm_iHideHUDg_bitHudFlags)
    }    
}

public 
Event_HideWeaponid )
{
    new 
iFlags read_data(1)
    if( 
g_bitHudFlags && (iFlags g_bitHudFlags != g_bitHudFlags) )
    {
        
set_pdata_int(idm_iClientHideHUD0)
        
set_pdata_int(idm_iHideHUDiFlags|g_bitHudFlags)
    }

    if( 
iFlags HIDE_GENERATE_CROSSHAIR && !(g_bitHudFlags HUD_DRAW_CROSS) && is_user_alive(id) )
    {
        
set_pdata_cbase(idm_pClientActiveItemFM_NULLENT)
    }



fysiks 06-12-2011 12:29

Re: Using the plugin with variables
 
To make this per-player specific settings you only need one array with a dimension of 33 (each player would have their own g_bitHudFlags)

Something like this:

PHP Code:

#include <amxmodx> 
#include <fakemeta>
#include <hamsandwich>

#define VERSION "0.6" 

const HUD_HIDE_CAL 1<<0
const HUD_HIDE_FLASH 1<<1
const HUD_HIDE_ALL 1<<2    
const HUD_HIDE_RHA 1<<3
const HUD_HIDE_TIMER 1<<4
const HUD_HIDE_MONEY 1<<5
const HUD_HIDE_CROSS 1<<6
const HUD_DRAW_CROSS 1<<7

const HIDE_GENERATE_CROSSHAIR HUD_HIDE_FLASH|HUD_HIDE_RHA|HUD_HIDE_TIMER|HUD_HIDE_MONEY|HUD_DRAW_CROSS

#define    m_iHideHUD            361
#define    m_iClientHideHUD        362
#define    m_pClientActiveItem        374

new g_bitHudFlags[33]

public 
plugin_init() 

    
register_plugin("HUD Customizer"VERSION"Igoreso/ConnorMcLeod"
    
    
register_event("ResetHUD""Event_ResetHUD""b")
    
register_event("HideWeapon""Event_HideWeapon""b")
}

public 
Event_ResetHUD(id)
{
    if( 
g_bitHudFlags[id] )
    {
        
set_pdata_int(idm_iClientHideHUD0)
        
set_pdata_int(idm_iHideHUDg_bitHudFlags[id])
    }    
}

public 
Event_HideWeaponid )
{
    new 
iFlags read_data(1)
    if( 
g_bitHudFlags[id] && (iFlags g_bitHudFlags[id] != g_bitHudFlags[id]) )
    {
        
set_pdata_int(idm_iClientHideHUD0)
        
set_pdata_int(idm_iHideHUDiFlags|g_bitHudFlags[id])
    }

    if( 
iFlags HIDE_GENERATE_CROSSHAIR && !(g_bitHudFlags[id] & HUD_DRAW_CROSS) && is_user_alive(id) )
    {
        
set_pdata_cbase(idm_pClientActiveItemFM_NULLENT)
    }



bibu 06-12-2011 12:31

Re: Using the plugin with variables
 
But I want all of these functions seperetely activated/deactivated.

fysiks 06-12-2011 12:37

Re: Using the plugin with variables
 
Quote:

Originally Posted by bibu (Post 1486463)
But I want all of these functions seperetely activated/deactivated.

You can set/remove them individually but you need the bit flags either way when using set_pdata_int(). You will just need to write those functions to do it. Bugsy's bitwise functions tutorial will help you set and unset bits in for g_bitHudFlags[id].

bibu 06-12-2011 16:47

Re: Using the plugin with variables
 
You didn't understand what I am asking for, look I only need to check the variable, so it would be like this:

PHP Code:

public Event_ResetHUD(id)
{
    if(
hud_money[id])
    {
           
//do or set what?
    
}
    if(
hud_timer[id])
    {
           
//do or set what else?
    
}
     
/*still continue the check of the other variables */



fysiks 06-12-2011 16:55

Re: Using the plugin with variables
 
Ok . . . you're correct, I don't understand the quesiton. In fact, now, I have no clue what the question is, lol.

Though, I did honestly think that my first suggestion would provide a solution to your original intent (making the HUD settings per-player).

bibu 06-12-2011 17:04

Re: Using the plugin with variables
 
You were talking about this, only one variable:

PHP Code:

    if( g_bitHudFlags[id] ) 
    { 

And I am talking about the others, you're using just one.

fysiks 06-12-2011 17:08

Re: Using the plugin with variables
 
Quote:

Originally Posted by bibu (Post 1486707)
You were talking about this, only one variable:

PHP Code:

    if( g_bitHudFlags[id] ) 
    { 

And I am talking about the others, you're using just one.

Correct. The one variable that I'm using uses bit flags so it is effectively 32 variables in one integer.

Was I correct in assuming that your overall goal is to make it so each individual player can choose which of the features are enabled or disabled?

bibu 06-13-2011 06:28

Re: Using the plugin with variables
 
Quote:

Originally Posted by fysiks (Post 1486713)
Was I correct in assuming that your overall goal is to make it so each individual player can choose which of the features are enabled or disabled?

Exactly yes. But still I would like to check them separately.

Hunter-Digital 06-13-2011 07:09

Re: Using the plugin with variables
 
Then use bitsums combined with a array like fysiks explained in his post.

You can set/unset/check them individually for each player:
Code:

if(g_bitHudFlags[id] & HUD_HIDE_MONEY)
{
    // money are hidden
}
else
{
    // money are not hidden
}

Code:

g_bitHudFlags[id] |= HUD_HIDE_MONEY // hide money

g_bitHudFlags[id] &= ~(HUD_HIDE_MONEY) // unhide money

The same goes with all bitsum flags defined in fysiks' code.


All times are GMT -4. The time now is 23:27.

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