[devRev4] Spawn gmcmd

Welcome in the osRose emulator Project.

Moderators: osRose dev team, ospRose dev team, osiRose dev team, Moderators

[devRev4] Spawn gmcmd

Postby kismetbecomes on Sat May 18, 2013 5:20 am

Hello osRose, I've been pretty loud here lately. Here's another - :D

I would like to revise the mob groups - I just want to keep track of all the mobs there is - of my server.

And putting them manually is very hard, and it consumes alot of time.
So I thought why not code a spawn command-

I actually tried but failed, FAILED completely.
So, please help me out.

I took the Ktrose code for "spawn" in gmcmds.cpp, and revised it to this:

  1.  
  2. else if (strcmp(command, "spawn")==0)
  3.     {
  4.         if(Config.Command_Spawn > thisclient->Session->accesslevel)
  5.             return true;
  6.        
  7.         int spawnid;
  8.         int mobid;
  9.         int mobcount;
  10.         int interval;
  11.         int radius;
  12.  
  13. if ((tmp = strtok(NULL, " "))==NULL)
  14.               return true;
  15.                else
  16.                spawnid = atoi(tmp);
  17.  
  18. if ((tmp = strtok(NULL, " "))==NULL)
  19.               return true;
  20.                else
  21.                mobid = atoi(tmp);
  22.  
  23. if ((tmp = strtok(NULL, " "))==NULL)
  24.               return true;
  25.                else
  26.                mobcount = atoi(tmp);
  27.  
  28. if ((tmp = strtok(NULL, " "))==NULL)
  29.               return true;
  30.                else
  31.                interval = atoi(tmp);
  32.  
  33. if ((tmp = strtok(NULL, " "))==NULL)
  34.               return true;
  35.                else
  36.               radius = atoi(tmp);
  37.  
  38. GServer->DB->QExecute("INSERT INTO spawns (spawnid,mapname,mapid,spawn_interval,mob_limit,radius,tactic,pos_x,pos_y,spawn_x,spawn_y,special,bmob1,bcount1,bmob2,bcount2,bmob3,bcount3,bmob4,bcount4,bmob5,bcount5,tmob1,tcount1,tmob2,tcount2,dir)
  39. VALUES(%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,)",
  40.  
  41. spawnid,NULL,thisclient->Position->Map, interval, 20, radius, 200,0,0,thisclient->Position->current.x,thisclient->Position->current.y,0,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount,0,0,0,0,0);
  42.  


//Do I have to put <= 100 after accesslevel?
//GM/DEV's would code it :: /spawn (spawnid) (mobid) (howMany) (IntervalOfSpawn) (radius)
//I've been having problems with the %i says NOT DECLARED everytime I compile it, so I'm guessing I've wrong.
//I just copied how its done in ktRose tho - sorry. Just wanna ask also, why x and y coors are %f.
//the NULL there is mapname, which I don't see how it would automatically put map name on it, it's just a description so just set it to NULL.
//all mob limits are default to 20.
//all tactics are default to 200.
//posx and posy are, useless?
//the mob id and count will automatically be entered to all bmobs and bcounts.
//Very important question tho.. is there a way to make the spawnid automatically count ++? dunno if this :   GServer->maxSpawnId++;thisspawn->id = GServer->maxSpawnId; has something to do with that.

NOW THE SECOND PART SUDDENLY GOT BLOODY.
I'm guessing this is where the server sends a spawn code to the client.

This is from KTROSE.
  1. CSpawnArea* thisspawn = new (nothrow) CSpawnArea;
  2.         if(thisspawn == NULL)
  3.         {
  4.             Log(MSG_ERROR, "Error allocing memory" );
  5.             DB->QFree( );
  6.             return false;
  7.         }
  8.         GServer->maxSpawnId++;
  9.         thisspawn->id = GServer->maxSpawnId;
  10.         thisspawn->map = thisclient->Position->Map;
  11.         thisspawn->montype = mobid;
  12.         thisspawn->min = 0;//atoi(row[3]);
  13.         thisspawn->max = max;
  14.         thisspawn->respawntime = stime;
  15.         thisspawn->point.x = thisclient->Position->current.x;
  16.         thisspawn->point.y = thisclient->Position->current.y;
  17.         thisspawn->radius = radius;
  18.         thisspawn->amon = 0;
  19.         thisspawn->lastRespawnTime = 0;
  20.         thisspawn->type = spawntype;
  21.         thisspawn->triggertype = triggermontype;
  22.         thisspawn->triggeramount = triggeramount;
  23.         thisspawn->aggressive = aggro;
  24.         thisspawn->typeoftrigger = 1;
  25.         thisspawn->limit = lim;
  26.         thisspawn->spawnkey = spawnk;
  27.         thisspawn->triggercount = 0;
  28.         thisspawn->thisnpc = GetNPCDataByID( thisspawn->montype );
  29.         thisspawn->RefVar = refvar;
  30.         thisspawn->RefVal = refval;
  31.         if(thisspawn->thisnpc == NULL)
  32.         {
  33.             SendPM(thisclient, "Invalid montype - Spawn %i will not be added", thisspawn->id );
  34.             delete thisspawn;
  35.             return true;
  36.         }
  37.         MapList.Index[thisspawn->map]->MonsterSpawnList.push_back( thisspawn );
  38.         SendPM(thisclient,"Spawn successfully saved with spawn id %i.",thisspawn->id);
  39.         return true;
  40.     }



