Thread: PvP stats
View Single Post
  #10  
Old 09-15-2005, 11:06 PM
Magoth78
Discordant
 
Join Date: Jun 2003
Posts: 345
Default

Last line of database.cpp
Code:
bool Database::UpdatePVPPoints(const char* killername, int klevel, int kguildid, const char* loosername, int llevel, int lguildid, int pvppoints)
{
	// debug
	printf("Starting the update...\n");
	// end debug
	char errbuf[MYSQL_ERRMSG_SIZE];
    char *query = 0;
	int32	affected_rows = 0;
	//printf("Variables ok...\n");
	if (!RunQuery(query, MakeAnyLenString(&query, 
		"INSERT INTO pvpstats (killername,klevel,kguildid,loosername,llevel,lguildid,pvppoints) VALUES ('%s','%i','%i','%s','%i','%i','%i')",killername,klevel,kguildid,loosername,llevel,lguildid,pvppoints),
		errbuf, 0, &affected_rows)); {
			//printf("Error Updating the points......\n");
		safe_delete_array(query);
		return false;
		}
	//printf("UpdatePVPPoints: %s,%i,%i,%s,%i,%i,%i\n",killername,klevel,kguildid,loosername,llevel,lguildid,pvppoints);
	safe_delete_array(query);
	return true;
}

add this in database.h:
Code:
bool UpdatePVPPoints(const char* killername, int klevel, int kguildid, const char* loosername, int llevel, int lguildid, int pvppoints);
and in attack.cpp just after the lines:
Code:
//		if(!IsLD())//Todo: make it so an LDed client leaves corpse if its enabled
//			MakeCorpse(exploss);
add this:
Code:
if(GetGM() || !IsBecomeNPC() && other != NULL && other->IsClient())
 // added GetGM() for debug purposes
	{
			const char* killername = other->GetName();
			int klevel = other->GetLevel();
			int kguildid = other->CastToClient()->GuildDBID();
			const char* loosername = this->GetName();
			int llevel = this->GetLevel();
			int lguildid = this->CastToClient()->GuildDBID();
			int pvppoints;
			int diflevel = klevel - llevel;
			
			if(diflevel >= 10)
				pvppoints = 10;

			if(diflevel < 10 && diflevel >= 7)
				pvppoints = 25;

			if(diflevel < 7 && diflevel >= 4)
				pvppoints = 40;

			if(diflevel < 4 && diflevel >= 1)
				pvppoints = 50;
				
			if(diflevel == 0)
				pvppoints = 60;

			if(diflevel <= -1 && diflevel > -4 )
				pvppoints = 80;

			if(diflevel <= -4 && diflevel > -7)
				pvppoints = 100;

			if(diflevel < -7)
				pvppoints = 120;

			if(kguildid == NULL){
				kguildid = 0;
			}
			if(lguildid == NULL){
				lguildid = 0;
			}
			//// let's calcul points of the group

				if(other->CastToClient()->IsGrouped()) {
					Group* group = entity_list.GetGroupByClient(other->CastToClient());
						for(int i=0;i<MAX_GROUP_MEMBERS;i++) {
								if(group->members[i] != NULL) {
									Client* c = group->members[i]->CastToClient();
									pvppoints = llevel / 4;
									c->Message(0,"You have gained %i points in this fight!",pvppoints);
									database.UpdatePVPPoints(c->GetName(),c->GetLevel(),c->GuildDBID(),loosername,llevel,lguildid,pvppoints);
								}
							}
						}
		
				else{
						printf("Variables: killername = %s, klevel = %i, kguildid = %i, loosername = %s, llevel = %i, lguildid = %i, pvppoints = %i\n",
						killername,klevel,kguildid,loosername,llevel,lguildid,pvppoints);

						database.UpdatePVPPoints(killername,klevel,kguildid,loosername,llevel,lguildid,pvppoints);
						//LogFile->write(EQEMuLog::Error, "%i,%i,%i,%s,%i,%i,%i"), killerid,klevel,kguildid,looserid,llevel,lguildid,pvppoints;
						other->CastToClient()->Message(0,"You have gained %i points in this fight!",pvppoints);
						printf("PVP: %s has been killed by %s\n",loosername,killername);
						//this->CastToClient()->Message(0,"You have been killed by an enemy. Xp lost!");
				    }
			

			
	}
yes I know that the code is ugly, but my skills in c++ are still low


You will can notice that all pvppoints are previously declared. (it's what i wanted to do on empire). You can change them, or add a formula for the points check.

You will have to create a new table in your db called "pvpstats" with the columns: id(int(11)auto_increment), killername(varchar(64)),klevel(int(11)),kguilid(in t(11)),loosername(varchar(64)),llevel(int(11)),lgu ildid(int(11)),pvppoints(int(11)),date(timestamp(C URRENT_TIMESTAMP on update CURRENT_TIMESTAMP)).


Mag
__________________
User's projects:
-- Original EMPIRE I/II and Factions! servers
-- Web GM Portal
-- EQoffline/bots

Last edited by Magoth78; 09-16-2005 at 07:09 AM..
Reply With Quote