Jump to content
Sign in to follow this  
Klutz

getmapusers - More options

Recommended Posts

Lately i been working to switch from eAthena server to Hercules.

with all the new functions Hercules has i started to build new scripts for my npcs.

 

i found myself searching a lot for lists:

1) Name of people on specific map.

2) Char ID of people on specific map.

3) Account ID of people on specific map.

 

BUILDIN(getmapusers) {
	int16 m;
	int type = 0;
	int users = 0;
	struct s_mapiterator* iter;
	struct map_session_data *sd;
	const char *str;
	str = script_getstr(st,2);
	if( (m=map->mapname2mapid(str))< 0) {
		script_pushint(st,-1);
		return true;
	}
	if (script_hasdata(st,3))
		type = script_getnum(st,3);
	else{
		script_pushint(st,map->list[m].users);
		return true;
	}
	iter = mapit_getallusers();
	for (sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); sd = BL_UCAST(BL_PC, mapit->next(iter))) {
		if (sd->bl.m == m){
			switch (type)
			{
				case 1:
					mapreg->setregstr(reference_uid(script->add_str("$@mapcharname$"), users), sd->status.name);
					break;
				case 2:
					mapreg->setreg(reference_uid(script->add_str("$@mapcharid"), users), sd->status.char_id);
					break;
				case 3:
					mapreg->setreg(reference_uid(script->add_str("$@mapaccountid"), users), sd->status.account_id);
					break;
			}
			users++;
		}
	}
	mapit->free(iter);
	return true;
}



BUILDIN_DEF(getmapusers,"s?"),

 

 

 

 

 

I was wondering if you want to add it to Hercules as a new feature.

 

Regards,

Klutx

Edited by Klutz

Share this post


Link to post
Share on other sites

You can use this :)

 


*getunits(<type>, <variable>, <limit>, "<map>"{, <x1>, <y1>, <x2>, <y2>})

This function searches a whole map or area for units and adds their GID to
the provided <variable> array. It filters units by <type> and stops searching
after <limit> units have been found. Set <limit> to false (0) if you wish to
disable the limit altogether.

Type is the type of unit to search for:

	BL_PC    - Character object
	BL_MOB   - Monster object
	BL_PET   - Pet object
	BL_HOM   - Homunculus object
	BL_MER   - Mercenary object
	BL_IEM   - Item object (item drops)
	BL_SKILL - Skill object (skill fx & sfx)
	BL_NPC   - NPC object
	BL_CHAT  - Chat object
	BL_ELEM  - Elemental object
	BL_CHAR  - Shorthand for (BL_PC|BL_MOB|BL_HOM|BL_MER|BL_ELEM)
	BL_ALL   - Any kind of object

** Do NOT use UNITTYPE_ constants here, they have different values.

Example:

	.@count = getunits((BL_PC | BL_NPC), .@units, false, "prontera");

The above example would search the map "prontera" for all PC and NPC units and
add them to the .@units array, while setting .@count to the amount of units
added to the array (useful in for() loops).

Share this post


Link to post
Share on other sites

 

You can use this :)

 


*getunits(<type>, <variable>, <limit>, "<map>"{, <x1>, <y1>, <x2>, <y2>})

This function searches a whole map or area for units and adds their GID to
the provided <variable> array. It filters units by <type> and stops searching
after <limit> units have been found. Set <limit> to false (0) if you wish to
disable the limit altogether.

Type is the type of unit to search for:

	BL_PC    - Character object
	BL_MOB   - Monster object
	BL_PET   - Pet object
	BL_HOM   - Homunculus object
	BL_MER   - Mercenary object
	BL_IEM   - Item object (item drops)
	BL_SKILL - Skill object (skill fx & sfx)
	BL_NPC   - NPC object
	BL_CHAT  - Chat object
	BL_ELEM  - Elemental object
	BL_CHAR  - Shorthand for (BL_PC|BL_MOB|BL_HOM|BL_MER|BL_ELEM)
	BL_ALL   - Any kind of object

** Do NOT use UNITTYPE_ constants here, they have different values.

Example:

	.@count = getunits((BL_PC | BL_NPC), .@units, false, "prontera");

The above example would search the map "prontera" for all PC and NPC units and
add them to the .@units array, while setting .@count to the amount of units
added to the array (useful in for() loops).

Very useful info, i didn't know it! and before I tried to approach this implementing the addrid command from rathena, but as this is official (of hercules) is better i guess.

Share this post


Link to post
Share on other sites

^^

If you're trying to add addrid you should read this http://herc.ws/board/topic/3285-script-command-addrid/

And the cons about using such a command :)

 

 

 


Will provide sexual favours to the person who can get this working for latest herc. Can pay money too.


This kind of addrid was rejected from Hercules too. Because this can be dangerous. It can have unexpected behavior when the player is attached to other npc and you call addrid, either that script would stop executing(think doing some quest, the variables changed but you didn't got reward), or the script with addrid would behave oddly(rid not attached but script continued to run)
More info: https://github.com/HerculesWS/Hercules/pull/211

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

Loading...
Sign in to follow this  

×
×
  • Create New...

Important Information

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