Raised This Month: $51 Target: $400
 12% 

Need help with hero scripting (SOLVED)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
josko
Member
Join Date: Dec 2008
Old 11-12-2020 , 10:28   Need help with hero scripting (SOLVED)
Reply With Quote #1

Hi!

I have been working on a hero that is supposed to get healed when he is getting hit, so pretty much the opposite from dracula!


Code:
// Mutant!

/* CVARS - copy and paste to shconfig.cfg
//Mutant
mutant_level 1
mutant_pctperlev 0.01	//chance of getting healed when being hit

*/

#include <amxmod>
#include <fun>
#include <superheromod>

// GLOBAL VARIABLES
new gHeroName[]="Mutant"
new bool:HasMutant[SH_MAXSLOTS+1]
new PlayersLevel2[SH_MAXSLOTS+1]
new PlayersMaxHealth2[SH_MAXSLOTS+1]
//----------------------------------------------------------------------------------------------
public plugin_init()
{
	register_plugin("SUPERHERO Mutant","2.0","Mutants will rule the world!")

	// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
	register_cvar("mutant_level", "1" )
	register_cvar("mutant_pctperlev", "0.01" )

	shCreateHero(gHeroName, "Damage Absorbtion", "Gain HP by getting shot by people - More HP per level!", false, "mutant_level" )

	// init.
	register_srvcmd("mutant_init", "mutant_init")
	shRegHeroInit(gHeroName, "mutant_init")

	// LEVELS
	register_srvcmd("mutant_levels", "mutant_levels")
	shRegLevels(gHeroName, "mutant_levels")

	// GET MORE ENERGY!
	register_event("Damage", "mutant_damage", "b", "2!0")

	// Makes superhero tell mutant a players max health
	register_srvcmd("mutant_maxhealth", "mutant_maxhealth")
	shRegMaxHealth(gHeroName, "mutant_maxhealth")
}
//----------------------------------------------------------------------------------------------
public mutant_init()
{
	// First Argument is an id
	new temp[6]
	read_argv(1,temp,5)
	new id=str_to_num(temp)

	// 2nd Argument is 0 or 1 depending on whether the id has mutant skills
	read_argv(2,temp,5)
	new hasPowers=str_to_num(temp)

	HasMutant[id] = (hasPowers!=0)
}
//----------------------------------------------------------------------------------------------
public mutant_levels()
{
	new id[5]
	new lev[5]

	read_argv(1, id, 4)
	read_argv(2, lev, 4)

	PlayersLevel2[str_to_num(id)] = str_to_num(lev)
}
//----------------------------------------------------------------------------------------------
public mutant_damage(id)
{

	if ( !shModActive() || !is_user_connected(id) ) return PLUGIN_CONTINUE

	new damage = read_data(2)
	new weapon, bodypart, attacker = get_user_attacker(id, weapon, bodypart)

	if ( attacker <= 0 || attacker > SH_MAXSLOTS ) return PLUGIN_CONTINUE

	if ( HasMutant[id] && is_user_alive(attacker) && id != attacker ) {
		// Add some HP back!
		//new giveHPs2 = floatround(damage * get_pcvar_float(CvarMultiplier2) * PlayersLevel2[attacker])
		new giveHPs2 = floatround( ( PlayersLevel2[id] * get_cvar_float("mutant_pctperlev") ) * damage )
		
		if (giveHPs2 > 0)
		{
			new alphanum = damage * 2
			if (alphanum > 200)
				alphanum = 200
			else if (alphanum < 40)
				alphanum = 40
			setScreenFlash(victim, 255, 10, 10, 10, alphanum)  //Red Screen Flash
			shAddHPs(attacker, giveHPs2, PlayersMaxHealth2[attacker])
		}

	}
	return PLUGIN_CONTINUE
}
//----------------------------------------------------------------------------------------------
public mutant_maxhealth()
{
	new id[6]
	new health[9]

	read_argv(1, id, 5)
	read_argv(2, health, 8)

	PlayersMaxHealth2[str_to_num(id)] = str_to_num(health)
}
//----------------------------------------------------------------------------------------------
public client_connect(id)
{
	HasMutant[id] = false
}
//----------------------------------------------------------------------------------------------

But it dosn't work. I suspect this will heal the enemy player instead that hurts me but I want it to heal me instead when a enemy player hurts me xD

Any help would be greatly appreciated!

Last edited by josko; 11-14-2020 at 09:16.
josko is offline
josko
Member
Join Date: Dec 2008
Old 11-14-2020 , 09:22   Re: Need help with hero scripting (SOLVED)
Reply With Quote #2

