View Single Post
Author Message
heliumdream
Senior Member
Join Date: Aug 2006
Old 09-02-2006 , 20:11   Admin Only Script Help
Reply With Quote #1

Okay I searched the threads, and found a hero that already had Admin Only *I used Uncle Sam*. I ripped the code and formulated this script. Initially I thought it was working, but some players ended up bypassing the admin only tag by mashing over and over again trying to select it and magically they got it. My routines to drop the hero while they are using it do not work! I put the admin_check routine everywhere I could bloody think of and still no dice! I would appreciate anyones ideas as to how I could fix this:

-edit- I appologize for not commenting my code properly

Code:
#include <amxmod>
#include <superheromod>

// Juggernaut - made by Mydas

/* CVARS
juggernaut_level 9 - his level
*/

#define HPNO 2048
// GLOBAL VARIABLES
new gHeroName[]="Juggernaut Part II"
new bool:gHasJuggernautPowers[SH_MAXSLOTS+1]
new bool:gJuggernautSelected [SH_MAXSLOTS+1]
new playerhealth[SH_MAXSLOTS+1]
new bool:tocheck[SH_MAXSLOTS+1]
new bool:protection[SH_MAXSLOTS+1]

public plugin_init()
{
  // Plugin Info
    register_plugin("SUPERHERO Juggernaut part II","1.0","Mydas")

    register_cvar("juggernaut_level", "9")
    register_cvar("juggernaut_adminflag","a")
    shCreateHero(gHeroName, "Invulnerability", "Almost permanent resistance to damage not caused by weapons (fall damage, lasers)", false, "juggernaut_level" )
    register_srvcmd("juggernaut_init", "juggernaut_init")
    shRegHeroInit(gHeroName, "juggernaut_init")

    register_event("ResetHUD","newRound","b")
    register_event("Damage", "juggernaut_damage", "b", "2!0")
    register_event("ResetHUD", "newSpawn", "b")
    register_event("DeathMsg", "newDeath", "a")

    set_task(0.1,"juggernaut_loop",0,"",0,"b" )
}

public juggernaut_init() 
{ 
    new temp[6] 

    read_argv(1, temp, 5) 
    new id = str_to_num(temp) 

    read_argv(2, temp, 5) 
    new hasPowers = str_to_num(temp) 
    gHasJuggernautPowers[id] = (hasPowers!=0)
    gJuggernautSelected[id]=gHasJuggernautPowers[id]
    
    juggernaut_admincheck(id)

    if (gHasJuggernautPowers[id]) {
        client_print(id, print_center, "You will get Juggernaut next time you spawn")
        tocheck[id]=true
    } else {
        tocheck[id]=false
        protection[id]=false
        if (get_user_health(id) >= HPNO) set_user_health(id, get_user_health(id)-HPNO)
    }
} 

public newRound(id)
{
  juggernaut_admincheck(id)
  if (!gHasJuggernautPowers[id]) return
  if (tocheck[id]) tocheck[id]=false
  new parm[1]
  parm[0]=id
  //set_user_health(id, 100)
  set_task(1.0,"sethealth",id,parm,1)
}

public newSpawn(id)
{
        juggernaut_admincheck(id)
}

public newDeath()
{
    new id = read_data(2)

    // In case server does not allow drop alive check on death
    juggernaut_admincheck(id)
}

public sethealth(parm[])
{
    new id=parm[0]
    playerhealth[id]=get_user_health(id)+HPNO
    protection[id]=true
    set_user_health(id, playerhealth[id])
}

public juggernaut_loop()
{
    for (new id = 1; id <= SH_MAXSLOTS; id++) {
        if (gHasJuggernautPowers[id] && protection[id] && is_user_alive(id) && hasRoundStarted() && !tocheck[id]){
            juggernaut_admincheck(id)
            //client_print(id,print_center,"life : %i-%i",get_user_health(id), playerhealth[id]) //debugging purposes
            //if ((get_user_health(id) <= HPNO) && (get_user_health(id) > playerhealth[id]-HPNO)) playerhealth[id] = get_user_health(id)+HPNO
            if (get_user_health(id) < playerhealth[id]) set_user_health(id, playerhealth[id])
            
          }
    }
}

public juggernaut_damage(id) 
{
    new damage = read_data(2)
    new weapon, bodypart, attacker = get_user_attacker(id, weapon, bodypart)
    if (attacker <= 0 || attacker > SH_MAXSLOTS || !gHasJuggernautPowers[id] || !is_user_alive(id) || !protection[id]) return 
    if (attacker!=id && !tocheck[id]) playerhealth[id] -= damage
    if (playerhealth[id] <= HPNO+10) {
        set_user_health(id, random_num(1,10))
        protection[id]=false
    }
}

public juggernaut_admincheck(id)
{    
    new accessLevel[10]
    get_cvar_string("juggernaut_adminflag", accessLevel, 9)

    if ( gJuggernautSelected[id] &&  !(get_user_flags(id)&read_flags(accessLevel)) ) {
        client_print(id, print_chat, "[SH](%s) **Admin Only** You are not authorized to use this hero", gHeroName)
        gJuggernautSelected[id] = false
        client_cmd(id, "say drop %s", gHeroName)
    }
}
Thanks in Advance
-hd

Last edited by heliumdream; 09-02-2006 at 20:14.
heliumdream is offline