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

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 - 65 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
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 #4

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 #5

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 #6

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-05-2020 , 02:56   Re: Restore boss plugin trouble
Reply With Quote #7

Can I have some example code? I am really bad at it.
Hoto Cocoa is offline
Hoto Cocoa
Senior Member
Join Date: Jun 2018
Location: Somewhere
Old 02-08-2020 , 09:07   Re: Restore boss plugin trouble
Reply With Quote #8

Well I guess restore boss's health is still a problem in FF2.
Hoto Cocoa is offline
Hoto Cocoa
Senior Member
Join Date: Jun 2018
Location: Somewhere
Old 02-08-2020 , 09:19   Re: Restore boss plugin trouble
Reply With Quote #9

It would be good if we can restore like
Code:
TargetHealthSet = BossMaxHealth * BossLivesLeft + BossNowHealth +Playerdamage
I have read a heal boss subplugin in M7's subplugin and it looks like this:
Code:
if(selfheal)
	{
		new Selfhealth = FF2_GetBossHealth(boss);
		new Selfmaxhealth = FF2_GetBossMaxHealth(boss);
				
		Selfhealth = RoundToCeil(Selfhealth + (Selfmaxhealth * healing));
		if(Selfhealth > Selfmaxhealth)
		{
			Selfhealth = Selfmaxhealth;
		}
				
		FF2_SetBossHealth(boss, Selfhealth);
	}
However those codes I borrowed will still make boss lose all the health it left. I don't know how FF2 works with boss's lives. Because FF2_SetBossMaxHealth can only get 1 lives but I have to count those lives * MaxHealth to get the actually number I want. And for the god of coding the Health become negative for some reasons.

Edit:
If I have to set boss's health with more than 2 lives then I have to plus those lives * maxhealth..

Edit2:
Code:
int Healthtoset, MaxHealthWithLives;
		MaxHealthWithLives = FF2_GetBossMaxHealth(BossIndex) * FF2_GetBossMaxLives(BossIndex);
		Healthtoset = FF2_GetBossMaxHealth(BossIndex) * (CurLives - 1) + CurHealth + CurDamage;
		if(Healthtoset > MaxHealthWithLives)
		{
			Healthtoset = MaxHealthWithLives
			FF2_SetBossHealth(BossIndex, Healthtoset);
                        PrintToChatAll("Boss get fully heal back");
			respawn[client] = false;
			return Plugin_Handled;
		}
		FF2_SetBossHealth(BossIndex, Healthtoset);
Try this and boss will always get Healthtoset = MaxHealthWithLives which is a full heal.

Edit3:
Code:
public Action Command_Seeheal (int client, int args)
{
	int Bossdehealth, Bossdemaxhealth;
	Bossdehealth = FF2_GetBossHealth(BossIndex);
	Bossdemaxhealth = FF2_GetBossMaxHealth(BossIndex);
	PrintToChat(client, "BossHealth is:%d", Bossdehealth);
	PrintToChat(client, "BossMaxHealth is:%d", Bossdemaxhealth);
}
So what you know is that BossMaxHealth(FF2_GetBossMaxHealth) is only for 1 live but BossHealth is for the full health of all lives.
Sometime it's that simple...
I will open another thread for this plugin.

Last edited by Hoto Cocoa; 02-08-2020 at 11:07. Reason: edit
Hoto Cocoa 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 06:22.


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