TheBiky88

talk.lua

Feb 25th, 2026 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. local unit05_messages = {
  2.   "Hello, tiny friend!",
  3.   "Greetings.",
  4.   "I wonder what happened to unit 6 & 7..",
  5.   "Oh. Uhh. Hi!",
  6.   "Are you taking good care of the friends I gave you?",
  7.   "Beep boop. I am bored.",
  8.   "Sorry, were you saying something?",
  9.  
  10.  
  11. }
  12.  
  13. script.on_nth_tick(3600, function()
  14.   for _, player in pairs(game.connected_players) do
  15.  
  16.     local entity = player.surface.find_entities_filtered{name="unit-05"}
  17.     for _, entity in pairs(entity) do
  18.       if player.position and entity.valid then
  19.         local dx = player.position.x - entity.position.x
  20.         local dy = player.position.y - entity.position.y
  21.         local dist = math.sqrt(dx*dx + dy*dy)
  22.         if dist < 10 then
  23.           trigger_message(player, entity)
  24.         end
  25.       end
  26.     end
  27.   end
  28. end)
  29.  
  30. function trigger_message(player, entity)
  31.     -- FIX: storage.rng.talk(N) instead of math.random(N).
  32.     -- The talk generator is created in init_debris() alongside the others.
  33.     local msg = unit05_messages[storage.rng.talk(#unit05_messages)]
  34.  
  35.     rendering.draw_text{
  36.         text = msg,
  37.         surface = entity.surface,
  38.         target = entity,
  39.         target_offset = {0, -2},
  40.         color = {r=1, g=1, b=0.8},
  41.         scale = 1.5,
  42.         time_to_live = 300,
  43.         players = {player}
  44.     }
  45. end
Advertisement
Add Comment
Please, Sign In to add comment