Raised This Month: $ Target: $400
 0% 

When surviving the round, get more HP


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
D o o m
Veteran Member
Join Date: Sep 2005
Location: Germany
Old 05-16-2008 , 15:03   When surviving the round, get more HP
Reply With Quote #1

Hello together

I'll try to do a hero for new player.

The hero should give the player who has it a specific amount of HP every round he survives.
1 round surviving = +25HP
2 rounds surviving = +50HP
3 rounds surviving = +75HP
...

I think I did something wrong with the loop..

Hopefully you can help me

Code:
/* CVARS - copy and paste to shconfig.cfg

// Beginner
beginner_level 0
beginner_health 25
beginner_maxrounds 25

*/

#include <amxmodx>
#include <superheromod>

// GLOBAL VARIABLES
new gHeroName[]="Beginner"
new bool:gHasBeginnerPower[SH_MAXSLOTS+1]
new bool:gDied[SH_MAXSLOTS+1]
new bool:gPowerUsed[SH_MAXSLOTS+1]
//----------------------------------------------------------------------------------------------
public plugin_init()
{
	// Plugin Info
	register_plugin("SUPERHERO Beginner","1.0","-]Tical2k[- DooM")

	// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
	register_cvar("beginner_level", "0" )
	register_cvar("beginner_health", "25")
	register_cvar("beginner_maxrounds", "25")

	// FIRE THE EVENT TO CREATE THIS SUPERHERO!
	shCreateHero(gHeroName, "More HP", "You will gain every round you survive HP", false, "beginner_level" )

	// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
	// INIT
	register_srvcmd("beginner_init", "beginner_init")
	shRegHeroInit(gHeroName, "beginner_init")
	// DEATH
	register_event("DeathMsg", "beginner_death", "a")
	// NEW ROUND
	register_event("ResetHUD","newRound","b")
}
//----------------------------------------------------------------------------------------------
public beginner_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)

	gHasBeginnerPower[id] = (hasPowers!=0)
}
//----------------------------------------------------------------------------------------------
public beginner_death()
{
	new id = read_data(2)

	gDied[id] = true
	remove_task(id)
}
//----------------------------------------------------------------------------------------------
public newRound(id)
{
	gPowerUsed[id] = false

	if(gDied[id] == false && gPowerUsed[id] == false) {
	new i
	while ( i < get_cvar_num("beginner_maxrounds") ) {
	new parm[2]
	parm[0] = id
	parm[1] = i
	i = i+1
	set_task(0.9, "beginner_addHP", 0, parm, 1)
	}
	gPowerUsed[id] = true
	} else {
	gDied[id] = false
	}
}
//----------------------------------------------------------------------------------------------
public beginner_addHP(parm[])
{
	new id = parm[0]
	new multi = parm[1]

	new HPamount = get_cvar_num("beginner_health") * multi
	new currentHP = get_user_health(id)
	new MaxHP = HPamount + currentHP

	shAddHPs(id, HPamount, MaxHP)
}
//----------------------------------------------------------------------------------------------
*EDIT*
The current problem is: You get 7600HP if you survive a round...
__________________
Heroes
:+: Deadpool :+:

Last edited by D o o m; 05-16-2008 at 15:08.
D o o m is offline
G-Dog
Senior Member
Join Date: Dec 2005
Location: Thunderstorm Central
Old 05-16-2008 , 20:35   Re: When surviving the round, get more HP
Reply With Quote #2

thats because of the while loop in newround event, the way you have it it will execute the addhp 25 times. It would be better to use a global to store round count.
Code:
/* CVARS - copy and paste to shconfig.cfg

// Beginner
beginner_level 0
beginner_health 25
beginner_maxrounds 25

*/

#include <amxmodx>
#include <superheromod>