I got this from Rev4 startup.cpp
  1. CSpawnArea* thisspawn = new (nothrow) CSpawnArea;
  2.         if(thisspawn == NULL)
  3.         {
  4.             Log(MSG_ERROR, "Error allocing memory" );
  5.             DB->QFree( );
  6.             return false;
  7.         }
  8.         thisspawn->id = atoi(row[0]);
  9.         thisspawn->map = atoi(row[1]);
  10.         thisspawn->radius = atoi(row[2]);
  11.         thisspawn->points.x = atof(row[3]);
  12.         thisspawn->points.y = atof(row[4]);
  13.         thisspawn->tactic = atoi(row[5]);
  14.         thisspawn->bmob[1] = atoi(row[6]);
  15.         thisspawn->bmob[2] = atoi(row[7]);
  16.         thisspawn->bmob[3] = atoi(row[8]);
  17.         thisspawn->bmob[4] = atoi(row[9]);
  18.         thisspawn->bmob[5] = atoi(row[10]);
  19.         thisspawn->bcount[1] = atoi(row[11]);
  20.         thisspawn->bcount[2] = atoi(row[12]);
  21.         thisspawn->bcount[3] = atoi(row[13]);
  22.         thisspawn->bcount[4] = atoi(row[14]);
  23.         thisspawn->bcount[5] = atoi(row[15]);
  24.         thisspawn->tmob[1] = atoi(row[16]);
  25.         thisspawn->tmob[2] = atoi(row[17]);
  26.         thisspawn->tcount[1] = atoi(row[18]);
  27.         thisspawn->tcount[2] = atoi(row[19]);
  28.         thisspawn->respawntime = atoi(row[20]);
  29.  
  30.  


I don't know what came to me but I came up with this:
  1. thisspawn->id = spawnid;
  2.         thisspawn->map = thisclient->Position->Map;
  3.         thisspawn->radius = radius;
  4.         thisspawn->points.x = thisclient->Position->current.x;
  5.         thisspawn->points.y = thisclient->Position->current.y;
  6.         thisspawn->tactic = 200;
  7.         thisspawn->bmob[1] = mobid;
  8.         thisspawn->bmob[2] = mobid;
  9.         thisspawn->bmob[3] = mobid;
  10.         thisspawn->bmob[4] = mobid;;
  11.         thisspawn->bmob[5] = mobid;
  12.         thisspawn->bcount[1] = mobcount;
  13.         thisspawn->bcount[2] = mobcount;
  14.         thisspawn->bcount[3] = mobcount;
  15.         thisspawn->bcount[4] = mobcount;
  16.         thisspawn->bcount[5] = mobcount;
  17.         thisspawn->tmob[1] = 0;
  18.         thisspawn->tmob[2] = 0;
  19.         thisspawn->tcount[1] = 0;
  20.         thisspawn->tcount[2] = 0;
  21.         thisspawn->respawntime = interval;


