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] >= 0 ) {
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] > 0 ) {
playSoundDenySelect(id)
return PLUGIN_HANDLED
}
g_AberrationTimer[id] = get_cvar_num("aberration_duration")
aberration_damage(id)
ultimateTimer(id, get_cvar_num("aberration_cooldown") * 1.0)
// Aberration Messsage
new message[128]
format(message, 127, "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(id, message)
emit_sound(id,CHAN_STATIC, g_AberrationSound, 0.2, ATTN_NORM, 0, PITCH_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]>0 && gHasAberrationPower[id] != 0 && is_user_alive(id)){
set_user_health(id, newlife)
}
}
//----------------------------------------------------------------------------------------------
public stopSound(id)
{
emit_sound(id,CHAN_STATIC, g_AberrationSound, 0.0, ATTN_NORM, SND_STOP, PITCH_LOW)
}
//----------------------------------------------------------------------------------------------
public aberration_loop()
{
for ( new id = 1; id <= SH_MAXSLOTS; id++ ) {
if ( gHasAberrationPower[id] && is_user_alive(id) ) {
if ( g_AberrationTimer[id] > 0 ) {
new message[128]
format(message, 127, "%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_hudmessage( id, message)
g_AberrationTimer[id]--
}
else if ( g_AberrationTimer[id] == 0 ) {
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]>0 && gHasAberrationPower[id] != 0 && is_user_alive(id)){
set_user_health(id, newlife)
}