View Single Post
heliumdream
Senior Member
Join Date: Aug 2006
Old 10-28-2006 , 13:46   Re: Hero: Protoman (useless)
Reply With Quote #9

Code:
// Protoman - Proto Shield blocks all projectiles while not moving, shooting, or zooming for x seconds

 /*

 //Protoman
 protoman_level 60   - what level must they be for Protoman's powers?
 protoman_delay 8    - how long after shooting does the shield kick in?
 protoman_chance .25   - % chance the shield will work


 Version Changes:

 1.0 - useless

 * Initial Release

 1.2 - yang

 * Corrected for AMXX Compiler
 * Code CleanUp
 * Optimized Code

1.3 - heliumdream

* Made use of the proto_delay cvar
* Added a %chance cvar
* Switched health preservation code from old method to the method used in 'Juggernaut II'
* Also note about 8 lines below this is a defination 'HPNO 1200'.  This should be treated as 'additional health'.

 */


 #include <amxmod>
 #include <superheromod>

 // VARIABLES
 #define HPNO 1200
 new gHeroName[]="Protoman"
 new playerhealth[SH_MAXSLOTS+1]
 new bool:gHasProtoPower[SH_MAXSLOTS+1]
 new bool:gProtoShield[SH_MAXSLOTS+1]
 new protoDelay[SH_MAXSLOTS+1]
 //----------------------------------------------------------------------------------------------
 public plugin_init()
 {
    // Plugin Info
    register_plugin("SUPERHERO Protoman","1.2","useless / yang")

    // FIRE THE EVENT TO CREATE THIS SUPERHERO!
    if ( isDebugOn() ) server_print("Attempting to create Protoman Hero")
    if ( !cvar_exists("protoman_level") ) register_cvar("protoman_level", "3")
    shCreateHero(gHeroName, "Proto Shield", "Chance to block projectiles when not moving, shooting, or zooming for x seconds", false, "protoman_level" )

    // REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
    register_event("ResetHUD","newRound","b")
    register_event("Damage", "proto_damage", "b", "2!0")
    // INIT
    register_srvcmd("protoman_init", "protoman_init")
    shRegHeroInit(gHeroName, "protoman_init")

    // CHECK SOME BUTTONS
    set_task(0.01,"check_attack",0,"",0,"b")
    set_task(0.01,"check_two_buttons",0,"",0,"b")
    set_task(0.01,"check_move_buttons",0,"",0,"b")

    // DEFAULT THE CVARS
    register_cvar("protoman_delay", "8.0")
    register_cvar("protoman_chance", "0.25")
 }
 //----------------------------------------------------------------------------------------------
 public protoman_init()
 {
    new temp[128]    
    // First Argument is an id
    read_argv(1,temp,5)
    new id=str_to_num(temp)
    // 2nd Argument is 0 or 1 depending on whether the id has proto
    read_argv(2,temp,5)
    new hasPowers=str_to_num(temp)
    gHasProtoPower[id]=(hasPowers!=0)
    protoDelay[id]=get_cvar_float("protoman_delay")

    // Got to remove the powers if he is not Protoman
    if ( !hasPowers ){
        uninvis(id)
    }
    //Give Powers to the Protoman
    if ( hasPowers )
    set_task(protoDelay[id],"invis",id)
 }

 public newRound(id)
 {
    new parm[1]
    parm[0]=id  
    if ( is_user_alive(id) && gHasProtoPower[id] == true ) {
        set_task(protoDelay[id],"invis",id)
    }
    set_task(1.0,"sethealth",id,parm,1)
 }
 
 public sethealth(parm[])
{
    new id=parm[0]
    playerhealth[id]=get_user_health(id)+HPNO
    set_user_health(id, playerhealth[id])
}

 public invis(id) {
    if ( gProtoShield[id] != true )
    {
         client_print(id, print_chat, "[SH](Protoman): You have a chance to absorb projectiles.")
         gProtoShield[id] = true
    
    }
 }

 public uninvis(id) {
    if ( gProtoShield[id] != false )
    {        
        client_print(id, print_chat, "[SH](Protoman): No longer impervious to projectiles.")
        gProtoShield[id] = false
         }
 }

 public check_attack() {

    for(new i = 1; i <= get_maxplayers(); ++i) {
        if (is_user_alive(i)) {
            if ((get_user_button(i)&IN_ATTACK) && gHasProtoPower[i]) {
                uninvis(i)
            }
            else if (!(get_user_button(i)&IN_ATTACK) && gHasProtoPower[i]) {
                set_task(protoDelay[i],"invis",i)
            }
        }
    }
    return PLUGIN_CONTINUE
 }

 public check_two_buttons() {

    for(new i = 1; i <= get_maxplayers(); ++i) {
        if (is_user_alive(i) || gHasProtoPower[i] ) {
            if (get_user_button(i)&IN_USE || get_user_button(i)&IN_ATTACK2) {
                uninvis(i)
            }
        }
    }
    return PLUGIN_CONTINUE
 }

 public check_move_buttons() {
    for(new i = 1; i <= get_maxplayers(); ++i)
    {
        if (is_user_alive(i) && gHasProtoPower[i] == true )
        {
            if (get_user_button(i)&IN_BACK || get_user_button(i)&IN_MOVELEFT || get_user_button(i)&IN_MOVERIGHT || get_user_button(i)&IN_FORWARD || get_user_button(i)&IN_RUN )
            {
                uninvis(i)
            }
        }
    }
    return PLUGIN_CONTINUE
 }
 
public proto_damage(id) {
    if (gProtoShield[id]) {
        new damage = read_data(2)
        new weapon, bodypart, attacker = get_user_attacker(id, weapon, bodypart)
        if (attacker!=id && weapon!=CSW_KNIFE) playerhealth[id] -= damage
        new randNum = random_num(0, 100)
        if (get_user_health(id) < playerhealth[id] && (get_cvar_float("protoman_chance") * 100 >= randNum)) 
            {
            set_user_health(id, playerhealth[id])
            new message[128]
            format(message, 127, "Protoman deflected the projectile!" )
            set_hudmessage(0,120,255,-1.0,1.0,0,0.25,1.0,0.0,0.0,4)
            show_hudmessage(id, message)
            }
        }
 }
-edit #3- This is not a fixed release. I got a version working that involved an ambiguous loop and check that were being tastked every .1 seconds. however, I tried following the suggestions yang gave me below, and I've been frustrated with failure.

I believe everything is working properly - except my set_task call. My set_tasks are executing immediately, and not 8 seconds in the future.

Yang I'm hoping you'll prolly be able to look at it and tell me whats wrong :-D.

Any help is appreciated.

Yang if you read this, also jump to page 2 of this thread and read my next code chunklet.

Last edited by heliumdream; 10-30-2006 at 00:36.
heliumdream is offline