EOSERV Forum > EOSERV > Pet system [tutorial] (outdated)
Topic is locked.
Page: << 1 2 3 4 5 6 7 8 >>
Pet system [tutorial] (outdated)
Author Message
Post #33375 Re: RELEASE: Pet system [tutorial]
epicnoob posted: (27th Feb 2010 12:50 am)

Yea that would be nice and did u get jimbos code working? cuz i tried it and worked fine then i made ananas spawn apozen now all i really need is ur despawn cmd to work


I posted a reply to Jimbo's code with a version I modified, that works. I updated it so that eggs or whatever other item you have to summon pets don't dissapear when used. 


---
Do what thou wilt shall be the whole of the law. Love is the law, love under will. There is no law
beyond do what thou wilt. 93/93
15 years, 10 weeks ago
Post #33376 Re: RELEASE: Pet system [tutorial]

Yea i still dont know how to do that make the item not dissapear 1s u used it already

---
Fate-Gaming/Forgotten Memories Owner.
15 years, 10 weeks ago
Post #33377 Re: RELEASE: Pet system [tutorial]
epicnoob posted: (27th Feb 2010 12:54 am)

Yea i still dont know how to do that make the item not dissapear 1s u used it already

put this code below this "if(id == ItemID)
{"



and above "if(this->player->character->has_pet)"



code:

this->player->character->Save(); //this may be unnessasary
                     this->player->character->AddItem(id, 1);//adds back the item after it's use
                     this->player->character->Save();

Edit:
you don't have to modify anything in the AddItem code, just leave it the way it is, it already knows what item ID to change because it's an if statement for a particular item

---
Do what thou wilt shall be the whole of the law. Love is the law, love under will. There is no law
beyond do what thou wilt. 93/93
15 years, 10 weeks ago
Post #33379 Re: RELEASE: Pet system [tutorial]

Alright thx man im still trying to add ur cmd ill let u know when i got it

---
Fate-Gaming/Forgotten Memories Owner.
15 years, 10 weeks ago
Post #33380 Re: RELEASE: Pet system [tutorial]
epicnoob posted: (27th Feb 2010 01:00 am)

Alright thx man im still trying to add ur cmd ill let u know when i got it


well like i said, if you show me what errors you're getting i may be able to help more
---
Do what thou wilt shall be the whole of the law. Love is the law, love under will. There is no law
beyond do what thou wilt. 93/93
15 years, 10 weeks ago
Post #33382 Re: RELEASE: Pet system [tutorial]

Here are the errors

C:\Documents and Settings\Mando\Escritorio\trunk\trunk\src\handlers\Talk.cpp||In member function 'bool EOClient::Handle_Talk(PacketFamily, PacketAction, PacketReader&, int)':|

C:\Documents and Settings\Mando\Escritorio\trunk\trunk\src\handlers\Talk.cpp|135|error: 'usercmd' was not declared in this scope|

C:\Documents and Settings\Mando\Escritorio\trunk\trunk\src\handlers\Talk.cpp|135|error: 'userar' was not declared in this scope|

C:\Documents and Settings\Mando\Escritorio\trunk\trunk\src\handlers\Talk.cpp|139|warning: suggest parentheses around assignment used as truth value|

||=== Build finished: 2 errors, 1 warnings ===|

Edit:

I Narrowed it down to only 1 error

C:\Documents and Settings\Mando\Escritorio\trunk\trunk\src\handlers\Talk.cpp||In member function 'bool EOClient::Handle_Talk(PacketFamily, PacketAction, PacketReader&, int)':|
C:\Documents and Settings\Mando\Escritorio\trunk\trunk\src\handlers\Talk.cpp|135|error: 'command' was not declared in this scope|
||=== Build finished: 1 errors, 0 warnings ===|

---
Fate-Gaming/Forgotten Memories Owner.
15 years, 10 weeks ago
Post #33383 Re: RELEASE: Pet system [tutorial]
epicnoob posted: (27th Feb 2010 01:15 am)

Here are the errors

C:\Documents and Settings\Mando\Escritorio\trunk\trunk\src\handlers\Talk.cpp||In member function 'bool EOClient::Handle_Talk(PacketFamily, PacketAction, PacketReader&, int)':|

C:\Documents and Settings\Mando\Escritorio\trunk\trunk\src\handlers\Talk.cpp|135|error: 'usercmd' was not declared in this scope|

C:\Documents and Settings\Mando\Escritorio\trunk\trunk\src\handlers\Talk.cpp|135|error: 'userar' was not declared in this scope|

C:\Documents and Settings\Mando\Escritorio\trunk\trunk\src\handlers\Talk.cpp|139|warning: suggest parentheses around assignment used as truth value|

||=== Build finished: 2 errors, 1 warnings ===|

Edit:

I Narrowed it down to only 1 error

C:\Documents and Settings\Mando\Escritorio\trunk\trunk\src\handlers\Talk.cpp||In member function 'bool EOClient::Handle_Talk(PacketFamily, PacketAction, PacketReader&, int)':|
C:\Documents and Settings\Mando\Escritorio\trunk\trunk\src\handlers\Talk.cpp|135|error: 'command' was not declared in this scope|
||=== Build finished: 1 errors, 0 warnings ===|

ok if at some point you changed usercmd to command that could be the issue. Other than that I don't really know what the problem could be, because I never got any errors when i wrote the command

---
Do what thou wilt shall be the whole of the law. Love is the law, love under will. There is no law
beyond do what thou wilt. 93/93
15 years, 10 weeks ago
Post #33386 Re: RELEASE: Pet system [tutorial]

Yea cuz if i use urscmd it gives me the errors

---
Fate-Gaming/Forgotten Memories Owner.
15 years, 10 weeks ago
Post #33393 Re: RELEASE: Pet system [tutorial]


Here is my command of a pet being dismissed using (Command) etc.

Just write #dismiss and it will leave.
The server message is only showable to the player using the command.
You could just erase the line.

else if (command.length() >= 7 && command.compare(0,7,"dismiss") == 0 && this->player->character->has_pet)
                {
                    UTIL_PTR_LIST_FOREACH(this->player->character->map->characters, Character, character)
                        {
                            if (this->player->character->InRange(*character))
                            {
                                this->player->character->pet->RemoveFromView(*character);
                            }
                        }
                            erase_first(this->player->character->map->npcs, this->player->character->pet);
                            this->player->character->pet->Release();
                            this->player->character->has_pet = false;
                            this->player->character->ServerMsg("NPC left!");
                }

---
"Pineapples and shit."
15 years, 10 weeks ago
Post #33435 Re: RELEASE: Pet system [tutorial]

I tried the code ananas but it only worked for admin and i put it under the # cmds cuz players tried it and it didnt work

---
Fate-Gaming/Forgotten Memories Owner.
15 years, 10 weeks ago
Post #33437 Re: RELEASE: Pet system [tutorial]
ReemDead posted: (26th Feb 2010 03:14 am)

Jimbo posted: (24th Feb 2010 02:29 am)

If anyone wants to let characters spawn a pet by using an item place this in item.cpp


Under this..

               

                EIF_Data *item = this->server->world->eif->Get(id);
                reply.SetID(PACKET_ITEM, PACKET_REPLY);
                reply.AddChar(item->type);
                reply.AddShort(id);


Code:


if(id == ItemID)
                {
                    if(!this->player->character->has_pet)
                    {
                        this->player->character->has_pet = true;
                        unsigned char index = this->player->character->map->GenerateNPCIndex();
                        if (index > 250)
                        {
                            break;
                        }
                        if (this->player->character->PetCounter > 1)
                        {
                            break;
                        }
                       this->player->character->pet=newNPC(this->player->character->map,NpcID,this->player->character->x+1,this->player->character->y, 1, 1, index, true, true);
                        this->player->character->pet->SetOwner(this->player->character);
                        this->player->character->map->npcs.push_back(this->player->character->pet);
                        this->player->character->pet->Spawn();
                        this->player->character->PetCounter = 1;
                    }
                }


Just replace NpcID / ItemID with the item / npc you wish to use.


Edit: Remove PetCounter if you don't want it.




This does not work, at all. Even after I put

#include npc.hpp

I tried modding this code in several different ways, but it just doesn't want to work. It compiles fine however, I can't seem to get my eggs to do anything.



Edit: tinkered with it, fixed it. put it where Jimbo said to put it. also make sure you 

Edit: Figured out how to get the item to stay after use(choppy but works)

#include npc.hpp


if(id == ItemID)
                {


                     this->player->character->Save(); //this may be unnessasary
                     this->player->character->AddItem(id, 1);//adds back the item after it's use
                     this->player->character->Save();


                    if(!this->player->character->has_pet)
                    {

                        unsigned char index = this->player->character->map->GenerateNPCIndex();
                        if (index > 250)

                        {

                        break;

                        }

                        this->player->character->pet = new NPC(this->player->character->map, NpcID, this->player->character->x + 1,this->player->character->y, 1, 1, index, true, true);
                        this->player->character->pet->Spawn();
                        this->player->character->pet->SetOwner(this->player->character);
                        this->player->character->has_pet = true;
                        //this->player->character->AddItem(682, 1);
                        this->player->character->map->npcs.push_back(this->player->character->pet);


                        this->player->character->Save();

                    }
                }
I set the item type as reward in the pub, with exp bonus of 0.


I edited your code to dismiss the pet if the item is used again, the pet can be summoned and dismissed as many times as needed by clicking the reward item. Now there's no need to type either command to summon or dismiss.



in "npc.cpp" ; 

#include "npc.hpp"


under:



if (this->player->character->HasItem(id))
{
EIF_Data *item = this->server->world->eif->Get(id);
reply.SetID(PACKET_ITEM, PACKET_REPLY);
reply.AddChar(item->type);
reply.AddShort(id);


Add:

if(id == ItemID)
{


this->player->character->Save(); //this may be unnessasary
this->player->character->AddItem(id, 1);//adds back the item after it's use
this->player->character->Save();


if(!this->player->character->has_pet)
{

unsigned char index = this->player->character->map->GenerateNPCIndex();
if (index > 250)

{

break;

}

  this->player->character->pet = new NPC(this->player->character->map, NpcID, this->player->character->x + 1,this->player->character->y, 1, 1, index, true, true);
this->player->character->pet->Spawn();
this->player->character->pet->SetOwner(this->player->character);
this->player->character->has_pet = true;
//this->player->character->AddItem(682, 1);
this->player->character->map->npcs.push_back(this->player->character->pet);


this->player->character->Save();

}


else if(this->player->character->has_pet = true)
{
UTIL_PTR_LIST_FOREACH(this->player->character->map->characters, Character, character)
{
if (this->player->character->InRange(*character))
{
this->player->character->pet->RemoveFromView(*character);
}
}
erase_first(this->player->character->map->npcs, this->player->character->pet);
this->player->character->pet->Release();
this->player->character->has_pet = false;
}
}
---
Web developer, currently looking for graphic artists / designers.
15 years, 10 weeks ago
Post #33449 Re: RELEASE: Pet system [tutorial]
Klutz posted: (27th Feb 2010 11:13 pm)

ReemDead posted: (26th Feb 2010 03:14 am)

Jimbo posted: (24th Feb 2010 02:29 am)

If anyone wants to let characters spawn a pet by using an item place this in item.cpp


Under this..

               

                EIF_Data *item = this->server->world->eif->Get(id);
                reply.SetID(PACKET_ITEM, PACKET_REPLY);
                reply.AddChar(item->type);
                reply.AddShort(id);


Code:


if(id == ItemID)
                {
                    if(!this->player->character->has_pet)
                    {
                        this->player->character->has_pet = true;
                        unsigned char index = this->player->character->map->GenerateNPCIndex();
                        if (index > 250)
                        {
                            break;
                        }
                        if (this->player->character->PetCounter > 1)
                        {
                            break;
                        }
                       this->player->character->pet=newNPC(this->player->character->map,NpcID,this->player->character->x+1,this->player->character->y,1,1, index, true, true);
                        this->player->character->pet->SetOwner(this->player->character);
                        this->player->character->map->npcs.push_back(this->player->character->pet);
                        this->player->character->pet->Spawn();
                        this->player->character->PetCounter = 1;
                    }
                }


Just replace NpcID / ItemID with the item / npc you wish to use.


Edit: Remove PetCounter if you don't want it.




This does not work, at all. Even after I put

#include npc.hpp

I tried modding this code in several different ways, but it just doesn't want to work. It compiles fine however, I can't seem to get my eggs to do anything.



Edit: tinkered with it, fixed it. put it where Jimbo said to put it. also make sure you 

Edit: Figured out how to get the item to stay after use(choppy but works)

#include npc.hpp


if(id == ItemID)
                {


                     this->player->character->Save(); //this may be unnessasary
                     this->player->character->AddItem(id, 1);//adds back the item after it's use
                     this->player->character->Save();


                    if(!this->player->character->has_pet)
                    {

                        unsigned char index = this->player->character->map->GenerateNPCIndex();
                        if (index > 250)

                        {

                        break;

                        }

                        this->player->character->pet = new NPC(this->player->character->map, NpcID, this->player->character->x + 1,this->player->character->y, 1, 1, index, true, true);
                        this->player->character->pet->Spawn();
                        this->player->character->pet->SetOwner(this->player->character);
                        this->player->character->has_pet = true;
                        //this->player->character->AddItem(682, 1);
                        this->player->character->map->npcs.push_back(this->player->character->pet);


                        this->player->character->Save();

                    }
                }
I set the item type as reward in the pub, with exp bonus of 0.


I edited your code to dismiss the pet if the item is used again, the pet can be summoned and dismissed as many times as needed by clicking the reward item. Now there's no need to type either command to summon or dismiss.



in "npc.cpp" ; 

#include "npc.hpp"


under:



if (this->player->character->HasItem(id))
{
EIF_Data *item = this->server->world->eif->Get(id);
reply.SetID(PACKET_ITEM, PACKET_REPLY);
reply.AddChar(item->type);
reply.AddShort(id);


Add:

if(id == ItemID)
{


this->player->character->Save(); //this may be unnessasary
this->player->character->AddItem(id, 1);//adds back the item after it's use
this->player->character->Save();


if(!this->player->character->has_pet)
{

unsigned char index = this->player->character->map->GenerateNPCIndex();
if (index > 250)

{

break;

}

  this->player->character->pet = new NPC(this->player->character->map, NpcID, this->player->character->x + 1,this->player->character->y, 1, 1, index, true, true);
this->player->character->pet->Spawn();
this->player->character->pet->SetOwner(this->player->character);
this->player->character->has_pet = true;
//this->player->character->AddItem(682, 1);
this->player->character->map->npcs.push_back(this->player->character->pet);


this->player->character->Save();

}


else if(this->player->character->has_pet = true)
{
UTIL_PTR_LIST_FOREACH(this->player->character->map->characters, Character, character)
{
if (this->player->character->InRange(*character))
{
this->player->character->pet->RemoveFromView(*character);
}
}
erase_first(this->player->character->map->npcs, this->player->character->pet);
this->player->character->pet->Release();
this->player->character->has_pet = false;
}
}
I was actually trying to do this lol. Thanks Klutz, I'll test this immediately 

Edit: Epic Win dude, works perfectly
---
Do what thou wilt shall be the whole of the law. Love is the law, love under will. There is no law
beyond do what thou wilt. 93/93
15 years, 10 weeks ago
Post #33494 Re: RELEASE: Pet system [tutorial]

Nice job man. Your code is similar to the pets I coded in FE. Great minds think alike.

---
http://www.addipop.com
15 years, 10 weeks ago
Post #33575 Re: RELEASE: Pet system [tutorial]

sweet coding. how do you make it attack npc now?

also.. anyone want to upload a project file with the items added in too? i'm nub to the extreme with this coding.

15 years, 9 weeks ago
Post #33601 Re: RELEASE: Pet system [tutorial]


It only attacks if a player attacks the pet.

By typing #attack a bool turns from false to true.
The #follow button changes it back to false but most of the time the pets don't listen to it. It just turn the players damage to the pet to false but the pet keeps on attacking. I'm almost finished with an #attack <player> script. Might of releasing it here.

---
"Pineapples and shit."
15 years, 9 weeks ago
Page: << 1 2 3 4 5 6 7 8 >>
Topic is locked.
EOSERV Forum > EOSERV > Pet system [tutorial] (outdated)