View Single Post
The Art of War
Veteran Member
Join Date: Dec 2009
Location: Sweden Rock Festival
Old 02-18-2011 , 02:26   Re: Hulk level limit
Reply With Quote #2

http://forums.alliedmods.net/showthr...ght=robin+hood

PHP Code:
// ROBIN HOOD! - Steal money from rich players

/* CVARS - copy and paste to shconfig.cfg

//Robin Hood
robinhood_level 0
robinhood_pctstealmoney 0.15        //What percent of money to give back per shot on player
robinhood_maxlevel 7            //max level allowed to use this power

*/

/*
* v1.1 - Fr33m@n - 8/7/10
*      - cvars name changed due to robin_level already used in Robin hero
*      - Updated to be SH 1.2.0 compliant, removed amx compatibility.
*      - Code cleaned up.
*/

#include <superheromod>

// GLOBAL VARIABLES
new gHeroID
new const gHeroName[] = "Robin Hood"
new bool:gHasRobinHood[SH_MAXSLOTS+1]
new 
bool:gMustDrop[SH_MAXSLOTS+1]
new 
gPcvarPctStealMoneygPcvarMaxLvl
//----------------------------------------------------------------------------------------------
public plugin_init()
{
    
// Plugin Info
    
register_plugin("SUPERHERO Robin Hood""1.1""Fr33m@n")

    
// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
    
new pcvarLevel register_cvar("robinhood_level""0")
    
gPcvarPctStealMoney register_cvar("robinhood_pctstealmoney""0.15")
    
gPcvarMaxLvl register_cvar("robinhood_maxlevel""7")

    
// FIRE THE EVENT TO CREATE THIS SUPERHERO!
    
gHeroID sh_create_hero(gHeroNamepcvarLevel)
    
sh_set_hero_info(gHeroID"Steal money from rich players""Take a percent of victim's money by attacking it")
}
//----------------------------------------------------------------------------------------------
public sh_hero_init(idheroIDmode)
{
    if ( 
gHeroID != heroID ) return

    switch(
mode) {
        case 
SH_HERO_ADD: {
            
gHasRobinHood[id] = true
            robinhood_checklevel
(id)
        }

        case 
SH_HERO_DROP: {
            
gHasRobinHood[id] = false
            gMustDrop
[id] = false
        
}
    }

    
sh_debug_message(id1"%s %s"gHeroNamemode "ADDED" "DROPPED")
}
//----------------------------------------------------------------------------------------------
public client_connect(id)
{
    
gHasRobinHood[id] = false
    gMustDrop
[id] = false
}
//----------------------------------------------------------------------------------------------
public sh_client_spawn(id)
{
    
robinhood_checklevel(id)
}
//----------------------------------------------------------------------------------------------
robinhood_checklevel(id)
{
    new 
iMaxLvl get_pcvar_num(gPcvarMaxLvl)
    if ( (
gHasRobinHood[id] && sh_get_user_lvl(id) > iMaxLvl) || gMustDrop[id] ) {
        
gMustDrop[id] = true
        gHasRobinHood
[id] = false
        sh_chat_message
(idgHeroID"You must be level %d or lower to use this hero"iMaxLvl)
        
client_cmd(id"say drop %s"gHeroName)
    }
}
//----------------------------------------------------------------------------------------------
public client_damage(attackervictimdamagewpnindex)
{
    if ( !
sh_is_active() ) return
    if ( !
is_user_connected(victim) || !is_user_alive(attacker) ) return

    
// Should nades not count? maybe remove them later
    
if ( gHasRobinHood[attacker] && CSW_P228 <= wpnindex <= CSW_P90 ) {
        
robinhood_stealmoney(attackervictim)
    }
}
//----------------------------------------------------------------------------------------------
// Leave this public so it can be called with a forward from Longshot
public robinhood_stealmoney(attackervictim)
{
    if ( 
sh_is_active() && gHasRobinHood[attacker] && is_user_alive(attacker) )
    {
        new 
iVictimMoney cs_get_user_money(victim)
        new 
iStealMoney floatround(iVictimMoney get_pcvar_float(gPcvarPctStealMoney))

        
// Remove the money from the victim
        
cs_set_user_money(victimiVictimMoney iStealMoney1)
        
        
// Give the money to the attacker
        
cs_set_user_money(attackercs_get_user_money(attacker) + iStealMoney1)
    }
}
//---------------------------------------------------------------------------------------------- 
Look at the
Code:
robinhood_checklevel(id)
forward, where he has placed the
Code:
robinhood_checklevel(id)
forward calls (for example in sh_client_spawn(id))

and how he registers the cvar and so on.
__________________
The Art of War is offline