NOW THIS PART I TOTALLY GAVE UP BECAUSE I DON'T KNOW WHAT TO DO ANYMORE. I TRIED, BUT, :? I got exhausted.
this is also from KtRose, don't know how to revise it.
  1.  thisspawn->thisnpc = GetNPCDataByID( thisspawn->montype );
  2.         thisspawn->RefVar = refvar;
  3.         thisspawn->RefVal = refval;
  4.         if(thisspawn->thisnpc == NULL)
  5.         {
  6.             SendPM(thisclient, "Invalid montype - Spawn %i will not be added", thisspawn->id );
  7.             delete thisspawn;
  8.             return true;
  9.         }
  10.         MapList.Index[thisspawn->map]->MonsterSpawnList.push_back( thisspawn );
  11.         SendPM(thisclient,"Spawn successfully saved with spawn id %i.",thisspawn->id);
  12.         return true;
  13.     }


I would just like to stress out I'am not a coder, but I'm trying to learn. Please be patient with me.
Last edited by kismetbecomes on Thu May 23, 2013 7:27 am, edited 1 time in total.
RoseZa v437 - HueRose Test Project -- http://hueroseonline.no-ip.biz
kismetbecomes
Rackie
Rackie
 
Posts: 299
Joined: Mon Feb 06, 2012 12:41 am

Re: [devRev4] help me code rev 4 /spawn.

Postby kismetbecomes on Sun May 19, 2013 8:08 am

