PDA

View Full Version : New Commands #2 <Spawn code variation>


Nefarious
01-16-2002, 07:23 AM
I added some code so that when you spawn something using #spawn it will tell you the x, y, z, and the heading of the spawn


Code:

else if (strcasecmp(sep.arg[0], "#spawn") == 0 &amp;&amp; (admin >= 1)) // Image's Spawn Code
{
int pHeading;
cout &lt;&lt; "Spawning:" &lt;&lt; endl;
//Well it needs a name!!!
if(sep.arg[1][0] == 0)
{
Message(1, "Format: #spawn firstname lastname(put (null) for no last name) race gender class level hp weaponnumber heading (North- 0; West- 60; South-130; East-190): spawns a npc those parameters.");
}
else
{
//Lets see if someone didn't fill out the whole #spawn function properly
if ((!strcmp(sep.arg[2],"(null)")) || sep.arg[2][0] == 0)
sprintf(sep.arg[2],"");
if (!sep.IsNumber(3))
sprintf(sep.arg[3],"1");
if (!sep.IsNumber(4))
sprintf(sep.arg[4],"1");
if (!sep.IsNumber(5))
sprintf(sep.arg[5],"1");
if (!sep.IsNumber(6))
sprintf(sep.arg[6],"1");
if (!sep.IsNumber(7))
sprintf(sep.arg[7],"100");
if (atoi(sep.arg[7]) > 32000)
sprintf(sep.arg[7],"32000");
if (!sep.IsNumber(8))
sprintf(sep.arg[8],"0");
if (!sep.IsNumber(9) &amp;&amp; heading >= 0)
pHeading = heading;
if (!sep.IsNumber(9) &amp;&amp; heading &lt; 0)
pHeading = heading + 260;
if (sep.IsNumber(9))
pHeading = atoi(sep.arg[9]);

char fullname[500];
if (sep.arg[2][0] == 0)
strcpy(fullname, sep.arg[1]);
else
sprintf(fullname,"%s_%s",sep.arg[1],sep.arg[2]);

// Well we want everyone to know what they spawned, right?
Message(4, "New spawn:");
Message(1, " First Name: %s",sep.arg[1]);
Message(1, " Last Name: %s",sep.arg[2]);
Message(1, " Race: %s",sep.arg[3]);
Message(1, " Gender: %s",sep.arg[4]);
Message(1, " Class: %s",sep.arg[5]);
Message(1, " Level: %s",sep.arg[6]);
Message(1, " Current/Max HP: %s",sep.arg[7]);
Message(1, " Weapon Item Number: %s",sep.arg[8]);
Message(1, " ");
Message(1, " Current Heading: %d", heading);
Message(1, " Current x: %d", x_pos);
Message(1, " Current y: %d", y_pos);
Message(1, " Current z: %d", z_pos/10);

//Time to create the NPC!!
NPCType npc_type;
strcpy(npc_type.name,fullname);
strcpy(npc_type.lastname,sep.arg[2]);
npc_type.cur_hp = atoi(sep.arg[7]);
npc_type.max_hp = atoi(sep.arg[7]);
npc_type.race = atoi(sep.arg[3]);
npc_type.gender = atoi(sep.arg[4]);
npc_type.class_ = atoi(sep.arg[5]);
npc_type.deity= 1;
npc_type.level = atoi(sep.arg[6]);
npc_type.npc_id = 0;
npc_type.loottable_id = 0;
npc_type.texture = 0; // add this to be defineable when we find it in the packet
npc_type.light = 0;
for (int i=0; i&lt;9; i++)
npc_type.equipment[i] = atoi(sep.arg[8]);


NPC* npc = new NPC(&amp;npc_type, 0, x_pos, y_pos, z_pos, pHeading, false);

// Disgrace: add some loot to it!
npc->AddCash(0,0,0,0);
int itemcount = (rand()%5) + 1;
for (int counter=0; counter&lt;itemcount; counter++)
{
Item_Struct* item = 0;
while (item == 0)
item = database.GetItem(rand() % 33000);

npc->AddItem(item, 0, 0);
}

entity_list.AddNPC(npc);

//What the hell lets send a position update!
SendPosUpdate();
}
}

-------------------------------------------------------------

Yodason
01-20-2002, 10:38 AM
hey that was my idea first! (not that I care)