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

FF2 Restore boss plugin trouble


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hoto Cocoa
Senior Member
Join Date: Jun 2018
Location: Somewhere
Old 02-04-2020 , 09:13   Restore boss plugin trouble
Reply With Quote #1

Hi. I am making a plugin that allow player with the o flag can respawn themselves and restore the boss with the damage they dealt. But the boss will become 0 after 1 use respawn. Can anyone would like to help me? I am bad at coding.

Code:
public Action Command_spawn (int client, int args)
{			
	new Selfhealth = FF2_GetBossHealth();
	new Selfmaxhealth = FF2_GetBossMaxHealth();
	//new Selflive = FF2_GetBossLives();
	//new Selfmaxlive = FF2_GetBossMaxLives();
	new playerdamage = FF2_GetClientDamage(client);
	
	if (IsPlayerAlive(client))
	{
		CPrintToChat(client,"{white}[{purple}FF2{white}]You are still alive~",client);
		return Plugin_Handled;
	}
	if (respawn[client] == 1)
	{
			CPrintToChat(client,"{white}[{purple}FF2{white}]You have already used your respawn chance.",client);
			return Plugin_Handled;
	}
	TF2_RespawnPlayer(client);
	Selfhealth = RoundToCeil(Selfhealth + playerdamage);
	if(Selfhealth > Selfmaxhealth)
	{
			Selfhealth = Selfmaxhealth;
	}
	FF2_SetBossHealth(0,Selfhealth);
	//FF2_SetBossLives(bossindex,Selflive);
	CPrintToChat(client,"{white}[{purple}FF2{white}]You have respawned~",client);
	CPrintToChatAll("{white}[{purple}FF2{white}]%N has respawn and restore boss with %d HP!", client, playerdamage);
    respawn[client] = 1;
    return Plugin_Handled;
}
Another thing is if the boss has 2 or more lives their health will be set to 0 when one use the respawn.
Attached Files
File Type: sp Get Plugin or Get Source (respawnvip2.sp - 64 views - 3.2 KB)

Last edited by Hoto Cocoa; 02-04-2020 at 09:15.
Hoto Cocoa is offline
Batfoxkid
Senior Member
Join Date: Nov 2018
Location: ''On the map''
Old 02-04-2020 , 11:00   Re: Restore boss plugin trouble
Reply With Quote #2

- RoundToCeil isn't needed as both values are integers
- Boss max health is only for one life, you can multiply it by the boss's max lives
- You have client in your formatting when it's not needed
- new should be int for new syntax
__________________
Batfoxkid is offline
Hoto Cocoa
Senior Member
Join Date: Jun 2018
Location: Somewhere
Old 02-05-2020 , 00:07   Re: Restore boss plugin trouble
Reply With Quote #3

Quote:
Originally Posted by Batfoxkid View Post
- RoundToCeil isn't needed as both values are integers
- Boss max health is only for one life, you can multiply it by the boss's max lives
- You have client in your formatting when it's not needed
- new should be int for new syntax
Allright, but if there's a life loss ability wouldn't it broke those abilities?
I tried to get boss's max lives using FF2_GetBossMaxLives but it need boss's index. So I use FF2_GetBossIndex(FF2_GetBossUserId(0)) but will make a Array index out-of-bounds (index 66, limit 66) in error log and broke the plugin.
And I still don't know why Selfhealth will become 0 when boss has more than 1 live.
My friend make the respawn plugin for me but he don't know much about FF2 so I have to improve it myself.
Hoto Cocoa is offline
Hoto Cocoa
Senior Member
Join Date: Jun 2018
Location: Somewhere
Old 02-05-2020 , 02:56   Re: Restore boss plugin trouble
Reply With Quote #4

Can I have some example code? I am really bad at it.
Hoto Cocoa is offline
Batfoxkid
Senior Member
Join Date: Nov 2018
Location: ''On the map''
Old 02-05-2020 , 10:50   Re: Restore boss plugin trouble
Reply With Quote #5

