Advertisement
rafizzzz

Untitled

Feb 7th, 2021
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. function init_global( )
  2.     global["newForceModData"] = {}
  3. end
  4.  
  5.  
  6. function set_gloal(name,value)
  7.     if (global["newForceModData"] == nil) then
  8.         init_global()
  9.     end
  10.     global["newForceModData"][name] = value
  11. end
  12.  
  13. function get_global(name)
  14.     if (global["newForceModData"] == nil) then
  15.         init_global()
  16.     end
  17.     return global["newForceModData"][name]
  18. end
  19.  
  20. function befriendRadarForce(force)
  21.     local radar_force = get_global("radar_force")
  22.     if(radar_force == nil) then
  23.         radar_force = game.create_force("Radars Force")
  24.         set_gloal("radar_force",radar_force)
  25.         radar_force.share_chart = true
  26.     end
  27.  
  28.     radar_force.set_friend(force,true)
  29.     force.set_friend(radar_force,true)
  30. end
  31.  
  32. function createPlayerForce( player )
  33.     local player_forces = get_global("player forces")
  34.     if (player_forces == nil) then
  35.         player_forces = {}
  36.     end
  37.     local newForceName = player.name .. " force"
  38.     local newForce = game.create_force(newForceName)
  39.     player_forces[newForceName] = newForce
  40.     set_gloal("player forces",player_forces) --update global variable
  41.     return newForce
  42. end
  43.  
  44. function on_player_created(event)
  45.     local player = game.players[event.player_index]
  46.     local newForce = createPlayerForce(player)
  47.     game.print('1' .. player.force.name)
  48.     game.print('2' .. newForce.name)
  49.     player.force = newForce
  50.     game.print('3' .. player.force.name)
  51.     game.print('4' .. newForce.name)
  52.     newForce.share_chart = true
  53.     befriendRadarForce(newForce)
  54.     game.print('5' .. player.force.name)
  55.     game.print('6' .. newForce.name)
  56. end
  57.  
  58. function on_built_entity(event)
  59.     local entity = event.created_entity
  60.     if (entity.name == "radar") then
  61.         entity.surface.create_entity{name="radar", position=entity.position, force=get_global("radar_force")}
  62.         entity.destroy()
  63.     end
  64. end
  65.  
  66. script.on_event(defines.events.on_player_created, on_player_created)
  67.  
  68. script.on_event(defines.events.on_built_entity, on_built_entity)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement