Jump to content
  • 0

HELP, please check my code :)


namerpus18

Question


  • Group:  Members
  • Topic Count:  40
  • Topics Per Day:  0.07
  • Content Count:  102
  • Reputation:   5
  • Joined:  11/15/22
  • Last Seen:  

//===============SOURCE CODE REFERENCE=============
void mob_add_spotted(struct mob_data *md, uint32 char_id) {
	int i;

	//Check if char_id is already logged
	for (i = 0; i < DAMAGELOG_SIZE; i++) {
		if (md->spotted_log[i] == char_id)
			return;
	}

	//Not logged, add char_id to first empty slot
	for (i = 0; i < DAMAGELOG_SIZE; i++) {
		if (md->spotted_log[i] == 0) {
			md->spotted_log[i] = char_id;
			return;
		}
	}
}
//==========CODE I MAKE FROM REFERENCE ABOVE
void mob_add_atker(struct mob_data *md, uint32 char_id) {
	int i;

	//Check if char_id is already logged
	for (i = 0; i < DAMAGELOG_SIZE; i++) {
		if (md->dmglog[i] == char_id)
			return;
	}

	//Not logged, add char_id to first empty slot
	for (i = 0; i < DAMAGELOG_SIZE; i++) {
		if (md->dmglog[i] == 0) {
			md->dmglog[i] = char_id;
			return;
		}
	}
}

Good day everyone,

I am new and still learning in source code and I want to try to make something for my project using lines from the source code itself. 
What I am trying to achieve here is to log char IDs of all those who attacked the monster(MVP). I am focusing this one before proceeding to the next step. Did I make it right?

 

Thank you so much as always, 


EDITED:

Or should I use this one? from pc.ccp
 

void pc_damage_log_add(map_session_data *sd, int id)
{
	uint8 i = 0;

	if (!sd || !id)
		return;

	//Only store new data, don't need to renew the old one with same id
	ARR_FIND(0, DAMAGELOG_SIZE_PC, i, sd->dmglog[i] == id);
	if (i < DAMAGELOG_SIZE_PC)
		return;

	for (i = 0; i < DAMAGELOG_SIZE_PC; i++) {
		if (sd->dmglog[i] == 0) {
			sd->dmglog[i] = id;
			return;
		}
	}
}

 

Edited by namerpus18
Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0

  • Group:  Forum Moderator
  • Topic Count:  44
  • Topics Per Day:  0.01
  • Content Count:  898
  • Reputation:   119
  • Joined:  05/23/12
  • Last Seen:  

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  40
  • Topics Per Day:  0.07
  • Content Count:  102
  • Reputation:   5
  • Joined:  11/15/22
  • Last Seen:  

1 hour ago, Rynbef said:

I have checked it and kinda understand it but not fully as I am not yet familiar to sql structures or parameters but I think its kinda straight forward. From what i see 'mvplog' is a function right? And inside the parentheses are its parameters? 

Uhm regarding the script I made above does it make sense? I just want to know if i understand a little now about source code editing. coz pointers realy confused me most of the time and giving me hard time always.

 

 

EDIT. is there something i can lookup in source code that uses this 'mvplog'? just to figure how to use it

 

Thanks a lot

Edited by namerpus18
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  6
  • Topics Per Day:  0.01
  • Content Count:  42
  • Reputation:   3
  • Joined:  04/11/22
  • Last Seen:  

On 8/15/2023 at 3:00 AM, namerpus18 said:

I have checked it and kinda understand it but not fully as I am not yet familiar to sql structures or parameters but I think its kinda straight forward. From what i see 'mvplog' is a function right? And inside the parentheses are its parameters? 

Uhm regarding the script I made above does it make sense? I just want to know if i understand a little now about source code editing. coz pointers realy confused me most of the time and giving me hard time always.

 

 

EDIT. is there something i can lookup in source code that uses this 'mvplog'? just to figure how to use it

 

Thanks a lot

I think you can focus on what you want to do with the logs as they already exist so you might find something else you could test using it, if I understand your situation maybe try creating a new NPC from scratch that given a MVP ID you tell the last 10 players who hit it 

  • Like 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.01
  • Content Count:  39
  • Reputation:   30
  • Joined:  06/08/23
  • Last Seen:  

better using vector instead array since rA is now c++

  • Like 2
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  40
  • Topics Per Day:  0.07
  • Content Count:  102
  • Reputation:   5
  • Joined:  11/15/22
  • Last Seen:  

8 hours ago, zeusc137 said:

I think you can focus on what you want to do with the logs as they already exist so you might find something else you could test using it, if I understand your situation maybe try creating a new NPC from scratch that given a MVP ID you tell the last 10 players who hit it 

That's quite what I want to achieve. But to tell you what it is exactly, I want to reward all IDs who met a dealt total damage(example: 100,000 dealt total damage) to the MVP aside from MVP reward for top1,top2, and top3. Of course, I need to adjust MVP's HP maybe up to x100 if there are more than 500 players participating.

 

 

EDIT: Actually I think this 'mvplog' thing will do the trick but I need to learn first how to use it coz I don't know yet about functions from SQL.

Edited by namerpus18
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  40
  • Topics Per Day:  0.07
  • Content Count:  102
  • Reputation:   5
  • Joined:  11/15/22
  • Last Seen:  

5 hours ago, Harvin said:

better using vector instead array since rA is now c++

I will read about using vector, thank you. I am still new.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.01
  • Content Count:  39
  • Reputation:   30
  • Joined:  06/08/23
  • Last Seen:  

On 8/17/2023 at 6:15 AM, namerpus18 said:

EDIT: Actually I think this 'mvplog' thing will do the trick but I need to learn first how to use it coz I don't know yet about functions from SQL.

SQL thing is not what you want, you are in right direction, with referencing function of mob_add_spotted or pc_damage_log_add, then if you want to remember the log you need to store it on db sql or beware the mob will be wiped out from memory later on after the mob dead.
 

there is some way to achieve what you want since you want to learn your self, I wouldn't throw some code here, but here some note you may search on search engine to achieve what you want
- vector with struct.
- vector with map (better unordered map I think)
 

oh also dmglog member of mob data is wiped for mvp upon dead

			if( md->get_bosstype() == BOSSTYPE_MVP )
				pc_damage_log_clear(tmpsd[i],md->bl.id);

you need to create your own new member of struct mob data.

my suggestion is create flag for the mob you want to its damage to be logged, then do some regulated rules, like if the player has gone from map or etc2, it will 2 side check, first the mob it self and the player, same with dmglog of currect code, which can you use for reference.

  • Love 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  40
  • Topics Per Day:  0.07
  • Content Count:  102
  • Reputation:   5
  • Joined:  11/15/22
  • Last Seen:  

5 hours ago, Harvin said:

 dmglog member of mob data is wiped for mvp upon dead

oh so data will disappear once the mob die unless i make a separate struct data? about putting it on db sql i still need to check on it if its not too complicated i might consider. 

and about this for loop do you think i can use it too?

 

//found this on exp computation coz im finding a way to use tdmg so I can filter out IDs depending on their tdmg though im not sure if i can use it

double per = (double)md->dmglog[i].dmg/(double)md->tdmg;

=================

 

for(i = 0; i < DAMAGELOG_SIZE && md->dmglog[i].id; i++)   {

//can i filter out IDs based on md->tdmg here?

//and at the same time give reward base on tdmg?

//DAMAGELOG_SIZE is 30 so do i need to change it to 100+ if i want to log more IDs??

}

 

 

 

Thank you so much you helped me so much,

I am checking how to use vector now

Edited by namerpus18
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  40
  • Topics Per Day:  0.07
  • Content Count:  102
  • Reputation:   5
  • Joined:  11/15/22
  • Last Seen:  

On 8/20/2023 at 5:15 PM, Harvin said:

dmglog member of mob data is wiped for mvp upon dead

one last thing. So you mean I cannot pull out md->dmglog[i].id once the monster is dead right?

EDIT: I am guessing i need to struct my own data handling somewhere in log.ccp which i think not possible right now for me. I grasping bit by bit by reading all related lines of several scripts, analyzing small parts that I understand and finding logic behind it. Thanks  a lot

 

Edited by namerpus18
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  3
  • Topics Per Day:  0.01
  • Content Count:  39
  • Reputation:   30
  • Joined:  06/08/23
  • Last Seen:  

On 8/20/2023 at 9:20 PM, namerpus18 said:

for(i = 0; i < DAMAGELOG_SIZE && md->dmglog[i].id; i++)   {

//can i filter out IDs based on md->tdmg here?

//and at the same time give reward base on tdmg?

//DAMAGELOG_SIZE is 30 so do i need to change it to 100+ if i want to log more IDs??

}

I will still talk with vector as base, you can sort the damage with vector easy, you can look up function mob_add_spawn with it code sorting the qty of mob spawn in a map

	// sort spawns by spawn quantity
	std::sort(spawns.begin(), spawns.end(),
		[](const spawn_info & a, const spawn_info & b) -> bool
		{ return a.qty > b.qty; });

 

On 8/20/2023 at 9:20 PM, namerpus18 said:

//DAMAGELOG_SIZE is 30 so do i need to change it to 100+ if i want to log more IDs??

quoted from here https://www.geeksforgeeks.org/vector-in-cpp-stl/

Vectors are the same as dynamic arrays with the ability to resize itself automatically when an element is inserted or deleted

so you don't need to pre defined number to set size on the container.

16 hours ago, namerpus18 said:

one last thing. So you mean I cannot pull out md->dmglog[i].id once the monster is dead right?

for mvp its reset upon dead, so if mvp has rebirth skill, it will reset the logs value. later on will be removed in memory in status.cpp

	if(flag&4) // Delete from memory. (also invokes map removal code)
		unit_free(target,CLR_DEAD);
	else if(flag&2) // remove from map
		unit_remove_map(target,CLR_DEAD);

so you can still get the data of damage log, before it was wiped out from memory, but no longer after. so in case you want to preserve the damage log, you need to save it on sql db

On 8/20/2023 at 9:20 PM, namerpus18 said:

about putting it on db sql i still need to check on it if its not too complicated i might consider. 

its not complicated, you just need consider what you want to log, I think it will be gid of mob, account id, char id, damage

CREATE TABLE IF NOT EXISTS `mob_damage_log` (
  `id` int(11) NOT NULL auto_increment,
  `mob_gid` int(11) NOT NULL default '0',
  `account_id` int(11) NOT NULL default '0',
  `char_id` int(11) NOT NULL default '0',
  `damage` int(10) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `mob_gid` (`mob_gid`),
  KEY `account_id` (`account_id`),
  KEY `char_id` (`char_id`)
) ENGINE=MyISAM;

something like that maybe. and the code would go like this, as the sd, you can get it with map_session_data *sd= map_charid2sd(char_id);

	if( SQL_ERROR == Sql_Query(
		mmysql_handle,
		"INSERT INTO `mob_damage_log`(`mob_gid`,`account_id`,`char_id`,`damage`) VALUES ( '%d', '%d', '%d', '%d' )",
		md->bl.id, sd->status.account_id, sd->status.account_id, damage) ){
		Sql_ShowDebug(mmysql_handle);
		return;
	}

 

  • Love 1
  • MVP 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...