Raised This Month: $32 Target: $400
 8% 

Out of bounds error in clientPrethink. Would appreciate some help.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Y060N
BANNED
Join Date: Dec 2011
Location: www.equilibriumcs.com
Old 07-09-2012 , 13:39   Out of bounds error in clientPrethink. Would appreciate some help.
Reply With Quote #1

PHP Code:
#include <amxmodx>
#include <cstrike>
#include <fakemeta>
#include <hamsandwich>
#include <zp50_class_zombie>
#include <zp50_class_nemesis>
#include <zp50_ammopacks>

new g_bitAlivePlayersg_bitUserAllowed
#define MarkUserAlive(%0)       g_bitAlivePlayers |= (1 << (%0 & 31))
#define ClearUserAlive(%0)      g_bitAlivePlayers &= ~(1 << (%0 & 31))
#define IsUserAlive(%0)        g_bitAlivePlayers & (1 << (%0 & 31))

#define MarkUserAllow(%0)       g_bitUserAllowed |= (1 << (%0 & 31))
#define ClearUserAllow(%0)      g_bitUserAllowed &= ~(1 << (%0 & 31))
#define IsUserAllow(%0)        g_bitUserAllowed & (1 << (%0 & 31))

/*================================================================================
 [Constants, Offsets, Macros]
=================================================================================*/

// Plugin Version
new const PLUGIN_VERSION[] = "1.1.0 (zp50)"

// Brute Mother
new const zclass_name[] = { "Shaman" }
new const 
zclass_info[] = { "Heal teammates [E]" }
new const 
zclass_model[][] = { "bmother" }
new const 
zclass_clawmodel[][] = { "models/zombie_plague/v_bmother_hands.mdl" }
const 
zclass_health 2750
const Float:zclass_speed 0.90
const Float:zclass_gravity 1.0
const Float:zclass_knockback 1.0

/*================================================================================
 [Global Variables]
=================================================================================*/

