Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

NPCs Spawn Mobs

Status
Not open for further replies.
Newbie Spellweaver
Joined
Apr 16, 2008
Messages
11
Reaction score
0
Not really sure if this had been released yet, but I managed to figure out how to make NPCs spawn Mobs.

Im using TitanMS ver009b
SHOULD work on other TitanMS Revs too!

By the way this spawns a MOB or MOBS on the Character's Pos.
EDIT: I Figured out how to spawn MOB or MOBS on a Specific Pos. too.

Hope I helped by contributing this.

Files to be Edited: NPCs.cpp & NPCs.h

Firstly, Open & add this to the top of NPCs.cpp, IF not already there :
Code:
#include "Mobs.h"

Secondly, search for :
Code:
void [B]NPC[/B]::sendStyle(int [B]styles[/B][], char [B]size[/B]){
	[B]Packet[/B] [B]packet[/B] = npcPacket(7);
	packet.addByte(size);
	for(int i=0; i<size; i++)
		packet.addInt(styles[i]);
	packet.packetSend(player);
}
Thirdly, add this UNDER it then Save :
Code:
void [B]NPC[/B]::spawnMob(int [B]mobid[/B]){
	if(Mobs::mobinfo.find(mobid) != Mobs::mobinfo.end())
		Mobs::spawnMob(player, mobid);
}
void NPC::spawnMobPos(int mobid, int xx, int yy){
	if(Mobs::mobinfo.find(mobid) != Mobs::mobinfo.end())
		Mobs::spawnMobPos(player, mobid, xx, yy);
}
Fourthly, Open NPCs.h then search for :
Code:
void teleport(int [B]mapid[/B]);

Fifthly, add this UNDER it :
Code:
void spawnMob(int [B]mobid[/B]);
void spawnMobPos(int [B]mobid[/B], int xx, int yy);
DONE~!

Example of how to Script NPCs to spawn mobs :
Code:
void NPCsScripts::npc_[I][B]NPC[/B][/I] [I][B]ID HERE[/B][/I](NPC* npc){
	int state = npc->getState();
	if(state == 0){
		npc->addText("I will now Spawn a [B]Mob[/B].");
		npc->sendOK();
		npc->end();
		npc->spawnMob([I][B]MOB[/B] [B]ID HERE[/B][/I]);
		[I][B][U]OR[/U][/B][/I]
		npc->spawnMobPos([I][B]MOB[/B] [B]ID[/B][/I], [B][I]x[/I][/B], [B][I]y[/I][/B]);
	}
}
To Figure out X and Y in the NPC code. IN GAME, go to the map that the NPC is in and type " !pos " and you should get something like...
Code:
[Notice] X: 596 Y: 100
Use the X and Y for the "x, y" in the NPC code to spawn the mob there!
Example:
The MobID "9300003" is "King Slime (PC)"
Code:
npc->spawnMobPos([I][B]9300003[/B][/I], [B][I]596[/I][/B], [B][I]0[/I][/B]);
I ENTIRELY figured out this by myself.
Credits to Me.
 
Last edited:
Junior Spellweaver
Joined
Apr 7, 2008
Messages
100
Reaction score
0
Re: [Realease] NPCs Spawn Mobs

Or, the easier way: In you NPC script, add: (maby not easier, but it was the way I did it, and I have seen NPC's done the same way)
#include "Mobs.h"
and when you want the mobs to spawn, just put in:
Mobs::spawnMobPos(player, mobid, x, y);

You can also use Mobs::spawnMob, but I like to have a position for my mobs set.


But as for programming that, good job, it makes it easier for people new to programming to do.

Great for a 1st post here. =)
 
Newbie Spellweaver
Joined
Apr 26, 2008
Messages
52
Reaction score
0
Re: [Realease] NPCs Spawn Mobs

Great release! Now I gotta figure out how to add an NPC to a map, and make him charge to spawn the mob x3 Thanks!
 
Newbie Spellweaver
Joined
Apr 16, 2008
Messages
11
Reaction score
0
Re: [Realease] NPCs Spawn Mobs

Thanks for compliments. :biggrin2:

UPDATE: Spawn Mobs by Pos NOW... YAY~
Edited Scripting NPC guide a bit.
 
