EOSERV Forum > EOSERV > Fishing system tutorial [RELEASE]
Topic is locked.
Page: << 1 2 >>
Fishing system tutorial [RELEASE]
Author Message
Post #36596 Fishing system tutorial [RELEASE]

This is a basic fishing system that I wrote. It uses the .ini file settings from Ananas' harvesting system. I have only tested this on r187 so you can try on other revisions if you would like.

What this does is, if you are on a specific coordination facing a specific direction with a fishing rod, and you press ctrl it will say "Waiting for a bite.." then after 10 seconds (im going to make it a random time between 10-60seconds when i could be bothered) it will either say "Youhave caught a fish +name+" and give u the item or "You failed to catch a fish +name+".

This probably will be a long process that you are going to follow very closely.

First we will edit the "character.cpp" file.

Now find this line (around about line 131):

this->partner = GetRow<std::string>(row, "partner");

And ADD BELOW it:

this->fishing = 0;

This is the end of editing "character.cpp"

Now to edit "character.hpp"

Find this line (around about line 91):

int usage;

And ADD BELOW it:

int fishing;

This is the end of editing "character.hpp"

Now to edit "Attack.cpp".

Find this line (around about line 42):

this->player->character->Attack(direction);

And ADD BELOW it:

int Map, X, Y, Dir, Wep;
   for(int i = 0 ; i < static_cast<int>(this->server->world->fish_config["LocationAmount"]) ; i++)
   {
                Wep = static_cast<int>(this->server->world->fish_config["Weapon"]);
                Map = static_cast<int>(this->server->world->fish_config[util::to_string(i+1) + ".map"]);
                X = static_cast<int>(this->server->world->fish_config[util::to_string(i+1) + ".x"]);
                Y = static_cast<int>(this->server->world->fish_config[util::to_string(i+1) + ".y"]);
                Dir = static_cast<int>(this->server->world->fish_config[util::to_string(i+1) + ".dir"]);
                if(this->player->character->mapid == Map && this->player->character->x == X &&this->player->character->y==Y&&this->player->character->direction==Dir && this->player->character->paperdoll[Character::Weapon] == Wep)
                    {
                        this->player->character->fishing = 1;
                        this->server->world->fishing(this->player->character);
                        break;
                    }
   }

This is the end of editing "Attack.cpp".

Now to edit "World.cpp"

Find these lines (around about 49-64):

void world_act_npcs(void *world_void)
{
 World *world(static_cast<World *>(world_void));

 double current_time = Timer::GetTime();
 UTIL_PTR_VECTOR_FOREACH(world->maps, Map, map)
 {
  UTIL_PTR_VECTOR_FOREACH(map->npcs, NPC, npc)
  {
   if (npc->alive && npc->last_act + npc->act_speed < current_time)
   {
    npc->Act();
   }
  }
 }
}

And ADD BELOW them:

void fishcatch(void *world_void)
{
 World *world(static_cast<World *>(world_void));
 PacketBuilder reply;
 int ItemID, ItemA, Map, X, Y, Dir, Wep;
    for(int i = 0 ; i < static_cast<int>(world->fish_config["LocationAmount"]) ; i++)
    {
        ItemID = static_cast<int>(world->fish_config["ItemID"]);
        ItemA = static_cast<int>(world->fish_config["ItemAmount"]);
        Wep = static_cast<int>(world->fish_config["Weapon"]);
        Map = static_cast<int>(world->fish_config[util::to_string(i+1) + ".map"]);
        X = static_cast<int>(world->fish_config[util::to_string(i+1) + ".x"]);
        Y = static_cast<int>(world->fish_config[util::to_string(i+1) + ".y"]);
        Dir = static_cast<int>(world->fish_config[util::to_string(i+1) + ".dir"]);
        UTIL_PTR_VECTOR_FOREACH(world->characters, Character, character)
        if (character->x == X && character->y == Y && character->direction == Dir && character->fishing == 1 && character->mapid == Map && character->paperdoll[Character::Weapon] == Wep)
        {
            int random = util::rand(0 ,150);
            if (random < 25)
            {
                character->fishing = 0;
                character->ServerMsg("You caught a fish " + character->name + ".");
                character->AddItem(1, 1);
                reply.SetID(PACKET_ITEM, PACKET_GET);
                reply.AddShort(0);
                reply.AddShort(ItemA);
                reply.AddThree(ItemID);
                reply.AddChar(character->weight);
                reply.AddChar(character->maxweight);
                character->player->client->SendBuilder(reply);
            }
            else if (random >25)
            {
                character->fishing = 0;
                character->ServerMsg("You failed to catch a fish " + character->name + ".");
            }
        }
    }
}