I have now solved it. Hero works like I want it to, being the opposite of Dracula: Healing when getting shot/knifed!



Code:
// Reverse DRACULA!

/* CVARS - copy and paste to shconfig.cfg

//Reverse Dracula
rdracula_level 0
rdracula_pctperlev 0.03	//What percent of damage to give back per level of player

*/

// v1.18m - vittu - m for modified version of Dracula for use with Blade and/or Longshot
// v1.17.5 - JTP - Added code to allow you to regen to your max heatlh

#include <amxmodx>
#include <superheromod>

// GLOBAL VARIABLES
new HeroName[] = "Reverse Dracula"
new bool:HasrDracula[SH_MAXSLOTS+1]
new rPlayersLevel[SH_MAXSLOTS+1]
new rPlayersMaxHealth[SH_MAXSLOTS+1]
new rCvarMultiplier
//----------------------------------------------------------------------------------------------
public plugin_init()
{
	// Plugin Info
	register_plugin("SUPERHERO Reverse Dracula", "1.18m", "{HOJ} Batman/JTP10181")

	// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
	register_cvar("rdracula_level", "0")
	rCvarMultiplier = register_cvar("rdracula_pctperlev", "0.03")

	// FIRE THE EVENT TO CREATE THIS SUPERHERO!
	shCreateHero(HeroName, "Reverse Healing", "Gain HP by getting shot by people - More HPs per level", false, "rdracula_level")

	// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
	// INIT
	register_srvcmd("rdracula_init", "rdracula_init")
	shRegHeroInit(HeroName, "rdracula_init")

	// LEVELS
	register_srvcmd("rdracula_levels", "rdracula_levels")
	shRegLevels(HeroName, "rdracula_levels")

	// GET MORE ENERGY!
	register_event("Damage", "rdracula_damage", "b", "2!0")

	// Makes superhero tell reverse dracula a players max health
	register_srvcmd("rdracula_maxhealth", "rdracula_maxhealth")
	shRegMaxHealth(HeroName, "rdracula_maxhealth")
}
//----------------------------------------------------------------------------------------------
public rdracula_init()
{
	// First Argument is an id
	new temp[6]
	read_argv(1, temp, 5)
	new id = str_to_num(temp)

	// 2nd Argument is 0 or 1 depending on whether the id has the hero
	read_argv(2, temp, 5)
	new hasPowers = str_to_num(temp)

	rPlayersMaxHealth[id] = 100

	HasrDracula[id] = (hasPowers!=0)
}
//----------------------------------------------------------------------------------------------
public rdracula_levels()
{
	new id[5]
	new lev[5]

	read_argv(1, id, 4)
	read_argv(2, lev, 4)

	rPlayersLevel[str_to_num(id)] = str_to_num(lev)
}
//----------------------------------------------------------------------------------------------
public rdracula_damage(id)
{
	if ( !shModActive() || !is_user_connected(id) )
		return

	new damage = read_data(2)
	//new attacker = get_user_attacker(id)

	//if ( attacker <= 0 || attacker > SH_MAXSLOTS || attacker == id )
		//return

	if ( HasrDracula[id] && is_user_alive(id) )
		rdracula_suckblood(id, damage)
}
//----------------------------------------------------------------------------------------------
// Leave this public so it can be called with a forward from Longshot
public rdracula_suckblood(id, damage)
{
	if ( shModActive() && HasrDracula[id] && is_user_alive(id) )
	{
		// Add some HP back!
		new rgiveHPs = floatround(damage * get_pcvar_float(rCvarMultiplier) * rPlayersLevel[id])

		if ( get_user_health(id) < rPlayersMaxHealth[id] && rgiveHPs > 0 )
		{
			new alphanum = damage * 2
			if (alphanum > 200)
				alphanum = 200
			else if (alphanum < 40)
				alphanum = 40
			setScreenFlash(id, 255, 10, 10, 10, alphanum)  //Red Screen Flash
			shAddHPs(id, rgiveHPs, rPlayersMaxHealth[id])
		}
	}
}
//----------------------------------------------------------------------------------------------
public rdracula_maxhealth()
{
	new id[6]
	new health[9]

	read_argv(1, id, 5)
	read_argv(2, health, 8)

	rPlayersMaxHealth[str_to_num(id)] = str_to_num(health)
}
//----------------------------------------------------------------------------------------------
public client_connect(id)
{
	HasrDracula[id] = false
}
//----------------------------------------------------------------------------------------------
All I had to do was changing from attacker to id but keep damage and remove/comment out some small amount of code.

So I'll just post my fix here incase anyone is interested in it. It's hilarious how hard it is for you to die if you set the chance per level to 0.1 or something!
josko is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:22.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode