Jump to content

Join our Discord

Talk to other users and have a great time
Discord Server

Welcome to our Community

Click here to get your Exiled Bot license
Donation Store
Sign in to follow this  
Jarvis101

re: totem timer function

Recommended Posts

So I was checking out the requests forum and decided to write up some functions you can use for delayed and conditional skill usage.

It was late when I wrote this so it could probably be made more efficient.

* Notes

- the program was written as standalone to debug

- couts were used for debugging/place holding purposes. Remove them when applying.

- I did not include any file streams as 1) i don't have access to source code, and 2) I'm sure you guys want to handle the usage of config files

-will probably look better as a class and could probably use children, however it's late and I just want to get this posted.

//Declaring my headers
#include "stdafx.h"
#include <iostream>
#include <ctime>
#include <string>

//Declaring my namespace
using namespace std;

//Declaring my functions
void TotTime(); // ******** This function needs to be copy and pasted for each skill that uses a timer,
				// then edited to match skill parameters
void Timer(int seconds);
void useSkill(); //function holding placeholder code for calling upon the function to use skills
void SkillSlot1(); //determines how to use the skill in slot x. all skillslot functions other than 1 are
				   //blank, copy paste code and edit as needed for other skills.
void SkillSlot2(); //determines how to use the skill in slot x
void SkillSlot3(); //determines how to use the skill in slot x
void SkillSlot4(); //determines how to use the skill in slot x
void SkillSlot5(); //determines how to use the skill in slot x
void SkillSlot6(); //determines how to use the skill in slot x
void SkillSlot7(); //determines how to use the skill in slot x
void SkillSlot8(); //determines how to use the skill in slot x
void FunctionThatUsesSkills(); //a function that determines when to use certain skills. Probably redundant
bool shouldibeused(); //funcion that determines whether a skill should be used or not and returns a bool
void attackspeed(); //probably a misdirecting function name. Used to delay the time between attacks
void initvariables(); //initialization and/or loading of variables
bool Totemdeath(); // A function to break the timer, and an example for totem death.

//Declaring my public variables
float atkspd;
bool takeaction;
float totemuptime;
bool totemhasdied;
bool checktotemdeath;
//skill id's used to determine method of use in skillslotx()
int skill[8];


//Main
int _tmain(int argc, _TCHAR* argv[])
{
	initvariables(); //initialize variables and/or load configurations
	FunctionThatUsesSkills();
	return 0;
}

//Functions

void initvariables()
{
	atkspd = 1;
	bool takeaction = true;
	totemuptime = 10;
	totemhasdied = false;
	skill[0] = 1;
	skill[1] = 0;
	skill[2] = 0;
	skill[3] = 0;
	skill[4] = 0;
	skill[5] = 0;
	skill[6] = 0;
	skill[7] = 0;
}


void FunctionThatUsesSkills()
{
	bool Skill1params; // This variable is to dictate whether the situation warrents
						  // the usage of a skill
	Skill1params = shouldibeused();
	while (Skill1params == true)
	{
		SkillSlot1();
	}	
}

bool shouldibeused()
{
// An example of parameters you would use
	bool Incombat = true; // automatically assuming skill should be used
	if (Incombat = true)
	{
		return true;
	}
	else
	{
		return false;
	}
}
void SkillSlot1()
{
	bool isaninstantskill;
	int skillcheck;
	skillcheck = skill[0]; //the latter variable (skill1) will need to be changed when copying this function
 // You would arrange the skill ID's to have instant id's to be numbered below non
 // instant ID's
	if (skillcheck == 0)
	{
		isaninstantskill = true;
	}
	else if  (skillcheck == 1)
	{
		isaninstantskill = false;
	}
	else
	{
		cout << "error" << endl;
	}
// End of determining type of skill, begin determining what to do with skill
	if (isaninstantskill == true)
	{
		while (takeaction = true)
		{
			takeaction = false;
			useSkill();
			attackspeed();
		}
	}
	else if (isaninstantskill == false)
	{
		// ******** This section of code needs to be edited to match skill parameters

		if (skillcheck == 1)
		{
			while(takeaction = true)
			{
				takeaction = false;
				useSkill();
				TotTime(); //wait for next cast
			}			
		}

		// ******** This section of code needs to be edited to match skill parameters
	}
}

void SkillSlot2(){}
void SkillSlot3(){}
void SkillSlot4(){}
void SkillSlot5(){}
void SkillSlot6(){}
void SkillSlot7(){}
void SkillSlot8(){}

void useSkill()
{
		cout << "this is the normal code to use a skill" <<  endl;
}

void TotTime()
{
	checktotemdeath = true;
	for (float uptime = totemuptime; uptime!= 0; uptime--) //int uptime = x; where x is the time 
				  										   //inbetween casts
	{
		Timer(1);
		if(Totemdeath()==true)
		{
			break;
		}
	}
	takeaction = true;

}

bool Totemdeath() 
{
	if(checktotemdeath == true)
	{
		if(totemhasdied == true)
		{
			return true;
		}
	}
	else
	{
		return false;
	}
}


void attackspeed() 
{
	for (float uptime = atkspd; uptime!=0; uptime--) //int uptime = x; where x is the time inbetween casts
	{
		Timer(1);
	}
	takeaction = true;
}

void Timer(int seconds)
{
	clock_t totemtimer;
	totemtimer = clock() + seconds * CLOCKS_PER_SEC;
	while (clock() < totemtimer) {}
}

Hope you guys can use this.

Share this post


Link to post
Share on other sites
Sign in to follow this  

×
×
  • Create New...