Jump to content

mobexists() = Checks if Mob Exists/Spawns Naturally


joecalis

Recommended Posts


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  64
  • Reputation:   40
  • Joined:  03/26/12
  • Last Seen:  

Hallo, hallo everyone.

This is going to be my very first release here, so I hope it can be useful.

 

So basically I made a script command that checks whether the monster stated

exists in the mob_db or spawns naturally (Some monsters doesn't spawn naturally but listed on the mob_db). So here's how it works.

if(mobexists(1002)){	// It works with mob name too "mobexists("Poring")"
	mes "Yes its a Poring, of course exists foo!";
	close;
} else {
	mes "No that monster does not exist or maybe it just doesn't spawn.";
	mes "Meh! What ever floats your boat...";
	close;
}

 

If the mob stated exists it returns a value of 1 if not it returns -1 or 0.

 

So if you want this script command here's what you do:

Step 1 - open src\map\script.c

Step 2 - Find this line.

BUILDIN_FUNC(checkvending)

 

Step 3 - Right above it, just slap this code right in so it would look like this.

Raw Code

BUILDIN_FUNC(mobexists)	//added code start
{
	struct mob_db *mob, *mob_array[MAX_SEARCH];
	const char* mob_id = script_getstr(st,2);
	int count;
	int i, j, k;

	if (!mob_id){
	ShowError("buildin_mobexists: No Monster ID set.");
	return -1;
	}
	// If monster identifier/name argument is a name
	if ((i = mobdb_checkid(atoi(mob_id))))
	{
		mob_array[0] = mob_db(i);
		count = 1;
	} else
		count = mobdb_searchname_array(mob_array, MAX_SEARCH, mob_id);
	if (!count) {
		script_pushint(st,-1);
	}
	if (count > MAX_SEARCH) {
		count = MAX_SEARCH;
	}
	for (k = 0; k < count; k++) {
		mob = mob_array[k];
		for (i = 0; i < ARRAYLENGTH(mob->spawn) && mob->spawn[i].qty; i++)
		{
			j = map_mapindex2mapid(mob->spawn[i].mapindex);
			if (j < 0) continue;
		}
		if (i == 0)
		{
			script_pushint(st,-1);
		}
		else
		{
			script_pushint(st,1);
		}
	}
	return 0;
}	//added code end

BUILDIN_FUNC(checkvending) 

 

Step 4 - Find this code.

	BUILDIN_DEF(getmonsterinfo,"ii"), 

 

Step 5 - Right below it slap this code right in too so it would look like this.

	BUILDIN_DEF(getmonsterinfo,"ii"),
	BUILDIN_DEF(mobexists,"i"),	//added code 

 

Step 6 - Save and Recompile and Done.

 

 

So there you go folks, just a little bit of finding and a little slapping here and there and your good to go.

Reply to this thread if you're having any problems/errors.

Edited by joecalis
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  17
  • Topics Per Day:  0.00
  • Content Count:  754
  • Reputation:   186
  • Joined:  05/22/12
  • Last Seen:  

Cheers mate! Good to see new people releasing stuff. :)

Not to disappoint you or anything but this will do the same thing for checking the existence of the mob.

if(strmobinfo(0,1002) != ""){
	mes "Yes its a Poring, of course exists foo!";
	close;
} else {
	mes "No that monster does not exist or maybe it just doesn't spawn.";
	mes "Meh! What ever floats your boat...";
	close;
}
Nonetheless, your code looks good. :)
  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  25
  • Topics Per Day:  0.01
  • Content Count:  251
  • Reputation:   20
  • Joined:  12/22/11
  • Last Seen:  

ihihihi can u create diff for ur mod? :)

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  26
  • Topics Per Day:  0.01
  • Content Count:  331
  • Reputation:   63
  • Joined:  11/29/11
  • Last Seen:  

Its not a custom source(strmobinfo), Its already included in rA

Edited by Dastgir Pojee
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  64
  • Reputation:   40
  • Joined:  03/26/12
  • Last Seen:  

Cheers mate! Good to see new people releasing stuff. :)

Not to disappoint you or anything but this will do the same thing for checking the existence of the mob.

 

if(strmobinfo(0,1002) != ""){
	mes "Yes its a Poring, of course exists foo!";
	close;
} else {
	mes "No that monster does not exist or maybe it just doesn't spawn.";
	mes "Meh! What ever floats your boat...";
	close;
}
Nonetheless, your code looks good. :)

 

 

Its not a custom source(strmobinfo), Its already included in rA

Yeah but (strmobinfo) doesn't track if the mob has natural spawn or not like event monsters and stuff ^^ 

 

And no sorry, I don't know how to create a diff. I'm a newbie at this kind of things  /wah

 

 

 

Edited by joecalis
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  98
  • Topics Per Day:  0.02
  • Content Count:  1302
  • Reputation:   77
  • Joined:  12/04/12
  • Last Seen:  

bro, when the patch will be use ? 

when we use @mi ? or when @whereis ?

Edited by mrlongshen
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  64
  • Reputation:   40
  • Joined:  03/26/12
  • Last Seen:  

bro, when the patch will be use ? 

when we use @mi ? or when @whereis ?

 

Its not an @command, its a script command meaning it will only work for npc scripts like the one shown in the example.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  98
  • Topics Per Day:  0.02
  • Content Count:  1302
  • Reputation:   77
  • Joined:  12/04/12
  • Last Seen:  

i dont get it. sry. i too noobies about src mod, if i implement this, when this will appear ?

 

 

  1. if(mobexists(1002)){    // It works with mob name too "mobexists("Poring")"
  2.     mes "Yes its a Poring, of course exists foo!";
  3.     close;
  4. } else {
  5.     mes "No that monster does not exist or maybe it just doesn't spawn.";
  6.     mes "Meh! What ever floats your boat...";
  7.     close;
  8. }
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  8
  • Topics Per Day:  0.00
  • Content Count:  64
  • Reputation:   40
  • Joined:  03/26/12
  • Last Seen:  

i dont get it. sry. i too noobies about src mod, if i implement this, when this will appear ?

 

 

  1. if(mobexists(1002)){    // It works with mob name too "mobexists("Poring")"
  2.     mes "Yes its a Poring, of course exists foo!";
  3.     close;
  4. } else {
  5.     mes "No that monster does not exist or maybe it just doesn't spawn.";
  6.     mes "Meh! What ever floats your boat...";
  7.     close;
  8. }

 

That will not appear ever unless you added an npc with a script code like that.

So if you implement this, You can make different npc with "mobexists(<Mob ID>)" function.

 

e.g.

prontera,150,150,4	script	Monster Spawn Check	405,{
set @npcname$,"[^ff0000 Monster Spawn Check ^000000]";
mes @npcname$;
mes "Put the monster ID you would like to check.";
next;
input @mobid;
if(@mobid<=0){
	mes @npcname$;
	mes "Please put in a real ID";
	close
} else if(!mobexists(@mobid)){
	mes @npcname$;
	mes "That monster does not exists or spawn naturally.";
	close;
} else {
	mes @npcname$;
	mes "Yes "+getmonsterinfo(@mobinfo,0)+" exists and spawns naturally.";
	close
}
}
	
Edited by joecalis
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  98
  • Topics Per Day:  0.02
  • Content Count:  1302
  • Reputation:   77
  • Joined:  12/04/12
  • Last Seen:  

now i understand. hehe thx mate :)

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

×   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...