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.