Now find this line:

this->formulas_config.Read(this->config["FormulasFile"]);

And ADD BELOW it:

this->fish_config.Read(static_cast<std::string>(this->config["FishFile"]));

Now find these lines:

int World::GenerateCharacterID()
{
 return ++this->last_character_id;
}

And ADD BELOW them:

void World::fishing(Character *from)
{
    from->player->character->ServerMsg("Waiting for a bite...");
    TimeEvent *event = new TimeEvent(fishcatch, this, 10.0, 1);
 this->timer.Register(event);
 event->Release();
}

Now find this line:

this->formulas_config.Read(this->config["FormulasFile"]);

And ADD BELOW it:

this->fish_config.Read(this->config["FishFile"]);

This is the end of editing "world.cpp"

Now to edit "world.hpp"

Find this line:

Config formulas_config;

And ADD BELOW it:

Config fish_config;

Find this line:

void Logout(Character *);

And ADD BELOW it:

void fishing(Character *from);

This is the end of editing "world.hpp"

You can now compile your source. If it doesn't compile successfully please post with your errors.

Not finished yet :P

Now to make an .ini file

You will need to go to your trunk/data directory and either Create a new text document and rename it to "fish.ini", or you could copy and paste one of the existing .ini files and rename it to "fish.ini".

Once you have an .ini file you will need to add the contents.

Open up your "fish.ini" file and put this inside it.

# The Item that will be 'caught' ID
ItemID = 1

# Amount of items being gained.
ItemAmount = 1

#Fishing rod's weapon id.
Weapon = 342

# Amount of locations
LocationAmount = 1

# E.g
#1.map = 4
#1.x = 11
#1.y = 9
#1.dir = 1 (0 facing down, 1 facing left, 2 facing up, 3 facing right)

Now save your "fish.ini" file.

Now you will need to open your config.ini file.

Find this:

## FormulasFile (string)
# File containing stat/combat/class formulas
FormulasFile = ./data/formulas.ini

And BELOW ADD this:

## FishFile(string)
# Fish Location File
FishFile = ./data/fish.ini

Now save your "config.ini" file.

Your server should now have a working fishing system.

If anything goes wrong ill try my hardest to fix it. Please tell me if any of the tutorial doesn't make sence.

Thanks,

Grazza

14 years, 2 weeks ago
Post #36598 Re: Fishing system tutorial [RELEASE]

So far so good, untill I reach the Config.ini for the formulas can't find that at all, But I do remember needing it before and finding it, but i cant seem to find it now,


Where exactly is this located?

14 years, 2 weeks ago
Post #36602 Re: Fishing system tutorial [RELEASE]

Just to make sure, What does the fishing column in your database do?

---
"Pineapples and shit."
14 years, 2 weeks ago
Post #36605 Re: Fishing system tutorial [RELEASE]

@helper, Go to your config.ini and press ctrl+F for the search box to pop up and type in FormulasFile, it will lead you straight to what your looking for.

14 years, 2 weeks ago
Post #36607 Re: Fishing system tutorial [RELEASE]

Okay But where is this at:

Open your databas file manager and execute this query:

ALTER TABLE characters ADD fishing INTEGER DEFAULT 0

14 years, 2 weeks ago
Post #36617 Re: Fishing system tutorial [RELEASE]
Ananas posted: (1st May 2010 06:23 am)

Just to make sure, What does the fishing column in your database do?

