Senior Member
|
10-30-2006
, 00:44
Re: Hero: Protoman (useless)
|
#12
|
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'
* Added support so the 'Casper' hero won't cause interference with health preservation
* Also note about 8 lines below this is a defination 'HPNO 799'. This should be treated as 'additional health'.
*/
#include <amxmod>
#include <superheromod>
// VARIABLES
#define HPNO 799
new gHeroName[]="Protoman"
new bool:gHasProtoPower[SH_MAXSLOTS+1]
new bool:gProtoShield[SH_MAXSLOTS+1]
new playerhealth[SH_MAXSLOTS+1]
new casperHealth
//----------------------------------------------------------------------------------------------
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", "Autoblock all 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")
set_task(0.1,"protoman_loop",0,"",0,"b" )
// DEFAULT THE CVARS
register_cvar("protoman_delay", "8.0")
register_cvar("protoman_chance", "0.25")
//CASPER SUPPORT
if ( !cvar_exists("casper_health") ) register_cvar("casper_health", "300")
casperHealth=get_cvar_num("casper_health")
}
//----------------------------------------------------------------------------------------------
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)
// Got to remove the powers if he is not Protoman
if ( !hasPowers ){
uninvis(id)
//set_user_rendering(id)
}
//Give Powers to the Protoman
if ( hasPowers )
invis(id)
}
public newRound(id)
{
new parm[1]
parm[0]=id
if ( is_user_alive(id) && gHasProtoPower[id] == true ) {
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 )
{
//set_user_rendering(id,kRenderFxGlowShell,255,0,0,kRenderNormal,16)
client_print(id, print_chat, "[SH](Protoman): You have a chance to absorb projectiles.")
gProtoShield[id] = true
}
}
public uninvis(id) {
if ( gProtoShield[id] != false )
{
//set_user_rendering(id,kRenderFxGlowShell,100,100,100,kRenderNormal,16)
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]) {
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 protoman_loop() {
for (new id = 1; id <= SH_MAXSLOTS; id++) {
if (gProtoShield[id] && (get_user_health(id) < playerhealth[id]))
{
new randNum = random_num(0, 100)
new protoChance = floatround(get_cvar_float("protoman_chance") * 100)
client_print(id, print_chat,"[SH](Protoman): protoChance=%d, randNum=%d", protoChance, randNum)
if (protoChance >= 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)
}
else
{
if (get_user_health(id) > casperHealth + 10) playerhealth[id]=get_user_health(id)
}
}
}
}
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
}
}
I ended up re-writing it again, and this is what it came out looking like this time. I added in support for the casper hero, so that it doesn't cause a wierd collision when trying to preserve health.
This code makes the hero work next to flawlessly, only it is not using the protoman_delay cvar anymore, as I could not get it to work alongside the set_task function properly.
It is set up the way it was originally, where protoman is ALWAYS active unless you are moving or shooting. If I can set 'invis' to execute 8 seconds in the future instead of imediately (by using set_task), there will be no more errors or problems. If anyone would please give me a sample line code snippet for a proper set_task function that makes the called routine run x seconds in the future that would be appreicated.
And no I'm not a fucking idiot, it should be something like set_task(8.0,routine_name,id) but that doesn't work! that makes it execute imediately, not 8.0 seconds in the future. Perhaps my syntax is wrong, I think there are more vars to pass to set_task.
|
|