19 Feb, 2014, jupiter wrote in the 1st comment:
Votes: 0
Running Smaug 1.4. I am wanting a new player to buy a pet and group with said pet. While fighting together, the pet would gain experience and level up along with the player. Then they could explore tougher areas together. I have petsave enabled.
Any ideas of how to code this in?
19 Feb, 2014, plamzi wrote in the 2nd comment:
Votes: 0
jupiter said:
Running Smaug 1.4. I am wanting a new player to buy a pet and group with said pet. While fighting together, the pet would gain experience and level up along with the player. Then they could explore tougher areas together. I have petsave enabled.
Any ideas of how to code this in?


I'm not familiar with your particular codebase and what "petsave" does exactly, but you will definitely find the answer by looking at how player characters gain experience. There's a lot of code you can re-use/re-purpose when you are trying to create a type of mob that has the properties of a player character. More than likely, you have all the code you need, but it's designed to only apply to PC's.
20 Feb, 2014, quixadhal wrote in the 3rd comment:
Votes: 0
Heh, in my old DikuMUD, I made it so ALL mobs gain XP. Nothing more fun than having some big ogre kill a few players and level up, so the players realize he's tougher and also has the loot he scavanged from the corpses of his previous victims. :)
20 Feb, 2014, Rarva.Riendf wrote in the 4th comment:
Votes: 0
You can make it work in a few line of code. Save the pet in the character files with the same code you save a mobile -and if you do not have it, just use the common code between char and mobiles structure.
I made my pet level when the player itself level to make it fast and simple as well.
After that it is up to your imagiantion (can the pet be charmed by another player/mobile, what happens when it dies etc etc)
21 Feb, 2014, Sharmair wrote in the 5th comment:
Votes: 0
The option of having pets (or any mob) get exp and level is something that came as a freebie
with the SMAUG codebase I work with when multi-classing was put in. The only thing that needed
changing just for this was the saving and loading of pets, as in stock only the strings and a couple
other things save (a stock pet first loads a mob just like a reset pop, then reads in and changes
the strings, position and flags and might have different max hp and even level from one log in to
another).

I took a peek at some pre multi-class files and it seems stock SMAUG actually has a bit of
support for mob exp, it seems the get_exp_base function is mob safe and returns a valid and
useable number (1000). The gain_exp and group_gain functions have a check for NPC near the
top that would have to be changed, then (VERY IMPORTANT) you will have to make sure those
functions AND any functions they call (advance_level I see that will be of major concern) are
mob safe (make sure they don't assume a PC with act flags, assume a pcdata stuct, or use
race or class assuming they are within the PC range). You also probably want to have only pet
mobs get exp, so other then just removing the IS_NPC escape, change it to still exit the function
with a non pet mob. Then the fwrite_mobile and fread_mobile functions should be changed to
save and load exp, level and any other data you would like to make persistent(max hp etc come
to mind). One issue I foresee is if the pet does not have a PC class (in stock the first NPC
classes line up with the stock PC classes, though you might have changed this if you changed
the PC classes around), assuming you have made it so an out of range class does not crash
the MUD (in that make things mob safe I mentioned before), an out of range class pet will
(probably) not get any hp gain at all, and the gain for in range classes will be based on what
the PC class that has the same class number (in stock the same) would gain, you might want
to put in code to replace it with a pet based gain, though that is up to how you want it to
work.

Note to others: petsave is a cset option in SMAUG put in when they added persistent pets,
I assume it was put in to turn it off and on in the testing stage. It does just as the name
implies, it turns on and off the saving of a pet to the player file.
05 Mar, 2014, jupiter wrote in the 6th comment:
Votes: 0
Thanks so much to everyone who gave me plenty of great pointers! I have the mob (pets) gaining AND saving levels now. Still have some bugs to work out and other ideas to add. Again, thank you all!
0.0/6