// Player vars
new Float:g_flMaxHealth[33// zombie's max health
new g_iHealCounter[33// brute mother heal counter
new Float:g_fNextOccurance[33]
new 
healSpr

// Game vars
new g_iMotherIndex // index from the class

// Cvar pointers
new cvar_Intervalcvar_Amountcvar_Rangecvar_Counter

/*================================================================================
 [Precache and Init]
=================================================================================*/

public plugin_precache()
{
    
register_plugin("[ZP] Zombie Class: Shaman"PLUGIN_VERSION"lambda")
    
    new 
index
    g_iMotherIndex 
zp_class_zombie_register(zclass_namezclass_infozclass_healthzclass_speedzclass_gravity)
    
zp_class_zombie_register_kb(g_iMotherIndexzclass_knockback)
    for (
index 0index sizeof zclass_modelindex++)
        
zp_class_zombie_register_model(g_iMotherIndexzclass_model[index])
    for (
index 0index sizeof zclass_clawmodelindex++)
        
zp_class_zombie_register_claw(g_iMotherIndexzclass_clawmodel[index])
        
    
healSpr precache_model("sprites/healSpr.spr")
}

public 
plugin_init()
{
    
RegisterHam(Ham_Killed"player""fwd_PlayerKilled_Post"1)
    
    
register_forward(FM_PlayerPreThink"fwd_PlayerPreThink")
    
    
cvar_Interval register_cvar("zp_mother_interval""0.5")
    
cvar_Amount register_cvar("zp_mother_amount""25")
    
cvar_Range register_cvar("zp_mother_range""145")
    
cvar_Counter register_cvar("zp_mother_counter""100")
}

public 
client_putinserver(id)
{
    
g_iHealCounter[id] = 0
    ClearUserAlive
(id)
    
ClearUserAllow(id)
}

public 
client_disconnect(id)
{
    
g_iHealCounter[id] = 0
    ClearUserAlive
(id)
    
ClearUserAllow(id)
}

/*================================================================================
 [Main Forwards]
=================================================================================*/

public zp_fw_core_spawn_post(id)
{
    if(
is_user_alive(id))
        
MarkUserAlive(id)
}

public 
fwd_PlayerKilled_Post(victimattackergib)
{
    if (!
is_user_connected(victim))
        return
    
    
ClearUserAlive(victim)
    
g_iHealCounter[victim] = 0
}

public 
fwd_PlayerPreThink(id)
{
    if (~
IsUserAllow(id) || ~IsUserAlive(id))
        return
    
    static 
Float:fGameTime
    fGameTime 
get_gametime()
    
    if (
g_fNextOccurance[id] < fGameTime)
    {
        
g_fNextOccurance[id] = fGameTime get_pcvar_float(cvar_Interval)
    
        static 
Float:originF[3]
        
pev(idpev_originoriginF)
        
        static 
Float:rangeFloat:amountvictim
        range 
get_pcvar_float(cvar_Range)
        
amount get_pcvar_float(cvar_Amount)
        
victim = -1
        
        
while ((victim engfunc(EngFunc_FindEntityInSpherevictimoriginFrange)) != 0)
        {
            if (~
IsUserAlive(victim) || victim == id) continue
            
            new 
Float:currentHP
            pev
(victimpev_healthcurrentHP)
            if (
currentHP amount g_flMaxHealth[victim])
            {
                
set_pev(victimpev_healthcurrentHP amount)
                
g_iHealCounter[id]++
            }
        }
        
        while (
g_iHealCounter[id] > get_pcvar_num(cvar_Counter))
        {
            static 
Float:origin[3]
            
pev(idpev_originorigin)
            
            
engfunc(EngFunc_MessageBeginMSG_PVSSVC_TEMPENTITYorigin0)
            
write_byte(TE_SPRITE)
            
engfunc(EngFunc_WriteCoord,origin[0])
            
engfunc(EngFunc_WriteCoord,origin[1])
            
engfunc(EngFunc_WriteCoord,origin[2])
            
write_short(healSpr)
            
write_byte(8)
            
write_byte(255)
            
message_end()
            
            
zp_ammopacks_set(idzp_ammopacks_get(id) + 1)
            
            
g_iHealCounter[id] -= get_pcvar_num(cvar_Counter)
        }
    }
}

public 
zp_fw_core_infect_post(idattacker)
{
    if (!
is_user_connected(id))
        return
    
    
g_iHealCounter[id] = 0
    
    
if (zp_class_nemesis_get(id))
    {
        
ClearUserAllow(id)
        return
    }
    
    
pev(idpev_healthg_flMaxHealth[id])
    
    if (
zp_class_zombie_get_current(id) == g_iMotherIndex)
    {
        
MarkUserAllow(id)
    }
    else
        
ClearUserAllow(id)
}

public 
zp_fw_core_cure_post(id)
{
    
ClearUserAllow(id)
    
ClearUserAlive(id)
    
g_iHealCounter[id] = 0

Getting an index out of bounds error on:
PHP Code:
if (currentHP amount g_flMaxHealth[victim]) 
Not sure why, but I'd appreciate the help if possible.
Y060N is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-09-2012 , 14:54   Re: Out of bounds error in clientPrethink. Would appreciate some help.
Reply With Quote #2

~IsUserAlive(victim)

->

!is_user_alive(id)


And use http://www.amxmodx.org/funcwiki.php?go=func&id=390
Gonna save cpu.


And get rid of PreThink, doesn't seem to be needed at all.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Y060N
BANNED
Join Date: Dec 2011
Location: www.equilibriumcs.com
Old 07-09-2012 , 15:12   Re: Out of bounds error in clientPrethink. Would appreciate some help.
Reply With Quote #3

What can I use instead of PreThink to heal players around that player at a constant rate?

Also, why can't I use bits to check if they are alive?

Last edited by Y060N; 07-09-2012 at 15:13.
Y060N is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 07-09-2012 , 17:21   Re: Out of bounds error in clientPrethink. Would appreciate some help.
Reply With Quote #4

Problem is not to use bits, problem is to cache the value on some forwards that may not be reliable depending on what others plugins do, as revive a player without sending a reliable message/function, or kill a player without any notifiaction to other plugins.
That's why is_user_alive check is better.

Also, FindEntityInSphere returns entities indexes higher than players indexes, higher than 32.
When you perform the check IsUserAlive with such indexes, you "transform" that ent index in a mask so check can return 1, that's why you shouldn't use bits.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply


Thread Tools
Display Modes

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 23:05.


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