EOSERV Forum > EOSERV > NPC speech code
Page: << 1 >>
NPC speech code
Author Message
Post #198497 NPC speech code

Heyy, just wondering if anyone has NPC speech for the latest rev? Found a few topics on it but on one topic Apollo said the way it was done was essentially terrible.


And the other is out dated code. I guess I could try recoding it to  bring it up to the latest rev. However if anyone has it already made it'll speed up my servers development and free up some time so I can do other things.


Cheers!! Looks forward to replies.

8 years, 27 weeks ago
Post #198499 Re: NPC speech code

I have a code I used last year that gives the option for NPCS to all speak at once, or for some to skip the talk so only a few speak.

Honestly It's not the best of code, I probably wouldn't use it now xd. I'm sure Apollo won't like this one much either.

But yeah, World.cpp:

void world_npcs_talk(void *world_void)

{

    World *world(static_cast<World *>(world_void));


    UTIL_FOREACH(world->maps, map)

    {

        UTIL_FOREACH(map->npcs, npc)

        {

            if(static_cast<std::string>(world->config["NpcTalkType"]) == "whole")

            {

                int rand_msg = util::rand(1,3);

                std::string msg_1 = static_cast<std::string>(world->config[util::to_string(npc->id)+".NpcMessage1"]);

                std::string msg_2 = static_cast<std::string>(world->config[util::to_string(npc->id)+".NpcMessage2"]);

                std::string msg_3 = static_cast<std::string>(world->config[util::to_string(npc->id)+".NpcMessage3"]);



                if(rand_msg == 1 && msg_1 != "") npc->Msg(msg_1);

                else if(rand_msg == 2 && msg_2 != "") npc->Msg(msg_2);

                else if(rand_msg == 3 && msg_3 != "") npc->Msg(msg_3);

            }

            else if(static_cast<std::string>(world->config["NpcTalkType"]) == "induvidual")

            {

                //

                // THIS PART OF THE SYSTEM STILL NEEDS TO BE CHANGED

                //


                if(npc->time_until_next_talk > 0) --npc->time_until_next_talk;

                else if(npc->time_until_next_talk == 0)

                {

                    int rand_msg = util::rand(1,3);

                    std::string msg_1 = static_cast<std::string>(world->config[util::to_string(npc->id)+".NpcMessage1"]);

                    std::string msg_2 = static_cast<std::string>(world->config[util::to_string(npc->id)+".NpcMessage2"]);

                    std::string msg_3 = static_cast<std::string>(world->config[util::to_string(npc->id)+".NpcMessage3"]);



                    if(rand_msg == 1 && msg_1.length() > 0) npc->Msg(msg_1), npc->said_timed_msg = true;

                    else if(rand_msg == 2 && msg_2.length() > 0) npc->Msg(msg_2), npc->said_timed_msg = true;

                    else if(rand_msg == 3 && msg_3.length() > 0) npc->Msg(msg_3), npc->said_timed_msg = true;

                    else

                    {

                        npc->time_until_next_talk = -1;

                        npc->said_timed_msg = false;

                    }


                    if(npc->said_timed_msg)

                    {

                        npc->time_until_next_talk += double(world->config["NpcTalkTime"]);



                        if(double(world->config["NpcTalkBreak"]) > 0)

                        {

                            int rand_break = util::rand(0,100);


                            if(rand_break <= double(world->config["NpcTalkBreakChance"]) && npc->spawn_type != 7)

                            {

                                npc->time_until_next_talk += double(world->config["NpcTalkBreak"]);

                            }

                        }

                        npc->said_timed_msg = false;

                    }

                }

            }

        }

    }

}


Put this in the World( function:

if(this->config["NpcTalk"])

    {

        if(static_cast<std::string>(this->config["NpcTalkType"]) == "whole")

        {

            event = new TimeEvent(world_npcs_talk, this, double(this->config["NpcTalkTime"]), Timer::FOREVER);

            this->timer.Register(event);

        }

        else

        {

            event = new TimeEvent(world_npcs_talk, this, 1.0, Timer::FOREVER);

            this->timer.Register(event);

        }

    }

NPC.HPP

bool said_timed_msg;

double time_until_next_talk;


NPC.CPP

this->time_until_next_talk = 0;

    this->said_timed_msg = false;


I'm in a rush and have to go, but If I missed anything post the errors and I will fill them in when I get back.



8 years, 27 weeks ago
Post #198500 Re: NPC speech code 8 years, 27 weeks ago
Post #198504 Re: NPC speech code

When this enters the official build it will likely be based on the original meaning both methods above are wrong. 

The official file format looks like this:

NPCID.chats = #chats

NPCID.rate = %chance (0-100)

NPCID.# = "string message"

It appears chats are tied to NPC:Act() and cannot occur sooner than 5 seconds of the last chat. There is also a strong belief that one of a spawn tile group can talk at once.

Anyway, you can completely drop the timer in world.cpp and plug this method into NPC:Act. You probably want to add a global chat rate variable as well so you can modify the frequency both individually and globally.

8 years, 27 weeks ago
Post #198508 Re: NPC speech code

I have mine configured so that it reads from a 'vocab.ini' file formatted like so:

#7: Goat

7.freq = 15s

7.speech = Beh, Behhhh, Behhhhhhhhhh, BEEEHHHHHHHH

Which I used for testing my client. I can post the code, but my source control VM got corrupted (thanks, power outages -.-) and I lost the change history so it will be difficult to find all the changes that I made. It was done in nearly the same way that drops are done.

---
class EOSERV {
Programmer | Oldbie
Open source EO Client: https://github.com/ethanmoffat/EndlessClient
};
8 years, 27 weeks ago
Post #198510 Re: NPC speech code

Not really sure using a comma to separate lines of dialog is such a good idea. It may be best to just get the end of line although that may also create differences if converted to support the server talk data format. Commas should be included in dialog.

8 years, 27 weeks ago
Page: << 1 >>

EOSERV Forum > EOSERV > NPC speech code