Junior Spellweaver
Joined
Apr 7, 2008
Messages
100
Reaction score
0
Thanks for compliments. :biggrin2:

UPDATE: Spawn Mobs by Pos NOW... YAY~
Edited Scripting NPC guide a bit.

YAY! spawnMobPos


Also, Vallyn, if you want an NPC to spawn for money, use the commands
npc->givemeso(-*amount here*)
Mobs::spawnMobPos(player, *mobid*, *x*, *y*); (You'll need to add Mobs.h as an include for this way)
OR
npc->givemeso(-*amount here*)
npc->spawnMobPos(*mobid*, *x*, *y*); (You have to use the tut in the 1st post for this way)
 
Last edited:
Newbie Spellweaver
Joined
Apr 26, 2008
Messages
52
Reaction score
0
Re: [Realease] NPCs Spawn Mobs

Wow, thanks Frozen! One last thing... for the x and y, do I just go to the map where the NPC is, stand where I want the monsters to summon, do !pos, and use those coords.?
 
Newbie Spellweaver
Joined
Apr 16, 2008
Messages
11
Reaction score
0
Re: [Realease] NPCs Spawn Mobs

Wow, thanks Frozen! One last thing... for the x and y, do I just go to the map where the NPC is, stand where I want the monsters to summon, do !pos, and use those coords.?

Yep, exactly! :smilewink
or you could summon multiple monsters in various spots
Example:
This could look a bit similar to yours, if your summoning multiple Mobs
Oh and make sure you "#include Inventory.h & Player.h" or it won't take or give mesos and will probablly cuase an error or crash =P​
Code:
#include "NPCs.h"
#include "NPCsScripts.h"
#include "Player.h"
#include "Inventory.h"

void NPCsScripts::npc_[I][B]NPC ID HERE[/B][/I](NPC* npc){
	Player* player = npc->getPlayer();
	int state = npc->getState();

	if(state == 0){
		npc->giveMesos(-5000); // A negative give = taking mesos...
		npc->spawnMobPos(100100, 100, 101);
		npc->spawnMobPos(100100, 90, 311);
		npc->spawnMobPos(100100, 40, 501);
		npc->spawnMobPos(100100, 405, 201);
		npc->end();
	}
}
 
Last edited:
Junior Spellweaver
Joined
Apr 7, 2008
Messages
100
Reaction score
0
Re: [Realease] NPCs Spawn Mobs

Yep, exactly! :smilewink
or you could summon multiple monsters in various spots
Example:
This could look a bit similar to yours, if your summoning multiple Mobs
Oh and make sure you "#include Inventory.h & Player.h" or it won't take or give mesos and will probablly cuase an error or crash =P​
Code:
#include "NPCs.h"
#include "NPCsScripts.h"
#include "Player.h"
#include "Inventory.h"

void NPCsScripts::npc_[I][B]NPC ID HERE[/B][/I](NPC* npc){
    Player* player = npc->getPlayer();
    int state = npc->getState();

    if(state == 0){
        npc->giveMesos(-5000); // A negative give = taking mesos...
        npc->spawnMobPos(100100, 100, 101);
        npc->spawnMobPos(100100, 90, 311);
        npc->spawnMobPos(100100, 40, 501);
        npc->spawnMobPos(100100, 405, 201);
        npc->end();
    }
}

You don't need inventory as an include. (at least none of mine do unless I am using an inventory function)
 
Newbie Spellweaver
Joined
Apr 16, 2008
Messages
11
Reaction score
0
Re: [Realease] NPCs Spawn Mobs

You don't need inventory as an include. (at least none of mine do unless I am using an inventory function)
Oh.. well I've always included it just to be on the safe side. :eat:
Well, at least it won't hurt.
 
Newbie Spellweaver
Joined
Apr 26, 2008
Messages
52
Reaction score
0
Re: [Release] NPCs Spawn Mobs

So mudkip, when I code this NPC, should I make it on a completely separate .cpp?
 
Junior Spellweaver
Joined
Apr 20, 2008
Messages
139
Reaction score
0
Re: [Release] NPCs Spawn Mobs

I have the position and npc id, how would i do it? could someone post me my script and where to put it please? My x = 2025 and y = 334, Npc Id = (Unknown, i have the name of guy) Nicholas, The CVS Guy. Mob ID I will add in later, havnt decided yet, please someone post where to add it, and what my script should look like. Would it be like this;

void NPCsScripts::npc_NPC ID HERE(NPC* npc){
int state = npc->getState();
if(state == 0){
npc->addText("I will now Spawn a Mob.");
npc->sendOK();
npc->end();
npc->spawnMob(MOB ID HERE);
OR
npc->spawnMobPos(MOB ID, 2025, 334);
}
}

i will add the mob id and npc id after, but where would i put my script? in what .cpp and under what? please help.
 
Newbie Spellweaver
Joined
Apr 16, 2008
Messages
11
Reaction score
0
Re: [Release] NPCs Spawn Mobs

So mudkip, when I code this NPC, should I make it on a completely separate .cpp?
Yes... :wink_4:
If help is needed use the link below :
http://forum.ragezone.com/showthread.php?t=381658&highlight=NPCs

I have the position and npc id, how would i do it? could someone post me my script and where to put it please? My x = 2025 and y = 334, Npc Id = (Unknown, i have the name of guy) Nicholas, The CVS Guy. Mob ID I will add in later, havnt decided yet, please someone post where to add it, and what my script should look like. Would it be like this;

Code:
void NPCsScripts::npc_NPC ID HERE(NPC* npc){
	int state = npc->getState();
	if(state == 0){
		npc->addText("I will now Spawn a Mob.");
		npc->sendOK();
		npc->end();
		npc->spawnMob(MOB ID HERE);
		[U][I][B]OR[/B][/I][/U]
		npc->spawnMobPos(MOB ID, 2025, 334);
	}
}

i will add the mob id and npc id after, but where would i put my script? in what .cpp and under what? please help.
Make sure the OR is deleted in the code, its just there to show both ways of spawning Mobs,

I really don't want to show you how to script NPCs since there are a Million guides in the Guide section :juggle:
Example of a Link I found in 2.49849584 secs :
http://forum.ragezone.com/showthread.php?t=381658&highlight=NPCs
 
Last edited:
Junior Spellweaver
Joined
Jan 14, 2008
Messages
113
Reaction score
0
Re: [Release] NPCs Spawn Mobs

i d/c if i choose to let her spawn mobs
Code:
 #include "NPCs.h"
#include "NPCsScripts.h"
#include "Player.h"
#include "Inventory.h"

void NPCsScripts::npc_9010003(NPC* npc){
	Player* player = npc->getPlayer();
	int state = npc->getState();
	int type = npc->getSelected();
	if(state == 0){
		npc->addText("hello, i can spawn Golden Slimes for 1 milion mesos. Do you want me to spawn Golden Slimes?");
			npc->sendYesNo();
	}
else if(state == 1)
{
if(npc->getMesos() >= 1000000)
{
npc->addText("Okay, Poopiedoo");
npc->giveMesos(-1000000);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->sendOK();
npc->end();
}
if(npc->getMesos() <=1000000)
{
npc->addText("You don't have enough mesos");
npc->sendOK();
npc->end();
}
}
}
what's wrong
 
Newbie Spellweaver
Joined
Apr 16, 2008
Messages
11
Reaction score
0
Re: [Release] NPCs Spawn Mobs

i d/c if i choose to let her spawn mobs
Code:
 "A Bunch of Code"
what's wrong
EDIT: Here try this code~
Code:
#include "NPCs.h"
#include "Player.h"
#include "NPCsScripts.h"
#include "Inventory.h"

void NPCsScripts::npc_9010003(NPC* npc){
	Player* player = npc->getPlayer();
	int state = npc->getState();

	if(state == 0){
		npc->addText("Hello, I can spawn Golden Slimes for 1 milion mesos. Do you want me to spawn Golden Slimes?");
		state = 1;
		npc->sendYesNo();
	}
	else if(state == 1){
		if(npc->getMesos() >= 1000000){
			if(npc->getSelected() == YES){
				npc->addText("Okay, Poopiedoo.");
				npc->giveMesos(-1000000);
				npc->spawnMob(9400202);
				npc->spawnMob(9400202);
				npc->spawnMob(9400202);
				npc->spawnMob(9400202);
				npc->spawnMob(9400202);
				npc->spawnMob(9400202);
				npc->spawnMob(9400202);
				npc->spawnMob(9400202);
				npc->spawnMob(9400202);
				npc->spawnMob(9400202);
				npc->sendOK();
				npc->end();
			}
			else if(npc->getSelected() == NO){
				npc->addText("Fine, I won't spawn!");
				npc->sendOK();
				npc->end();
			}
		}
		else if(npc->getMesos() <=1000000){
			if(npc->getSelected() == YES){
				npc->addText("You don't have enough mesos.");
				npc->sendOK();
				npc->end();
			}
			else if(npc->getSelected() == NO){
				npc->addText("Fine, I won't spawn!");
				npc->sendOK();
				npc->end();
			}
		}
	}
}
Try this and tell me if it works~ :juggle:
 
Last edited:
Newbie Spellweaver
Joined
Apr 26, 2008
Messages
52
Reaction score
0
Re: [Release] NPCs Spawn Mobs

I keep getting 'identifier not found' in my NPCScripts.h ...

I added the NPC correctly and everything, and added his static void and case codes... the numbers are all right... I dont see what Im doing wrong.
 
Newbie Spellweaver
Joined
Apr 13, 2008
Messages
48
Reaction score
0
Re: [Realease] NPCs Spawn Mobs

Oh.. well I've always included it just to be on the safe side. :eat:
Well, at least it won't hurt.
Actually, it can hurt.

Adding that extra line makes the .cpp file larger, making it take up more memory. More memory used on something that is unnecessary means less memory for things that are necessary.
 
Newbie Spellweaver
Joined
Apr 16, 2008
Messages
11
Reaction score
0
Re: [Realease] NPCs Spawn Mobs

I keep getting 'identifier not found' in my NPCScripts.h ...

I added the NPC correctly and everything, and added his static void and case codes... the numbers are all right... I dont see what Im doing wrong.
Would be nice if you posted the Error directly from the "Output Box".

Double Check, To make sure the NPC ID in the "void NPCsScripts",
Is the SAME NPC ID in the "NPCsScripts.h" too.

Ex: "9010003" = Lakelis
Code:
void NPCsScripts::npc_9010003(NPC* npc){

Actually, it can hurt.

Adding that extra line makes the .cpp file larger, making it take up more memory. More memory used on something that is unnecessary means less memory for things that are necessary.
Well then... o.0
I'll take that into consideration next time. Ty
 
Junior Spellweaver
Joined
Jan 14, 2008
Messages
113
Reaction score
0
Re: [Release] NPCs Spawn Mobs

mudkip thanks the script works =D
 
Junior Spellweaver
Joined
Apr 20, 2008
Messages
139
Reaction score
0
Re: [Release] NPCs Spawn Mobs

Where would i put my code? anyone knows?

"#include "NPCs.h"
#include "Player.h"
#include "NPCsScripts.h"
#include "Inventory.h"

void NPCsScripts::npc_9010003(NPC* npc){
Player* player = npc->getPlayer();
int state = npc->getState();

if(state == 0){
npc->addText("Hello, I can spawn Golden Slimes for 1 milion mesos. Do you want me to spawn Golden Slimes?");
state = 1;
npc->sendYesNo();
}
else if(state == 1){
if(npc->getMesos() >= 1000000){
if(npc->getSelected() == YES){
npc->addText("Okay, Poopiedoo.");
npc->giveMesos(-1000000);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->spawnMob(9400202);
npc->sendOK();
npc->end();
}
else if(npc->getSelected() == NO){
npc->addText("Fine, I won't spawn!");
npc->sendOK();
npc->end();
}
}
else if(npc->getMesos() <=1000000){
if(npc->getSelected() == YES){
npc->addText("You don't have enough mesos.");
npc->sendOK();
npc->end();
}
else if(npc->getSelected() == NO){
npc->addText("Fine, I won't spawn!");
npc->sendOK();
npc->end();
}
}
}
}"

Thanks in advance~
 
Status
Not open for further replies.
Back
Top