Quote:
Originally Posted by Hoto Cocoa View Post
Allright, but if there's a life loss ability wouldn't it broke those abilities?
I tried to get boss's max lives using FF2_GetBossMaxLives but it need boss's index. So I use FF2_GetBossIndex(FF2_GetBossUserId(0)) but will make a Array index out-of-bounds (index 66, limit 66) in error log and broke the plugin.
And I still don't know why Selfhealth will become 0 when boss has more than 1 live.
My friend make the respawn plugin for me but he don't know much about FF2 so I have to improve it myself.
If you want to get the primary boss, the boss always is 0. So FF2_GetBossMaxLives(0)
__________________
Batfoxkid is offline
Hoto Cocoa
Senior Member
Join Date: Jun 2018
Location: Somewhere
Old 02-07-2020 , 03:23   Re: Restore boss plugin trouble
Reply With Quote #6

Quote:
Originally Posted by Batfoxkid View Post
If you want to get the primary boss, the boss always is 0. So FF2_GetBossMaxLives(0)
I am f*ck. Still cannot get the result I want.
Code:
Selfhealth = Selfhealth + playerdamage
	Selflive = Selflive - 1.0
	Selfhealth = Selfhealth + playerdamage + Selfmaxhealth * Selflive
	Selfmaxhealth = Selfmaxhealth * Selfmaxlive
		if(Selfhealth > Selfmaxhealth)
		{
				Selfhealth = Selfmaxhealth;
		} 
		
	FF2_SetBossHealth(0,Selfhealth);
Somtime it trigger the if(Selfhealth > Selfmaxhealth) so that boss get a full health of 2 lives. Sometime boss's health become 0 wtf....
Sometime selfhelth is negative wtf. And boss got instant dead

Last edited by Hoto Cocoa; 02-07-2020 at 03:47.
Hoto Cocoa is offline
WhiteFalcon
Member
Join Date: Nov 2019
Old 02-07-2020 , 09:08   Re: Restore boss plugin trouble
Reply With Quote #7

Code:
int BossIndex;
bool respawn[MAXPLAYERS+1];

public void On_RoundStart(Event hevent, const char[] name, bool dontBroadcast)
{
	for(int n=1; n <= MaxClients; n++)
	{
		if(!IsClientInGame(n))	continue;
		respawn[n]=true;
	}
	GetBossIndex();
}

public void GetBossIndex()
{
	BossIndex = 0;
	for (int client = 1; client <= MaxClients; client++)
	{
		if(!IsClientInGame(client))	continue;
		int boss = FF2_GetBossIndex(client);
		if (boss < 0)	continue;
		BossIndex = boss;
		break;
	}
}
public Action Command_spawn (int client, int args)
{
	if(!IsClientInGame(client))
	{
		//InGame Only
		return Plugin_Handled;
	}
	if(FF2_GetRoundState() != 1)
	{
		//Round Is not in progress "yet"
		return Plugin_Handled;
	}
	static int CurHealth, CurDamage, CurLives;
	CurLives = FF2_GetBossLives(BossIndex);
	CurHealth = FF2_GetBossHealth(BossIndex);
	CurDamage = FF2_GetClientDamage(client);
	if(IsPlayerAlive(client))
	{
		//You are alive
		return Plugin_Handled;
	}
	if(!respawn[client])
	{
		//Used your spawn ticket
		return Plugin_Handled;
	}
	if(CurHealth <= 0 || CurLives <= 0)
	{
		//boss already dead
		return Plugin_Handled;
	}
	TF2_RespawnPlayer(client);
	if(CurDamage <=0)
	{
		//no damage therefore no restore
		return Plugin_Handled;
	}
	if(FF2_GetBossMaxLives(BossIndex) > 1)
	{
		int CalcDmg, Lives;
		CalcDmg = CurDamage;
		for(int n= 1; n <= FF2_GetBossMaxLives(BossIndex); n++)
		{
			if(CalcDmg > FF2_GetBossMaxHealth(BossIndex))
			{
				CalcDmg -= FF2_GetBossMaxHealth(BossIndex);
				Lives++;
			} else break;
		}
		FF2_SetBossLives(BossIndex, CurLives  + Lives);
		FF2_SetBossHealth(BossIndex, FF2_GetBossMaxHealth(BossIndex) - CalcDmg);
		//restore lives wasted by this client 
		//and health
		respawn[client] = false;
		return Plugin_Handled;
	}
	FF2_SetBossHealth(BossIndex, CurHealth + CurDamage);
	//all done
	respawn[client] = false;
	return Plugin_Handled;
}