I'm currently using this code, altho it works in writing entries to the database -that is the easy part - the mobs does not spawn until server restart.
(Or is it really like that? I don't think so, I have in mind the mobs would summon and the server does need to be restarted for that spawn to start.)

  1. //GMcode-- /spawn [mobid] [mobcount] [respawnInterval] [radius]
  2. else if (strcmp(command, "spawn")==0)
  3.     {
  4.         if(Config.Command_SSpawn > thisclient->Session->accesslevel)
  5.             return true;
  6.  
  7.         int spawnid = 0;
  8.         int spawnidauto;
  9.         int mobid;
  10.         int mobcount;
  11.         int interval;
  12.         int radius;
  13.  
  14.  
  15. if ((tmp = strtok(NULL, " "))==NULL)
  16.               return true;
  17.                else
  18.                mobid = atoi(tmp);
  19.  
  20. if ((tmp = strtok(NULL, " "))==NULL)
  21.               return true;
  22.                else
  23.                mobcount = atoi(tmp);
  24.  
  25. if ((tmp = strtok(NULL, " "))==NULL)
  26.               return true;
  27.                else
  28.                interval = atoi(tmp);
  29.  
  30. if ((tmp = strtok(NULL, " "))==NULL)
  31.               return true;
  32.                else
  33.                radius = atoi(tmp);
  34.  
  35.  
  36. spawnidauto = spawnid++;
  37. GServer->DB->QExecute("INSERT INTO spawns (spawnid,mapname,mapid,spawn_interval,mob_limit,radius,tactic,pos_x,pos_y,spawn_x,spawn_y,special,bmob1,bcount1,bmob2,bcount2,bmob3,bcount3,bmob4,bcount4,bmob5,bcount5,tmob1,tcount1,tmob2,tcount2)VALUES(%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i)",
  38.                       spawnidauto,0,thisclient->Position->Map,interval,20,radius,200,0,0,thisclient->Position->current.x,thisclient->Position->current.y,0,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount);
  39.  
  40.  
  41.         CSpawnArea* thisspawn = new (nothrow) CSpawnArea;
  42.  
  43.         thisspawn->id = spawnidauto;
  44.         thisspawn->map = thisclient->Position->Map;
  45.         thisspawn->radius = radius;
  46.         thisspawn->points.x = thisclient->Position->current.x;
  47.         thisspawn->points.y = thisclient->Position->current.y;
  48.         thisspawn->tactic = 200;
  49.         thisspawn->bmob[1] = mobid;
  50.         thisspawn->bmob[2] = mobid;
  51.         thisspawn->bmob[3] = mobid;
  52.         thisspawn->bmob[4] = mobid;
  53.         thisspawn->bmob[5] = mobid;
  54.         thisspawn->bcount[1] = mobcount;
  55.         thisspawn->bcount[2] = mobcount;
  56.         thisspawn->bcount[3] = mobcount;
  57.         thisspawn->bcount[4] = mobcount;
  58.         thisspawn->bcount[5] = mobcount;
  59.         thisspawn->tmob[1] = mobid;
  60.         thisspawn->tmob[2] = mobid;
  61.         thisspawn->tcount[1] = mobcount;
  62.         thisspawn->tcount[2] = mobcount;
  63.         thisspawn->respawntime = interval;
  64.         thisspawn->ResetSpawn = true;
  65.  
  66.             CNPCData* tempnpc;
  67.             tempnpc = GetNPCDataByID( thisspawn->bmob[1] );
  68.             thisspawn->amon = 0;
  69.             thisspawn->lastRespawnTime = clock();
  70.  
  71.  
  72. }
  73.  


I'm pretty sure I screwed this part : CSpawnArea* thisspawn = new (nothrow) CSpawnArea; and below.. anyone can help?
RoseZa v437 - HueRose Test Project -- http://hueroseonline.no-ip.biz
kismetbecomes
Rackie
Rackie
 
Posts: 299
Joined: Mon Feb 06, 2012 12:41 am

Re: [devRev4] help me code rev 4 /spawn.

Postby PurpleYouko on Mon May 20, 2013 2:18 pm

It actually looks like you did a pretty good job on the whole.

You did miss one vital step though.
When you add a new spawn you have to actually add it to the spawnlist vector if you want to see it work immediately.
If you look in the startup code where the new CSpawnarea object is created you will see a line like this right at the bottom
  1. MapList.Index[thisspawn->map]->MonsterSpawnList.push_back( thisspawn );

That push_back command is the one that pushes your new "thisspawn" local structure( that you just spent so much time and effort to make) onto the global spawn vector.

As for using the KTRose code, you obviously already figured out that KT doesn't do spawning in the same way as the dev rev does. I built a completely custom system to allow for all kinds of triggers, spawning only at night or only in the day, etc. It's a very complex system.
Need to lookup information on NARose items, skills, quests?
Now featuring a newly completed skill tree for all classes
Formatting fixed for different resolutions
Image

"A Gazelle is nothing but a giraffe plotted logarithmicaly"
User avatar
PurpleYouko
Rose Guru
Rose Guru
 
Posts: 4733
Joined: Fri Aug 10, 2007 2:05 pm

Re: [devRev4] help me code rev 4 /spawn.

Postby kismetbecomes on Mon May 20, 2013 5:41 pm

Yes, I've noticed so many things changed. Esp the databases. :shock:
RoseZa v437 - HueRose Test Project -- http://hueroseonline.no-ip.biz
kismetbecomes
Rackie
Rackie
 
Posts: 299
Joined: Mon Feb 06, 2012 12:41 am

Re: [devRev4] help me code rev 4 /spawn.

Postby kismetbecomes on Wed May 22, 2013 5:58 am

Added this code at the bottom:

  1.  
  2.     MapList.Index[thisspawn->map]->MonsterSpawnList.push_back(thisspawn);
  3.     SendPM(thisclient,"Spawn successfully saved.");
  4.     return true;


Nothing happened :lol:
RoseZa v437 - HueRose Test Project -- http://hueroseonline.no-ip.biz
kismetbecomes
Rackie
Rackie
 
Posts: 299
Joined: Mon Feb 06, 2012 12:41 am

Re: [devRev4] help me code rev 4 /spawn.

Postby kismetbecomes on Wed May 22, 2013 6:00 am

This is the whole code i'm using now:

  1. //GMcode-- /spawn [mobid] [mobcount] [respawnInterval] [radius]
  2. else if (strcmp(command, "spawn")==0)
  3.     {
  4.         if(Config.Command_SSpawn > thisclient->Session->accesslevel)
  5.             return true;
  6.  
  7.         int spawnid = 0;
  8.         int spawnidauto;
  9.         int mobid;
  10.         int mobcount;
  11.         int interval;
  12.         int radius;
  13.  
  14.  
  15. if ((tmp = strtok(NULL, " "))==NULL)
  16.               return true;
  17.                else
  18.                mobid = atoi(tmp);
  19.  
  20. if ((tmp = strtok(NULL, " "))==NULL)
  21.               return true;
  22.                else
  23.                mobcount = atoi(tmp);
  24.  
  25. if ((tmp = strtok(NULL, " "))==NULL)
  26.               return true;
  27.                else
  28.                interval = atoi(tmp);
  29.  
  30. if ((tmp = strtok(NULL, " "))==NULL)
  31.               return true;
  32.                else
  33.                radius = atoi(tmp);
  34.  
  35.  
  36. spawnidauto = spawnid++;
  37. GServer->DB->QExecute("INSERT INTO spawns(spawnid,mapname,mapid,spawn_interval,mob_limit,radius,tactic,pos_x,pos_y,spawn_x,spawn_y,special,bmob1,bcount1,bmob2,bcount2,bmob3,bcount3,bmob4,bcount4,bmob5,bcount5,tmob1,tcount1,tmob2,tcount2)VALUES(%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i)",
  38.                       spawnidauto,0,thisclient->Position->Map,interval,20,radius,200,0,0,thisclient->Position->current.x,thisclient->Position->current.y,0,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount);
  39.  
  40.         CSpawnArea* thisspawn = new (nothrow) CSpawnArea;
  41.         thisspawn->id = spawnidauto;
  42.         thisspawn->map = thisclient->Position->Map;
  43.         thisspawn->radius = radius;
  44.         thisspawn->points.x = thisclient->Position->current.x;
  45.         thisspawn->points.y = thisclient->Position->current.y;
  46.         thisspawn->tactic = 200;
  47.         thisspawn->montype = mobid;
  48.         thisspawn->bmob[1] = mobid;
  49.         thisspawn->bmob[2] = mobid;
  50.         thisspawn->bmob[3] = mobid;
  51.         thisspawn->bmob[4] = mobid;
  52.         thisspawn->bmob[5] = mobid;
  53.         thisspawn->bcount[1] = mobcount;
  54.         thisspawn->bcount[2] = mobcount;
  55.         thisspawn->bcount[3] = mobcount;
  56.         thisspawn->bcount[4] = mobcount;
  57.         thisspawn->bcount[5] = mobcount;
  58.         thisspawn->tmob[1] = mobid;
  59.         thisspawn->tmob[2] = mobid;
  60.         thisspawn->tcount[1] = mobcount;
  61.         thisspawn->tcount[2] = mobcount;
  62.         thisspawn->respawntime = interval;
  63.         thisspawn->thisnpc = GetNPCDataByID(thisspawn->montype);
  64.  
  65.             CNPCData* tempnpc;
  66.             tempnpc = GetNPCDataByID(thisspawn->bmob[1]);
  67.             thisspawn->amon = 0;
  68.             thisspawn->lastRespawnTime = clock();
  69.  
  70.     MapList.Index[thisspawn->map]->MonsterSpawnList.push_back(thisspawn);
  71.     SendPM(thisclient,"Spawn successfully saved.");
  72.     return true;
  73.  
  74. }
RoseZa v437 - HueRose Test Project -- http://hueroseonline.no-ip.biz
kismetbecomes
Rackie
Rackie
 
Posts: 299
Joined: Mon Feb 06, 2012 12:41 am

Re: [devRev4] help me code rev 4 /spawn.

Postby kismetbecomes on Thu May 23, 2013 7:26 am

This code works:
thanks PY. :D


  1.  
  2. //GMcode-- /spawn [mobid] [mobcount] [respawnInterval] [radius]
  3. else if (strcmp(command, "spawn")==0)
  4.     {
  5.         if(Config.Command_SSpawn > thisclient->Session->accesslevel)
  6.             return true;
  7.  
  8.         int spawnid = 0;
  9.         int spawnidauto;
  10.         int mobid;
  11.         int mobcount;
  12.         int interval;
  13.         int radius;
  14.  
  15. if ((tmp = strtok(NULL, " "))==NULL)
  16.               return true;
  17.                else
  18.                mobid = atoi(tmp);
  19.  
  20. if ((tmp = strtok(NULL, " "))==NULL)
  21.               return true;
  22.                else
  23.                mobcount = atoi(tmp);
  24.  
  25. if ((tmp = strtok(NULL, " "))==NULL)
  26.               return true;
  27.                else
  28.                interval = atoi(tmp);
  29.  
  30. if ((tmp = strtok(NULL, " "))==NULL)
  31.               return true;
  32.                else
  33.                radius = atoi(tmp);
  34.  
  35. spawnidauto = spawnid++;
  36. GServer->DB->QExecute("INSERT INTO spawns(spawnid,mapname,mapid,spawn_interval,mob_limit,radius,tactic,pos_x,pos_y,spawn_x,spawn_y,special,bmob1,bcount1,bmob2,bcount2,bmob3,bcount3,bmob4,bcount4,bmob5,bcount5,tmob1,tcount1,tmob2,tcount2)VALUES(%i,%i,%i,%i,%i,%i,%i,%i,%i,%f,%f,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i,%i)",
  37.                       spawnidauto,0,thisclient->Position->Map,interval,20,radius,200,0,0,thisclient->Position->current.x,thisclient->Position->current.y,0,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount,mobid,mobcount);
  38.  
  39.         CSpawnArea* thisspawn = new (nothrow) CSpawnArea;
  40.         thisspawn->id = spawnidauto;
  41.         thisspawn->map = thisclient->Position->Map;
  42.         thisspawn->radius = radius;
  43.         thisspawn->points.x = thisclient->Position->current.x;
  44.         thisspawn->points.y = thisclient->Position->current.y;
  45.         thisspawn->tactic = 200;
  46.         thisspawn->montype = mobid;
  47.         thisspawn->bmob[1] = mobid;
  48.         thisspawn->bmob[2] = mobid;
  49.         thisspawn->bmob[3] = mobid;
  50.         thisspawn->bmob[4] = mobid;
  51.         thisspawn->bmob[5] = mobid;
  52.         thisspawn->bcount[1] = mobcount;
  53.         thisspawn->bcount[2] = mobcount;
  54.         thisspawn->bcount[3] = mobcount;
  55.         thisspawn->bcount[4] = mobcount;
  56.         thisspawn->bcount[5] = mobcount;
  57.         thisspawn->tmob[1] = mobid;
  58.         thisspawn->tmob[2] = mobid;
  59.         thisspawn->tcount[1] = mobcount;
  60.         thisspawn->tcount[2] = mobcount;
  61.         thisspawn->respawntime = interval;
  62.         thisspawn->thisnpc = GetNPCDataByID(thisspawn->montype);
  63.  
  64.             CNPCData* tempnpc;
  65.             tempnpc = GetNPCDataByID(thisspawn->bmob[1]);
  66.             thisspawn->amon = 0;
  67.             thisspawn->lastRespawnTime = clock();
  68.  
  69.     MapList.Index[thisspawn->map]->MonsterSpawnList.push_back(thisspawn);
  70.     SendPM(thisclient,"Spawn successfully saved.");
  71.     return true;
  72.  
  73. }
RoseZa v437 - HueRose Test Project -- http://hueroseonline.no-ip.biz
kismetbecomes
Rackie
Rackie
 
Posts: 299
Joined: Mon Feb 06, 2012 12:41 am


Return to Support - OsRose Emulator

Who is online

Users browsing this forum: No registered users and 9 guests

cron