It checks if the player is fishing.. im not sure if it actually works.. that code is pretty buggy as u can probably see lol

@Helper

You must execute that line of code in you database manager (sqliteman or heidisql or whatever) or just make another column in the characters table called fishing with integer status and default is 0.. if you understand that

14 years, 2 weeks ago
Post #36619 Re: Fishing system tutorial [RELEASE]

Ya I can see that.


Enplanes maybe why He just Released another Fishing code the a 1/3 of urs XD.

14 years, 2 weeks ago
Post #36620 Re: Fishing system tutorial [RELEASE]

Grazza, Its very easy to do that without adding it to the database. It cost space.


Add to character.cpp


this->fishing = 0;



Character.hpp


int fishing;



Then do an if statement (You probably have that one)

if(this->player->character->fishing == 0)
{
Player goes fishing;
this->player->character->fishing = 1;
}

If player is done with fishing the code makes it 0 again.

Like what if the player logs out while fishing? I think it would save it as 1. and the player would be seen as fishing.

Making temp values would just reset them if they log out.

---
"Pineapples and shit."
14 years, 2 weeks ago
Post #36621 Re: Fishing system tutorial [RELEASE]

im pretty sure his doesnt have a timer in his but i havent looked at it

ahh ok thanks ananas ill stick that in now and change it

14 years, 2 weeks ago
Post #37855 Re: Fishing system tutorial [RELEASE]


i get this error

..\src/npc.hpp:170: error: call of overloaded 'NPC(Map*&, short int&, unsigned char&, unsigned char&, unsigned char&, short int&, unsigned char&, bool&)' is ambiguous

13 years, 50 weeks ago
Post #38267 Re: Fishing system tutorial [RELEASE]

Uhm i dont think he says edit the npc one.  It looks like your fishing has compiled erm i dont know thats not a error related to the stuff u just added though.

13 years, 49 weeks ago
Post #48522 Re: Fishing system tutorial [RELEASE]

hey guys im at this part

int Map, X, Y, Dir, Wep;
   for(int i = 0 ; i < static_cast<int>(this->server->world->fish_config["LocationAmount"]) ; i++)
   {
                Wep = static_cast<int>(this->server->world->fish_config["Weapon"]);
                Map = static_cast<int>(this->server->world->fish_config[util::to_string(i+1) + ".map"]);
                X = static_cast<int>(this->server->world->fish_config[util::to_string(i+1) + ".x"]);
                Y = static_cast<int>(this->server->world->fish_config[util::to_string(i+1) + ".y"]);
                Dir = static_cast<int>(this->server->world->fish_config[util::to_string(i+1) + ".dir"]);
                if(this->player->character->mapid == Map && this->player->character->x == X &&this->player->character->y==Y&&this->player->character->direction==Dir && this->player->character->paperdoll[Character::Weapon] == Wep)
                    {
                        this->player->character->fishing = 1;
                        this->server->world->fishing(this->player->character);
                        break;
                    }
   }

 

at the top where it says int Map, X, Y, Dir, Wep do i edit that to where i want it to be and wep and whats dir?

---
stay tuned.
13 years, 36 weeks ago
Post #48531 Re: Fishing system tutorial [RELEASE]

You don't change anything. You just add that into attack.cpp and done. The weapon and (dir)ection can be added in the .ini file you create later on.

---
"Pineapples and shit."
13 years, 36 weeks ago
Post #49295 Re: Fishing system tutorial [RELEASE]


is there anyway to catch 2 items+ if there is please tell me +D

---
stay tuned.
13 years, 34 weeks ago
Post #49335 Re: Fishing system tutorial [RELEASE]
andrewbob1 posted: (16th Sep 2010 10:26 pm)


is there anyway to catch 2 items+ if there is please tell me +D

To do that you need to edit the "fishcatch" function in world.cpp
Replace it with this code to be able to catch two fish(it will load "ItemID2" from the fish config), I don't think it's the best way but it still works.



13 years, 34 weeks ago
Page: << 1 2 >>
Topic is locked.
EOSERV Forum > EOSERV > Fishing system tutorial [RELEASE]