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

Please help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Striker2008
Junior Member
Join Date: Aug 2008
Old 01-10-2015 , 20:19   Please help
Reply With Quote #1

Hello,

So I've been trying to create a hero that activates an ability which allows him to receive HP when being shot, instead of taking damage.

All is working quite well, except for the fact that sometimes when I activate the ability I get HP "out of nowhere" (without taking damage). This happens even if I activate it at the beginning of the round ...

Oh, and you should probably know that I don't know much about scripting... to say that I am beginner would still be too much. I'm just fairly good at reading code, and modifying it here and there. That's what I did here, I used the "template" from sh_shadowcat and added a damage event, plus a few other tweaks, of course.

Anyway, I would appreciate it if you could help me out

PHP Code:
// Aberration - when activated, you get health when being shot

#include <amxmod>
#include <superheromod>
#include <cstrike>

// VARIABLES
new gHeroName[]="Aberration"
new bool:gHasAberrationPower[SH_MAXSLOTS+1]
new 
g_AberrationTimer[SH_MAXSLOTS+1]
new 
g_AberrationSound[]="ambience/alien_zonerator.wav"
//----------------------------------------------------------------------------------------------
public plugin_init()
{
    
// Plugin Info
    
register_plugin("SUPERHERO Aberration","1","X")
  
    
// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
    
register_cvar("aberration_level","0")
    
register_cvar("aberration_cooldown""15" )
    
register_cvar("aberration_duration""5" )
 
    
// FIRE THE EVENT TO CREATE THIS SUPERHERO!
    
shCreateHero(gHeroName"Aberration""Get life when being shot"true"aberration_level" )
  
    
// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
    
register_event("Damage""aberration_damage""be")
    
register_event("ResetHUD","newRound","b")

    
//KEY DOWN
    
register_srvcmd("aberration_kd""aberration_kd")
    
shRegKeyDown(gHeroName"aberration_kd")

    
// INIT
    
register_srvcmd("aberration_init""aberration_init")
    
shRegHeroInit(gHeroName"aberration_init")

    
// LOOP
    
set_task(1.0,"aberration_loop",0,"",0,"b" )

    
// DEATH
    
register_event("DeathMsg""aberration_death""a")

}
//----------------------------------------------------------------------------------------------
public plugin_precache()
{
    
precache_sound(g_AberrationSound)
}
//----------------------------------------------------------------------------------------------
public aberration_init()
{
    
// First Argument is an id
    
new temp[6]
    
read_argv(1,temp,5)
    new 
id str_to_num(temp)
  
    
// 2nd Argument is 0 or 1 depending on whether the id has Aberration
    
read_argv(2,temp,5)
    new 
hasPowers str_to_num(temp)

    
gHasAberrationPower[id] = (hasPowers != 0)

    if ( !
hasPowers ) {
        if ( 
g_AberrationTimer[id] >= ) {
            
aberration_end(id)
        }
    }
}
//----------------------------------------------------------------------------------------------
public newRound(id)
{
    
gPlayerUltimateUsed[id] = false
    
if (gHasAberrationPower[id]) {
        
aberration_end(id)
    }
}
//----------------------------------------------------------------------------------------------
// RESPOND TO KEYDOWN
public aberration_kd()
{
    if ( !
hasRoundStarted() ) return PLUGIN_HANDLED

    
new temp[6]
    
read_argv(1,temp,5)
    new 
id=str_to_num(temp)

    if ( !
is_user_alive(id) ) return PLUGIN_HANDLED

    
// Make sure they're not in the middle of clip already
    // Let them know they already used their ultimate if they have
    
if ( gPlayerUltimateUsed[id] || g_AberrationTimer[id] > ) {
        
playSoundDenySelect(id)
        return 
PLUGIN_HANDLED
    
}
        
    
g_AberrationTimer[id] = get_cvar_num("aberration_duration")
    
aberration_damage(id)
    
ultimateTimer(idget_cvar_num("aberration_cooldown") * 1.0)

    
// Aberration Messsage
    
new message[128]
    
format(message127"Aberration^nYou will now receive HP when being shot!" )
    
set_hudmessage(255,0,0,-1.0,0.3,0,0.25,1.2,0.0,0.0,87)
    
show_hudmessage(idmessage)
    
emit_sound(id,CHAN_STATICg_AberrationSound0.2ATTN_NORM0PITCH_LOW)

    return 
PLUGIN_HANDLED
}
//----------------------------------------------------------------------------------------------
public aberration_damage(id)
{
    new 
damage read_data(2)
    new 
u_health get_user_health(id)
    new 
newlife u_health damage damage

    
if(g_AberrationTimer[id]>&& gHasAberrationPower[id] != && is_user_alive(id)){
        
set_user_health(idnewlife)
    }
}
//----------------------------------------------------------------------------------------------
public stopSound(id)
{
    
emit_sound(id,CHAN_STATICg_AberrationSound0.0ATTN_NORMSND_STOPPITCH_LOW)
}

//----------------------------------------------------------------------------------------------
public aberration_loop()
{
    for ( new 
id 1id <= SH_MAXSLOTSid++ ) {
        if ( 
gHasAberrationPower[id] && is_user_alive(id)  )  {
            if ( 
g_AberrationTimer[id] > ) {
                new 
message[128]
                
format(message127"%d seconds left"g_AberrationTimer[id] )
                
set_hudmessage(255,0,0,-1.0,0.3,0,1.0,1.2,0.0,0.0,87)
                
show_hudmessageidmessage)
                
g_AberrationTimer[id]--
            }
            else if ( 
g_AberrationTimer[id] == ) {
                
g_AberrationTimer[id]--
                
aberration_end(id)
            }
        }
    }
}
//----------------------------------------------------------------------------------------------
public aberration_end(id)
{
    if (!
is_user_connected(id)) return
    
g_AberrationTimer[id] = 0
    stopSound
(id)
}
//---------------------------------------------------------------------------------------------- 
Also, when compiling, the compiler is giving me a "tag mismatch" warning on this line:
PHP Code:
if(g_AberrationTimer[id]>&& gHasAberrationPower[id] != && is_user_alive(id)){
        
set_user_health(idnewlife)


Last edited by Striker2008; 01-11-2015 at 07:57.
Striker2008 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 08:54.


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