Jump to content
  • 0

Getmapusers


Decimal

Question


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  44
  • Reputation:   5
  • Joined:  02/07/12
  • Last Seen:  

Hi,

I would like to know if is there something like "getmapusers" for "party" and "guild" where you'll be able to view how many "party" and "guild" are currently located on the specified map.

See below an example of how I'll use the syntax:

if (getmapusers("pvp_n_1-5") == 0) {
announce "All players failed to survive.",0;
end;
}

Edited by Decimal
Link to comment
Share on other sites

7 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  72
  • Topics Per Day:  0.02
  • Content Count:  2997
  • Reputation:   1130
  • Joined:  05/27/12
  • Last Seen:  

No. You can use getpartymember and loop through the party array if you don't want to do an SQL query, but that's the only way for guilds.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  737
  • Reputation:   216
  • Joined:  11/29/11
  • Last Seen:  

There ain't a buildin one from what I know but you may do it in script even if that mean it would be less efficient.

Erf I just look and I didn't even found how you'll fetch users on map. (You sure can display there name but probably can treat that...)

Anyway a pseudo code woul be :

getuseronmap();
while(users_iterator.hasnext() ){
 cur_user = users_iterator.next();
 ARR_FIND(0, nbusersonmap, i, (guildid[i] == cur_user.guilid)); //did we already found this guild ?
 if(i<nbpersononmap) continue; //already in here
 else {
 ARR_FIND(0, nbusersonmap, i, (guildid[i]==0) ); //register guilid in a new spot
 guildid[i] = cur_user.guildid;
   guildcount++;
 }
}
script_pushint(st, guildcount); //send number of guild in here

but that jsut a pseudo code I'll suggest you request that on work on it. (You can either do that in src or npc but you'll need to fetch all user on map for the npc part)).

You can use that old fonction I add for that :

/*==========================================
* Template methode, [Lighta]
* 0 mapusers number returned as int
* 1 mapusers char id returned as $@mapcharid[]
* 2 mapuser char name returned as $@mapcharname$[]
*------------------------------------------*/
BUILDIN_FUNC(getmapusers2)
{
   const char *str = script_getstr(st, 2);
   int map_id = 0, users = 0;
   int type = script_getnum(st, 3);
   struct s_mapiterator* iter;
   TBL_PC *it_sd;

   if ((map_id = map_mapname2mapid(str)) <= 0)   //map not found
   {
    TBL_PC *sd = script_rid2sd(st);
    map_id = sd->bl.m;
   }
   if (!map_id) return -1;

   iter = mapit_getallusers();
   for (it_sd = (TBL_PC*) mapit_first(iter); mapit_exists(iter); it_sd = (TBL_PC*) mapit_next(iter))
   {
    if (it_sd->bl.m != map_id)
	    continue;
    if (pc_has_permission(it_sd, PC_PERM_HIDE_SESSION) && pc_isinvisible(it_sd))
	    continue; // skip hidden GMs (with !hide)
    switch (type)
    {
    case 1:
	    mapreg_setreg(reference_uid(add_str("$@mapcharid"), users), it_sd->status.char_id);
	    break;
    case 2:
	    mapreg_setregstr(reference_uid(add_str("$@mapcharname$"), users), it_sd->status.name);
	    break;
	    //add more type here
    }
    users++;
   }
   mapit_free(iter);
   if (type == 0) script_pushint(st, users);

   return 0;
}

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  93
  • Topics Per Day:  0.02
  • Content Count:  10013
  • Reputation:   2348
  • Joined:  10/28/11
  • Last Seen:  

for party....

getpartymember getcharid(1);
set .@Count,0;
for( set .@i,0; .@i < $@partymembercount; set .@i,.@i + 1 ){
getmapxy( .@Map$,.@X,.@Y,0,$@partymembername$[.@i];
if( .@Map$ == "MAPNAME" )
 set .@Count,.@Count + 1;
}
announce "Total of "+.@Count+" Player in this Map.",0;
end;

for guild....use SQL since we didnt add a official getguildmember command in rAthena..

or maybe you can do it yourself..

just copy the code for getpartymember..and edit it so it return the value you want....

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  737
  • Reputation:   216
  • Joined:  11/29/11
  • Last Seen:  

For what I understand he wanted to know how many different party and guild are on map not how many people from this party... well maybe I misinterpret.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  9
  • Topics Per Day:  0.00
  • Content Count:  44
  • Reputation:   5
  • Joined:  02/07/12
  • Last Seen:  

Exactly, I would like to know how many party/guild are on the map. Not how many members from the party/guild is online on the map.

getuseronmap();
while(users_iterator.hasnext() ){
 cur_user = users_iterator.next();
 ARR_FIND(0, nbusersonmap, i, (guildid[i] == cur_user.guilid)); //did we already found this guild ?
 if(i<nbpersononmap) continue; //already in here
 else {
 ARR_FIND(0, nbusersonmap, i, (guildid[i]==0) ); //register guilid in a new spot
 guildid[i] = cur_user.guildid;
guildcount++;
 }
}
script_pushint(st, guildcount); //send number of guild in here

I couldn't understand well. Do I have two options? The above one would work with the Script (doesn't seem like a Script though) only while the below one would work with the Source?