// GLOBAL VARIABLES
new gHeroName[]="Beginner"
new bool:gHasBeginnerPower[SH_MAXSLOTS+1]
new bool:gDied[SH_MAXSLOTS+1]
new gUsed[SH_MAXSLOTS+1]
//pcvars
new cvar_bonus, cvar_round
//----------------------------------------------------------------------------------------------
public plugin_init()
{
	// Plugin Info
	register_plugin("SUPERHERO Beginner","1.0","-]Tical2k[- DooM")

	// DO NOT EDIT THIS FILE TO CHANGE CVARS, USE THE SHCONFIG.CFG
	register_cvar("beginner_level", "0" )
	cvar_bonus = register_cvar("beginner_health", "25")
	cvar_round = register_cvar("beginner_maxrounds", "25")

	// FIRE THE EVENT TO CREATE THIS SUPERHERO!
	shCreateHero(gHeroName, "More HP", "You will gain every round you survive HP", false, "beginner_level" )

	// REGISTER EVENTS THIS HERO WILL RESPOND TO! (AND SERVER COMMANDS)
	// INIT
	register_srvcmd("beginner_init", "beginner_init")
	shRegHeroInit(gHeroName, "beginner_init")
	// DEATH
	register_event("DeathMsg", "beginner_death", "a")
	// NEW ROUND
	register_event("ResetHUD","newRound","b")
}
//----------------------------------------------------------------------------------------------
public beginner_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)

	gHasBeginnerPower[id] = (hasPowers!=0)
}
//----------------------------------------------------------------------------------------------
public beginner_death()
{
	new id = read_data(2)

	gDied[id] = true
	gUsed[id] = 0
	remove_task(id)
}
//----------------------------------------------------------------------------------------------
public newRound(id)
{			
	if( gDied[id] == false ) {
		if( gUsed[id]+1 < get_pcvar_num(cvar_round) ) gUsed[id]++
			
		new parm[2]
		parm[0] = id
		parm[1] = gUsed[id]
		set_task(0.9, "beginner_addHP", 0, parm, 1)
	}
	gDied[id] = false
}
//----------------------------------------------------------------------------------------------
public beginner_addHP(parm[])
{
	new id = parm[0]
	new multi = parm[1]

	new HPamount = get_pcvar_num(cvar_bonus) * multi
	new currentHP = get_user_health(id)
	new MaxHP = HPamount + currentHP

	shAddHPs(id, HPamount, MaxHP)
}
//--------------------------
though in this case it doesn't matter much "register_event("ResetHUD","newRound","b" )" gets called each time that a person spawns. For future refrence you may wanna take a look here.
__________________
If at first you don't succeed, then skydiving isn't for you.
G-Dog is offline
Send a message via AIM to G-Dog
D o o m
Veteran Member
Join Date: Sep 2005
Location: Germany
Old 05-16-2008 , 22:28   Re: When surviving the round, get more HP
Reply With Quote #3

Thank you
It works now like it should ;)

Another question: When should I call a command if I wanna have it loaded before you die.
Like saving the weapons you currently wear when you die..

If you use the death event it's too late, isn't it?

The right command should be get_user_weapon(id,ammo,clip).
__________________
Heroes
:+: Deadpool :+:
D o o m is offline
G-Dog
Senior Member
Join Date: Dec 2005
Location: Thunderstorm Central
Old 05-17-2008 , 04:35   Re: When surviving the round, get more HP
Reply With Quote #4

you could always store the weapon globably during curweapon event and then on death check it. Otherwise I'm not really sure, it depends on what you want to do.
__________________
If at first you don't succeed, then skydiving isn't for you.
G-Dog is offline
Send a message via AIM to G-Dog
D o o m
Veteran Member
Join Date: Sep 2005
Location: Germany
Old 05-18-2008 , 18:17   Re: When surviving the round, get more HP
Reply With Quote #5

I just wanna save the weapons of the round and when you die you should get it in the next round

Your advice should work with this idea, so thanks again *g*
Maybe I should begin to start just requesting a hero instead of "doing it myself"..
__________________
Heroes
:+: Deadpool :+:
D o o m 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 00:22.


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