[HELP] Buff Fairy's for OsRose

Welcome in the osRose emulator Project.

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

Re: [HELP] Buff Fairy's for OsRose

Postby AnimalCrackerz on Tue Sep 12, 2017 10:34 pm

ohh I thought about that but the programming skills I have are limited and learned from you guys..right now trying to figure out how to make a single dialog on the .con for instructions to type /buffme.
AnimalCrackerz
Pomic
Pomic
 
Posts: 102
Joined: Tue Apr 20, 2010 1:58 pm

Re: [HELP] Buff Fairy's for OsRose

Postby PurpleYouko on Wed Sep 13, 2017 1:33 am

I'm going to be busy tomorrow.
I'll throw something together to load in a database table on Thursday and post up some step by step instructions :D
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: [HELP] Buff Fairy's for OsRose

Postby AnimalCrackerz on Wed Sep 13, 2017 4:01 pm

How about loading in a list of positions from a database table? that way you don't need to hard code all the NPC locations.


I'll throw something together to load in a database table on Thursday and post up some step by step instructions :D


OK! looking forward to this. I really like going this route with the player command over a buff bot.. most PServers let the player have /go , I plan to have it for only the first 3 towns (/go) with the /buffme for the first 3 towns..at this point the playerbuffs should be stronger. Secondly it removes all the needless NPC constantly casting buff every 10 or 30 secs.

