Author | Message | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ![]() ~EDIT 2: You shouldn't use it since this code is outdated! There is my tutorial how to write a pet system on EOSERV :) I don't think it's something special. 1. NPC class. First we have to add some important variables to NPC class: (npc.hpp) public: bool pet; Now remake class constructor to support new NPC type: Declaration (npc.hpp): NPC(Map *map, short id, unsigned char x, unsigned char y, unsigned char spawn_type, short spawn_time, unsigned char index, bool temporary = false, bool pet = false); Implementation (npc.cpp): NPC::NPC(Map *map, short id, unsigned char x, unsigned char y, unsigned char spawn_type, short spawn_time, unsigned char index, bool temporary, bool pet) ..and now we need to remake NPC::Act() function to handle pet actions: Too much code :P Get it HERE. This function will let you set new owner for pet: void NPC::SetOwner(Character *character) 2. Pet transfer between maps. Add some variables to Character class that we will need: public: NPC *pet; At class constructor add: this->pet = 0; Now add fucntion that will transfer pet: Declaration (character.hpp): (as public) void PetTransfer(); Implementation: (character.cpp): void Character::PetTransfer() Go to map.cpp, find Map::Walk(Character *from, Direction direction, bool admin) function and find map warp code, you have to call Character::PetTransfer() here: Map_Warp *warp; 3. Pet initialization Now we need to make safe pet initialization on player login, go to handlers/Welcome.cpp, find case PACKET_MSG and after client state is set to Playing add code: unsigned char index = this->player->character->map->GenerateNPCIndex(); 4. Player commands There are 2 example commands for player to controll pet: #attack - set pet to attack closest player in range. #follow - if pet is attacking someone, it will make it following you. else if (command.length() >= 6 && command.compare(0,6,"follow") == 0 && this->player->character->has_pet) 5. (finally) Spawn a pet There are admin commands for spawn and delete pets from players: else if (command.length() >= 2 && command.compare(0,2,"sp") == 0 && arguments.size() >= 2 && this->player->character->admin >= static_cast<int>(this->server->world->admin_config["shutdown"])) 6. Example codes You can also make your pet immortal when it follows you, and able to die when it fight with some player, you have to add that statement in NPC::Damage() function: if(from != this->owner && this->attack_command) //rest of code } That's all, have fun guys ;D Leave comment how it works. If i forgot something or did something wrong, let me know it here. ~EDIT 1: Tutorial updated, added SetOwner() function code.
|
| ![]() Looks pretty rock solid to me.
|
| ![]() I have just tested this code again and everything works for me :P
|
| ![]() In what file do i have to put that? public: NPC *pet; At class constructor add: this->pet = 0;
|
| ![]() EpicAngel posted: (21st Feb 2010 03:22 pm)I guess here At class constructor add:
|
| ![]() Yeah but where IS class constructor?
|
| ![]() EpicAngel posted: (21st Feb 2010 04:05 pm) God damn I can't figure it out either. --- Web developer, currently looking for graphic artists / designers.
|
| ![]() i am working on this with epicangel but where is class constructor plz be more specific --- Live and let live. Hurt but do not kill. Finish what you start. NEVER GIVE UP!!!
|
| ![]() Character::Character()
|
| ![]() Seriously i cant find the class constructor ffs..
|
| ![]() Really ? How you want to write it if you don't know what's class constructor ?
|
| ![]() Well everything seems to be fine for me, but some 1 single error you might can help me out: C:\(path)\src\player.hpp|1341|error: 'class NPC' has no member named 'SetOwner'| How do i fix this :)
|
| ![]() Jimmyee posted: (21st Feb 2010 07:52 pm) If you just tell me wtf it is i can finish it alright?
|
| ![]() Look in the character.cpp There you should see lines with this-> entrys. There you add this->pet = 0;
|
| ![]() I got: --- Web developer, currently looking for graphic artists / designers. |