Jump to content

Building repair script


Pwn Call

Recommended Posts

So I was thinking of one that would allow you to buy a repair on a building, for example have an object like a mini console be pokable that when poked will repair a building for a price.  Maybe also allow for a custom price as well as a custom repair amount.  So I could change it from 50 credits for 1 health bar, or i could change it to 200 credits for 3 health bars.  

 

Also Adding a sound for when you purchase it and a different sound for when you are denied purchase.

 

Could you also add a setting for allowing a cooldown time?  So you could only purchase it every X amount of seconds or something?

 

Thanks again zunnie!

Link to comment
Share on other sites

Another thought.

Could you add a seperate sound if you are denied purchase because it is still in the cooldown phase?

So three different sounds for when either you are allowed purchase, are denied purchase, or are denied purchase because the cooldown period hasnt expired yet.

Let me know if this is doable.

Link to comment
Share on other sites

  • 1 year later...

Two scripts for the price of one.

 

This script will (*untested*) repair an object (by ID) for a specified amount and trigger a cooldown timer. If the object can't be located (either destroyed or some other error), it will just ignore the poke.

 

Source file: (be sure to include engine.h and scripts.h)

void zbl_Poke_Buy_Repair_Object::Created(GameObject *o){	m_sBuySound = Get_Parameter("Buy_Sound");	m_sDeniedSound = Get_Parameter("Denied_Sound");	m_sInsufficientFunds = Get_Parameter("NoMoney_Sound");	m_sDeniedCooldownSound = Get_Parameter("Cooldown_Denied_Sound");	m_iObjectID = Get_Int_Parameter("ObjectID");	m_iCost = Get_Int_Parameter("Cost");	m_iPlayerType = Get_Int_Parameter("Player_Type");	m_fAmount = Get_Float_Parameter("Amount");        m_fCooldownTimer = Get_Float_Parameter("Cooldown_Timer");}void zbl_Poke_Buy_Repair_Object::Timer_Expired(GameObject *o, int num){	if (num == 5555)	{		EndCooldown();	}}void zbl_Poke_Buy_Repair_Object::Poked(GameObject *o, GameObject *poker){	if (Get_Player_Type(poker) == m_iPlayerType)	{		cPlayer *plr = Find_Player(Get_Player_ID(poker));		if (!plr) return; // probably shouldn't happen. JIC.		GameObject *obj = Commands->Find_Object(m_iObjectID);		if (!obj) return; // flat ignore the poke if the object isn't found.		if (m_bOnCooldown)		{			Create_2D_Sound_Player(poker, m_sDeniedCooldownSound);		}		else if (plr->Purchase_Item(m_iCost))		{			Commands->Apply_Damage(obj, m_fAmount * -1.0f, "Repair", poker);			Create_2D_Sound_Player(poker, m_sBuySound);			BeginCooldown(o);		}		else		{			Create_2D_Sound_Player(poker, m_sInsufficientFunds);		}	}	else	{		Create_2D_Sound_Player(poker, m_sDeniedSound);	}}void zbl_Poke_Buy_Repair_Object_Send_Custom::Created(GameObject *o){	zbl_Poke_Buy_Repair_Object::Created(o); // delegate to base ctor.	m_iSendObjectID = Get_Int_Parameter("Send_Object");	m_iSucceedMessage = Get_Int_Parameter("Succeeded_Message");	m_iDeniedMessage = Get_Int_Parameter("Denied_Message");	m_iNoMoneyMessage = Get_Int_Parameter("NoMoney_Message");	m_iCooldownMessage = Get_Int_Parameter("Cooldown_Message");}void zbl_Poke_Buy_Repair_Object_Send_Custom::Poked(GameObject *o, GameObject *poker){	if (Get_Player_Type(poker) == m_iPlayerType)	{		cPlayer *plr = Find_Player(Get_Player_ID(poker));		if (!plr) return; // probably shouldn't happen. JIC.		GameObject *obj = Commands->Find_Object(m_iObjectID);		if (!obj) return; // flat ignore the poke if the object isn't found.		if (m_bOnCooldown)		{			Create_2D_Sound_Player(poker, m_sDeniedCooldownSound);			Send_Custom(m_iSendObjectID, m_iCooldownMessage, 0, poker);		}		else if (plr->Purchase_Item(m_iCost))		{			Commands->Apply_Damage(obj, m_fAmount * -1.0f, "Repair", poker);			Create_2D_Sound_Player(poker, m_sBuySound);			BeginCooldown(o);			Send_Custom(m_iSendObjectID, m_iSucceedMessage, 0, poker);		}		else		{			Create_2D_Sound_Player(poker, m_sInsufficientFunds);			Send_Custom(m_iSendObjectID, m_iNoMoneyMessage, 0, poker);		}	}	else	{		Create_2D_Sound_Player(poker, m_sDeniedSound);		Send_Custom(m_iSendObjectID, m_iDeniedMessage, 0, poker);	}}

Header file: (3 class declarations)

class zbl_Send_Custom_Base abstract{protected:	void Send_Custom(int ID, int message, int param, GameObject *sender, float delay = 0.0f)	{		GameObject *o = Commands->Find_Object(ID);		if (o)		{			Commands->Send_Custom_Event(sender, o, message, param, delay);		}	}};class zbl_Poke_Buy_Repair_Object : public ScriptImpClass{protected:	bool m_bOnCooldown;	float m_fCooldownTimer;	int m_iPlayerType;	int m_iObjectID;	int m_iCost;	float m_fAmount;	StringClass m_sBuySound;	StringClass m_sDeniedSound;	StringClass m_sInsufficientFunds;	StringClass m_sDeniedCooldownSound;	void BeginCooldown(GameObject *o)	{		m_bOnCooldown = true;		Commands->Start_Timer(o, this, m_fCooldownTimer, 5555);	}	void EndCooldown()	{		m_bOnCooldown = false;	}public:	virtual void Created(GameObject *o);	virtual void Poked(GameObject *o, GameObject *poker);	virtual void Timer_Expired(GameObject *o, int num);};class zbl_Poke_Buy_Repair_Object_Send_Custom : public zbl_Poke_Buy_Repair_Object, zbl_Send_Custom_Base{protected:	int m_iSendObjectID;	int m_iSucceedMessage;	int m_iDeniedMessage;	int m_iNoMoneyMessage;	int m_iCooldownMessage;public:	void Created(GameObject *o);	void Poked(GameObject *o, GameObject *poker);};

Registrant: (including my Register_Script macro)

#define Register_Script(ClassName,Params) ScriptRegistrant<ClassName> ClassName##_Registrant(#ClassName,Params)Register_Script(zbl_Poke_Buy_Repair_Object, "Player_Type:int,Cost:int,ObjectID:int,Amount:float,Cooldown_Timer:float,Buy_Sound:string,Denied_Sound:string,NoMoney_Sound:string,Cooldown_Denied_Sound:string");Register_Script(zbl_Poke_Buy_Repair_Object_Send_Custom, "Player_Type:int,Cost:int,ObjectID:int,Amount:float,Cooldown_Timer:float,Buy_Sound:string,Denied_Sound:string,NoMoney_Sound:string,Cooldown_Denied_Sound:string,Send_Object:int,Succeeded_Message:int,Denied_Message:int,NoMoney_message:int,Cooldown_Message:int");

I won't attach a precompiled scripts.dll this time because it's untested. I'll let you compile it into scripts.dll yourself so you can make changes as necessary.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.