/*==========================================
* Template methode, [Lighta]
* 0 mapusers number returned as int
* 1 mapusers char id returned as $@mapcharid[]
* 2 mapuser char name returned as $@mapcharname$[]
*------------------------------------------*/
BUILDIN_FUNC(getmapusers2)
{
const char *str = script_getstr(st, 2);
int map_id = 0, users = 0;
int type = script_getnum(st, 3);
struct s_mapiterator* iter;
TBL_PC *it_sd;

if ((map_id = map_mapname2mapid(str)) <= 0)   //map not found
{
	TBL_PC *sd = script_rid2sd(st);
	map_id = sd->bl.m;
}
if (!map_id) return -1;

iter = mapit_getallusers();
for (it_sd = (TBL_PC*) mapit_first(iter); mapit_exists(iter); it_sd = (TBL_PC*) mapit_next(iter))
{
	if (it_sd->bl.m != map_id)
		continue;
	if (pc_has_permission(it_sd, PC_PERM_HIDE_SESSION) && pc_isinvisible(it_sd))
		continue; // skip hidden GMs (with !hide)
	switch (type)
	{
	case 1:
		mapreg_setreg(reference_uid(add_str("$@mapcharid"), users), it_sd->status.char_id);
		break;
	case 2:
		mapreg_setregstr(reference_uid(add_str("$@mapcharname$"), users), it_sd->status.name);
		break;
		//add more type here
	}
	users++;
}
mapit_free(iter);
if (type == 0) script_pushint(st, users);

return 0;
}

And how exactly would I use the command? Would the syntax be like this:

if (getmapusers2("pvp_n_1-5") == 0) {
announce "All players failed to survive.",0;
end;
}

And what would getmapusers2 (Party or Guild?) be exactly? Sorry for my ignorance, I am a real newbie at all this.

:P

Edited by Decimal
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  16
  • Topics Per Day:  0.00
  • Content Count:  737
  • Reputation:   216
  • Joined:  11/29/11
  • Last Seen:  

Well if I was you I'd add some type in getmapusers2 to fit what u want, it's the easiest way :



/*==========================================
* Get info of users on a map, [Lighta]
* getmapusers2,"mapname",type;
* type :
*   0 mapusers count returned as int
*   1 mapusers char id returned as $@mapcharid[]
*   2 mapuser char name returned as $@mapcharname$[]
*   3 nb different guild in map
*   4 nb different party in map
*------------------------------------------*/
BUILDIN_FUNC(getmapusers2)
{
const char *str = script_getstr(st, 2);
int map_id = 0, users = 0, i=0;
int type = script_getnum(st, 3);
struct s_mapiterator* iter;
TBL_PC *it_sd;
int tmp[128]; //todo malloc me ?
int count=0; //return value

if ((map_id = map_mapname2mapid(str)) <= 0)   //map not found
{
		TBL_PC *sd = script_rid2sd(st);
		map_id = sd->bl.m;
}
if (!map_id) return -1;

iter = mapit_getallusers();
for (it_sd = (TBL_PC*) mapit_first(iter); mapit_exists(iter); it_sd = (TBL_PC*) mapit_next(iter))
{
		if (it_sd->bl.m != map_id)
				continue;
		if (pc_has_permission(it_sd, PC_PERM_HIDE_SESSION) && pc_isinvisible(it_sd))
				continue; // skip hidden GMs (with !hide)
		switch (type)
		{
		case 0: //nb user on map (may add extra cond here)
				count++;
				break;
		case 1: //get charid
				mapreg_setreg(reference_uid(add_str("$@mapcharid"), users), it_sd->status.char_id);
				break;
		case 2: //get names
				mapreg_setregstr(reference_uid(add_str("$@mapcharname$"), users), it_sd->status.name);
				break;
		case 3:  //get nb of diff guilds
				ARR_FIND(0, users, i, (tmp[i]==it_sd->status.guild_id) ); //search if guilid already here	
				if(i<users) continue; //already in here
				else {
					   ARR_FIND(0, users, i, (tmp[i]==0) ); //register guilid in a new spot
					   tmp[i] = it_sd->status.guild_id;
					   count++;
				}
				break;
		case 4: //get nb of diff team
				ARR_FIND(0, users, i, (tmp[i]==it_sd->status.party_id) ); //search if party already here  
				if(i<users) continue; //already in here
				else {
					   ARR_FIND(0, users, i, (tmp[i]==0) ); //register guilid in a new spot
					   tmp[i] = it_sd->status.party_id;
					   count++;
				}
				break;
		//add more type here
		}
		users++;
}
mapit_free(iter);
script_pushint(st, count);
return 0;
}

So for example of use for guild and party the syntaxe would be :

.@nbguild = getmapusers2,"prontera",3;

.@nbparty = getmapusers2,"prontera",4;

Code is compilable but I didn't test it, and he may have a probleme after founding more then 128 guild/party on map..

For the kind of syntaxe with only the name as parameter you'll need to slipt party and guild section in 2 command otherwise we can't differentiate them. good luck =)

(oh or I just think you may want both result at once.. (well just use some other setreg))

ah oups doing this by npc would be something like :

getmapuser "prontera",2;

for(.@i=0; .@i<getarraysize($@mapcharname$); .@i++) {

.@it_guild = getcharid(2,$@mapcharname$[.@i]);

//reste blabla loop it to see if exist etc

}

sql based would be something like :

SELECT count( DISTINCT `guild_id` )

FROM `char`

WHERE `last_map` = "prontera" AND `online` =1

but I wont recommand you that since last_map ain't refresh enough for what u want.

Edited by Lighta
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...