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 gPcvarPctStealMoney, gPcvarMaxLvl
//----------------------------------------------------------------------------------------------
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(gHeroName, pcvarLevel)
sh_set_hero_info(gHeroID, "Steal money from rich players", "Take a percent of victim's money by attacking it")
}
//----------------------------------------------------------------------------------------------
public sh_hero_init(id, heroID, mode)
{
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(id, 1, "%s %s", gHeroName, mode ? "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(id, gHeroID, "You must be level %d or lower to use this hero", iMaxLvl)
client_cmd(id, "say drop %s", gHeroName)
}
}
//----------------------------------------------------------------------------------------------
public client_damage(attacker, victim, damage, wpnindex)
{
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(attacker, victim)
}
}
//----------------------------------------------------------------------------------------------
// Leave this public so it can be called with a forward from Longshot
public robinhood_stealmoney(attacker, victim)
{
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(victim, iVictimMoney - iStealMoney, 1)
// Give the money to the attacker
cs_set_user_money(attacker, cs_get_user_money(attacker) + iStealMoney, 1)
}
}
//----------------------------------------------------------------------------------------------
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.
__________________