(did you notice the Adventure Plains I put in the client? Unused in the Jrose client was hiding under the name JGT002 think they didn't use it because of a lightmap blemish on one of huts.)
AnimalCrackerz
Pomic
Pomic
 
Posts: 102
Joined: Tue Apr 20, 2010 1:58 pm

Re: [HELP] Buff Fairy's for OsRose

Postby PurpleYouko on Thu Sep 14, 2017 2:55 pm

I don't like to make Go available to players at all personally.
A better option is to sell them return scrolls from NPC shops.
It's really easy to add items to NPC shops.
I even wrote a tutorial on how to do it many years ago.

Basically make an NPC in each map sell scrolls for that map only so the first time they either have to make their own way or buy them from other players. You could even make them untradable if you wanted to be really strict about a policy like this.
The first time a player wants to venture out to Junon Polis should be an interesting and fun trip, not just typing /go
After they have done it once they can just by a few scrolls when they get there.
Also takes some money out of the game.

So anyway, I've been thinking about how to best do this using the BUFF NPCs and it seems like we already have a list of NPCs right?
They are in list_npc.sql database table already. If you want to spawn any custom NPCs such as buff bots you would already have put them into that table with map and x,y positions
There is even a table added by lmame called list_npc_special which would suit our needs perfectly. It already has some useful fields that we could co-opt.
It isn't loaded in all server versions though. I suggest you have a look to see if there is any loading code in startup.cpp for this table. If not then we can write some.
Alternatively we could just slightly modify list_npc and use that instead. We would just have to add two new fields and modify the loading code and npc class to receive the new information. Pretty simple

list_npc_special isn't loaded in the 137 source code that I'm using to develop this stuff so it's probably easier to just modify list_npc.

I'm off to figure out exactly how to do this all and then I will tell you all how I did it. Back in a couple of hours. ;)

[ABE]
list_npc_special IS in fact loaded already. it's in startup.cpp in this function
  1. //LMA: Special NPCs (Events or whatever...)
  2. bool CWorldServer::LoadNPCsSpecial( )
  3. {
  4.     Log( MSG_LOAD, "NPC Special           " );

So i think i will develop it from that instead. Seems easier.
Not sure how I missed that the first time.
If it's in this server (rev 1.5) then it's in ALL eve servers after rev 81 :D
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: [HELP] Buff Fairy's for OsRose

Postby PurpleYouko on Thu Sep 14, 2017 3:50 pm

Instructions to code the buffbot start here.

Step 1.
First we need to be able to recognize that any NPC is indeed a buffbot and not just some random dude selling black market wands or something equally heinous
For this we are going to have to delve right down into the heart of the worldserver and modify one of the central structures.
Open up datatypes.h and find where struct CNPC is defined. Should be around line 850 or so. Might be different in some versions. If you can't find it just do a search on "cnpc" and you will find it pretty easily.
here is is AFTER I have added a new boolean variable called "buffbot"
  1. // -----------------------------------------------------------------------------------------
  2. // A typical npc
  3. // -----------------------------------------------------------------------------------------
  4. struct CNPC
  5. {
  6.     unsigned short clientid;
  7.     fPoint pos;
  8.     float dir;
  9.     unsigned short posMap;
  10.     unsigned npctype;
  11.     CNPCData* thisnpc;
  12.     unsigned dialog;
  13.     long int event;
  14.     clock_t lastAiUpdate;   //LMA: AIP.
  15.     bool buffbot;
  16. };

So now we will have the ability to tell if the NPC we are standing near to is in fact a buffbot or not.

Step 2.
We need to be able to tell the worldserver if an NPC in table is a buffbot so we need to open up table list_npc_special in a database editor and add a field "buffbot" as a TINYINT with a default value of 0.
buffbot_table.jpg


Step 3.
You might want to edit your LIST_NPC.STB and LIST_NPC_S_STL at this point unless you prefer to just test this with an existing NPC for now.
I'm going to make a copy of Aruas fairy (NPC 1030) and put it back in at row 1046 (just because it's an empty space).
I've set her up as a member of my Kuro-Tejina staff just like my faithful little Keako in the original KTRose :D
buffbot STB.jpg


Don't forget to make sure you have a valid entry in the "stl reference column and that you have also added the name and description to the STL to match it
buffbot STL.jpg


That's it for this post. Don't want to get them too long and get bogged down.
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: [HELP] Buff Fairy's for OsRose

Postby PurpleYouko on Thu Sep 14, 2017 4:43 pm

Step 4

Add at least one buff bot to table list_npc_special. Just go in game and figure out the coordinates for where you want to place it. getting the facing direction right might take some time. It's pretty awkward
Set the "buffbot" field to 1 and the "isactive" field to 1

Step 5

Now we start to modify some loading code.
open up startup.cpp and find function bool CWorldServer::LoadNPCsSpecial( )

modify the query to add the field "buffbot" to it in position 10
  1. MYSQL_RES *result = DB->QStore("SELECT type,map,dir,x,y,dialogid,eventid,tempdialogid,name,isactive,buffbot FROM list_npcs_special where isactive='1' ");


now add a line of code to load the boolean "buffbot" value
add it in this part of the code as shown
  1. thisnpc->clientid = GetNewClientID();
  2.         thisnpc->npctype = atoi(row[0]);
  3.         thisnpc->posMap = atoi(row[1]);
  4.         thisnpc->dir = (float)atof(row[2]);
  5.         thisnpc->pos.x = (float)atof(row[3]);
  6.         thisnpc->pos.y = (float)atof(row[4]);
  7.         thisnpc->thisnpc = GetNPCDataByID( thisnpc->npctype );
  8.         thisnpc->buffbot = atoi(row[10]);
  9.         if( thisnpc->thisnpc == NULL)
  10.         {
  11.            Log(MSG_LOAD,"The NPC %i has not been found!, it won't be displayed",thisnpc->npctype);
  12.             delete thisnpc;
  13.             continue;
  14.         }


Oh crap! i forgot a step. we need to edit the CHR file so that our new NPC actually uses a visual model. Otherwise we just have invisible NPCs. lol
Back with instructions on that shortly
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: [HELP] Buff Fairy's for OsRose

Postby PurpleYouko on Thu Sep 14, 2017 4:59 pm

Step 6

Edit that pesky CHR file
It's actually realllllllllly easy to do this. Just grab the CHR editor by Maxxon and Sethy and load up the CHR file that you will find in your extracted VFS. 3ddata/NPC/LIST_NPC.CHR
load the file then jump to the row in which you want to insert the NPC copy. In my case this is row 1046. The exact same row as i used in the STB
Type the row you wish to copy from in the box (in my case 1030 where the fairy lives) and click "copy" then save the modified CHR file. Your target NPC will be copied into your new location. The name of teh NPC is determined by the STL which we did earlier so nothing more to do here.
buff fairy CHR.jpg


NOTE: If you are NOT using KTRose pre-evo or KTRose 137 you will need to save your STB, STL and CHR back into your VFS. If you happen to be using one of my client versions then you won't need to as it will load in quite happily directly from the extracted files as long as the file structure mirrors the VFS. I just extracted all of mine into a 3ddata folder in the client root directory and it loads everything from there.

Now I'm gonna jump into my game and see what I have.
And here she is. My new buff fairy :D
buff fairy ingame.jpg


In the next episode we are going to figure out how to detect a buff fairy directly from the "buffme" command without the need for all that messy code that checks a bunch of specific cases.
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: [HELP] Buff Fairy's for OsRose

Postby PurpleYouko on Thu Sep 14, 2017 5:24 pm

So i just had a thought.
It will actually save a lot of coding if we don't have to go through the process of setting the buff power by map.
How about we go and add another field to the db table "buffpower" then we can set the value in the database externally and just read it into the server directly.
buffbot_table2.jpg


Now as before we need to add something to the CNPC structure
  1. // -----------------------------------------------------------------------------------------
  2. // A typical npc
  3. // -----------------------------------------------------------------------------------------
  4. struct CNPC
  5. {
  6.     unsigned short clientid;
  7.     fPoint pos;
  8.     float dir;
  9.     unsigned short posMap;
  10.     unsigned npctype;
  11.     CNPCData* thisnpc;
  12.     unsigned dialog;
  13.     long int event;
  14.     clock_t lastAiUpdate;   //LMA: AIP.
  15.     bool buffbot;
  16.     unsigned int buffpower;
  17. };


I'm just flying by the seat of my pants here.
None of this is pre-coded.
You are seeing the evolution of new stuff as ideas occur to me. This is the way I work :D

Anyway, now we need to go to startup again and modify that query then add the code to read "buffpower" into the npc structure in game
OK perhaps we shouldn't set the default buffpower to 1000. lol. It adds the value to all the existing entries in the table. It doesn't really matter since only our buffbots have the boolean (tinyint) value "buffbot" set to 1 but it's a bit strange to see all those NPCs with a buffpower of 1000 :D
So anyway I set my Zant buffbot with a buffpower of 3000 for testing.

now onto the code
here is the query
  1. MYSQL_RES *result = DB->QStore("SELECT type,map,dir,x,y,dialogid,eventid,tempdialogid,name,isactive,buffbot,buffpower FROM list_npcs_special where isactive='1' ");


And here is the loading code (in situ)
  1. thisnpc->npctype = atoi(row[0]);
  2.         thisnpc->posMap = atoi(row[1]);
  3.         thisnpc->dir = (float)atof(row[2]);
  4.         thisnpc->pos.x = (float)atof(row[3]);
  5.         thisnpc->pos.y = (float)atof(row[4]);
  6.         thisnpc->thisnpc = GetNPCDataByID( thisnpc->npctype );
  7.         thisnpc->buffbot = atoi(row[10]);
  8.         thisnpc->buffpower = atoi(row[11]);
  9.         if( thisnpc->thisnpc == NULL)
  10.         {
  11.            Log(MSG_LOAD,"The NPC %i has not been found!, it won't be displayed",thisnpc->npctype);
  12.             delete thisnpc;
  13.             continue;
  14.         }


So that gets us back to where we were before I added this bit
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: [HELP] Buff Fairy's for OsRose

Postby PurpleYouko on Thu Sep 14, 2017 5:43 pm

So now for the actual code.

I'm going to start from scratch here so follow along carefully

First we are going to need a function in gmcmds.cpp to control all this stuff. We could just do it directly in the "buffme" command but it's probably better to follow convention and make a dedicated function to control it all.
So go into worldserver.h and add a new prototype like this
  1. bool pakGMGiveBuff(CPlayer* thisClient, CPlayer* targetClient, int skillID, int strength); // by Drakia
  2.         bool pakFairyBuff(CPlayer* Target); //by PY
  3.         bool pakGMMaxStats(CPlayer* thisClient);

As you can see I placed my new function "pakFairyBuff" right after "pakGMGiveBuff"
It wouldn't really work to just use the pakGMGive buff since that function requires a caster (CPlayer* thisclient) as well as a target. typically thisclient would be the GM using the command so her INT value would determine the strength of the buff.
We are going to use the buffpower of the buff fairy from our database table and the skills will be determined later so we don't need to send anything other than the target

The buffme command structure now become ridiculously simple
  1.  
  2. if (strcmp(command, "buffme")==0)
  3.     {
  4.         pakFairyBuff(thisclient);
  5.         return true;
  6.     }

All we need to do here is just call the function and return true. (never return false from the commands functions unless you want to lock your player out of the server. they will still be logged in but they will end up frozen :D )
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: [HELP] Buff Fairy's for OsRose

Postby PurpleYouko on Thu Sep 14, 2017 7:37 pm

So now we write the pakBuffFairy() function
It goes further down gmcmds.cpp
immediately after Drakia's pakGMBuffs in fact. Seems a good a place as any to put it

here is the function
  1. // Buff fairy function. Like GM buffs but not really......
  2. bool CWorldServer::pakFairyBuff(CPlayer* Target)
  3. {
  4.     //so we called the buffme command. Now let's see if we are anywhere near a buff bot
  5.     //first what map are we in?
  6.     CMap* thisMap = GServer->MapList.Index[Target->Position->Map];
  7.     //so now we know the map. let's search for buffbots in this map
  8.     //initialize some stuff
  9.     UINT buffpower = 0;
  10.     for(int j=0;j<thisMap->NPCList.size();j++)
  11.     {
  12.         CNPC* npc = thisMap->NPCList.at(j);
  13.         if(npc->buffbot == true && npc->buffpower > 999)    //found a buffbot in this map. Strangely kept finding others besides teh buff fairy so added the second condition
  14.         {
  15.             Log(MSG_DEBUG,"found a buffbot in this map NPC id %i", npc->npctype);
  16.             float dx = Target->Position->current.x - (float)(npc->pos.x);
  17.             float dy = Target->Position->current.y - (float)(npc->pos.y);
  18.             float distance = sqrt((dx*dx) + (dy*dy));
  19.             if (distance < 20)  //it's within 20 distance of me so I can get the buff
  20.             {
  21.                 buffpower = npc->buffpower;
  22.             }
  23.         }
  24.     }
  25.     if(buffpower == 0)
  26.     {       //buffpower is still zero so we didn't find a buffbot in range
  27.         SendPM(Target,"Sorry! there are no buff bots in range.");
  28.     }
  29.     else
  30.     {       //Got buff bot so do de buffs
  31.         Target->GiveBuffsFromBot( Target, 3202, buffpower );
  32.         Target->GiveBuffsFromBot( Target, 3203, buffpower );
  33.         Target->GiveBuffsFromBot( Target, 3204, buffpower );
  34.         Target->GiveBuffsFromBot( Target, 3205, buffpower );
  35.         SendPM(Target,"Congratulations! You received buffs from the buff fairy with buffpower %i", buffpower);
  36.     }
  37.     return true;
  38. }

feel free to comment out the LOG_DEBUG messages. They just prove that it all works :D

And don't forget to create the prototype for this function in worldserver.h
here is is in situ
  1. bool pakGMDebuff(CPlayer* thisClient); // by Drakia
  2.         bool pakGMGiveBuff(CPlayer* thisClient, CPlayer* targetClient, int skillID, int strength); // by Drakia
  3.         bool pakFairyBuff(CPlayer* Target); //by PY
  4.         bool pakGMMaxStats(CPlayer* thisClient);
  5.         bool pakGMGMSkills ( CPlayer* thisclient, char* name);
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

PreviousNext

Return to Support - OsRose Emulator

Who is online

Users browsing this forum: No registered users and 6 guests

cron