Last edited by WhiteFalcon; 02-07-2020 at 09:51. Reason: wait wat
WhiteFalcon is offline
Hoto Cocoa
Senior Member
Join Date: Jun 2018
Location: Somewhere
Old 02-07-2020 , 22:55   Re: Restore boss plugin trouble
Reply With Quote #8

Quote:
Originally Posted by WhiteFalcon View Post
Code:
int BossIndex;
bool respawn[MAXPLAYERS+1];

public void On_RoundStart(Event hevent, const char[] name, bool dontBroadcast)
{
	for(int n=1; n <= MaxClients; n++)
	{
		if(!IsClientInGame(n))	continue;
		respawn[n]=true;
	}
	GetBossIndex();
}

public void GetBossIndex()
{
	BossIndex = 0;
	for (int client = 1; client <= MaxClients; client++)
	{
		if(!IsClientInGame(client))	continue;
		int boss = FF2_GetBossIndex(client);
		if (boss < 0)	continue;
		BossIndex = boss;
		break;
	}
}
public Action Command_spawn (int client, int args)
{
	if(!IsClientInGame(client))
	{
		//InGame Only
		return Plugin_Handled;
	}
	if(FF2_GetRoundState() != 1)
	{
		//Round Is not in progress "yet"
		return Plugin_Handled;
	}
	static int CurHealth, CurDamage, CurLives;
	CurLives = FF2_GetBossLives(BossIndex);
	CurHealth = FF2_GetBossHealth(BossIndex);
	CurDamage = FF2_GetClientDamage(client);
	if(IsPlayerAlive(client))
	{
		//You are alive
		return Plugin_Handled;
	}
	if(!respawn[client])
	{
		//Used your spawn ticket
		return Plugin_Handled;
	}
	if(CurHealth <= 0 || CurLives <= 0)
	{
		//boss already dead
		return Plugin_Handled;
	}
	TF2_RespawnPlayer(client);
	if(CurDamage <=0)
	{
		//no damage therefore no restore
		return Plugin_Handled;
	}
	if(FF2_GetBossMaxLives(BossIndex) > 1)
	{
		int CalcDmg, Lives;
		CalcDmg = CurDamage;
		for(int n= 1; n <= FF2_GetBossMaxLives(BossIndex); n++)
		{
			if(CalcDmg > FF2_GetBossMaxHealth(BossIndex))
			{
				CalcDmg -= FF2_GetBossMaxHealth(BossIndex);
				Lives++;
			} else break;
		}
		FF2_SetBossLives(BossIndex, CurLives  + Lives);
		FF2_SetBossHealth(BossIndex, FF2_GetBossMaxHealth(BossIndex) - CalcDmg);
		//restore lives wasted by this client 
		//and health
		respawn[client] = false;
		return Plugin_Handled;
	}
	FF2_SetBossHealth(BossIndex, CurHealth + CurDamage);
	//all done
	respawn[client] = false;
	return Plugin_Handled;
}
Reason: wait wat
Ummmmm
Hoto Cocoa is offline
WhiteFalcon
Member
Join Date: Nov 2019
Old 02-08-2020 , 01:42   Re: Restore boss plugin trouble
Reply With Quote #9

Quote:
Originally Posted by Hoto Cocoa View Post
Reason: wait wat
Ummmmm
Ignore that.
I forgot to add in my previous post Int BossIndex and changing FF2_SetBossHealth(BossIndex, FF2_GetBossMaxHealth(BossIndex) - CalcDmg);.
sorryyy!!

Last edited by WhiteFalcon; 02-08-2020 at 01:47. Reason: misspell.
WhiteFalcon is offline
Hoto Cocoa
Senior Member
Join Date: Jun 2018
Location: Somewhere
Old 02-08-2020 , 09:06   Re: Restore boss plugin trouble
Reply With Quote #10

Quote:
Originally Posted by WhiteFalcon View Post
Ignore that.
I forgot to add in my previous post Int BossIndex and changing FF2_SetBossHealth(BossIndex, FF2_GetBossMaxHealth(BossIndex) - CalcDmg);.
sorryyy!!
Tried. Boss will still lose all the health with extra lives and become negative health.
Hoto Cocoa is offline
Reply


Thread Tools
Display Modes

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 14:29.


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