Well, first of all you should check results of each function.
1)
gObjAddMonster result is stored into mIndex variable. I'm not sure what is the fail result for that function, but i'm going to assume it's -1.
After calling that function you need to compare mIndex with -1 this way:
Code:
///- Check if server was able to create a new monster.
if (mIndex == -1)
{
//- LOG HERE
return;
}
2)
I don't know if gObjSetMonster returns something or not, but in case it returns something you should check if the result failed.
3)
After assigning OBJECTSTRUCT* gObj variable you should check if gObj is null like this.
If you checked mIndex before this, then this should never be null. But just in case add the check and add a log.
Code:
///- If you are using an old version of visual studio maybe you need to use NULL instead of nullptr
if(gObj == nullptr)
{
//- LOG HERE
return;
}
4) And a final hint.
I assume that gObjSetMonster function already assign monster class. So you can just remove gObj->Class = 499;
This won't have any negative or positive effect. Just code reduction.
EDIT:
I haven't noticed this, but i'm not sure why you are using Map 5. Selupan map is 58