Advertisement
Guest User

Untitled

a guest
Oct 18th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. void world_speak_npcs(void *world_void)
  2. {
  3.     World *world = static_cast<World *>(world_void);
  4.  
  5.     UTIL_FOREACH(world->maps, map)
  6.     {
  7.         UTIL_FOREACH(map->npcs, npc)
  8.         {
  9.             double timeinterval = util::to_float(world->npcs_config[util::to_string(npc->id) + ".interval"]);
  10.             double current_time = Timer::GetTime();
  11.  
  12.             if (timeinterval > 0 && (current_time - npc->last_chat) >= timeinterval)
  13.             {
  14.                 std::vector<std::string> chats;
  15.  
  16.                 for (int i = 1; std::string(world->npcs_config[util::to_string(npc->id) + ".chat" + util::to_string(i)]) != "0"; i++)
  17.                     chats.push_back(world->npcs_config[util::to_string(npc->id) + ".chat" + util::to_string(i)]);
  18.  
  19.                 if (util::rand(0, 100) <= (util::to_int(world->npcs_config[util::to_string(npc->id) + ".frequency"])) && chats.size() > 0)
  20.                 {
  21.                     npc->ShowDialog(chats.at(util::rand(0, chats.size() - 1)));
  22.                     npc->last_chat = current_time;
  23.                 }
  24.                 else
  25.                 {
  26.                     npc->last_chat = current_time;
  27.                 }
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement