Spaces:
caillef
/
No application file

Corentin Cailleaud commited on
Commit
f7f82c2
·
1 Parent(s): 4e101e0
Files changed (1) hide show
  1. cubzh.lua +20 -17
cubzh.lua CHANGED
@@ -721,23 +721,26 @@ Client.OnWorldObjectLoad = function(obj)
721
  if obj.Name == "pirate_ship" then
722
  obj.Scale = 1
723
  end
724
- if obj.Name == "NPC_scientist" then
725
- local pos = obj.Position:Copy()
726
- gigaxWorldConfig.locations[1].position = pos
727
- gigaxWorldConfig.NPCs[1].position = pos
728
- gigaxWorldConfig.NPCs[1].rotation = obj.Rotation:Copy()
729
- obj:RemoveFromParent()
730
- elseif obj.Name == "NPC_baker" then
731
- local pos = obj.Position:Copy()
732
- gigaxWorldConfig.locations[2].position = pos
733
- gigaxWorldConfig.NPCs[2].position = pos
734
- gigaxWorldConfig.NPCs[2].rotation = obj.Rotation:Copy()
735
- obj:RemoveFromParent()
736
- elseif obj.Name == "NPC_pirate" then
737
  local pos = obj.Position:Copy()
738
- gigaxWorldConfig.locations[3].position = pos
739
- gigaxWorldConfig.NPCs[3].position = pos
740
- gigaxWorldConfig.NPCs[3].rotation = obj.Rotation:Copy()
 
 
 
741
  obj:RemoveFromParent()
742
  end
743
  end
@@ -780,7 +783,7 @@ Client.OnStart = function()
780
  pathfinding:createPathfindingMap()
781
 
782
  gigax:setConfig(gigaxWorldConfig)
783
- print(math.random(20))
784
  local randomNames = { "aduermael", "soliton", "gdevillele", "caillef", "voxels", "petroglyph" }
785
  Player.Avatar:load({ usernameOrId = randomNames[math.random(#randomNames)] })
786
  end
 
721
  if obj.Name == "pirate_ship" then
722
  obj.Scale = 1
723
  end
724
+
725
+ local locationsIndexByName = {}
726
+ for k, v in ipairs(gigaxWorldConfig.locations) do
727
+ locationsIndexByName[v.name] = k
728
+ end
729
+ local npcIndexByName = {
730
+ NPC_scientist = 1,
731
+ NPC_baker = 2,
732
+ NPC_pirate = 3,
733
+ }
734
+
735
+ local index = npcIndexByName[obj.Name]
736
+ if index then
737
  local pos = obj.Position:Copy()
738
+ gigaxWorldConfig.NPCs[index].position = pos
739
+ gigaxWorldConfig.NPCs[index].rotation = obj.Rotation:Copy()
740
+
741
+ local locationName = gigaxWorldConfig.NPCs[index].currentLocationName
742
+ local locationIndex = locationsIndexByName[locationName]
743
+ gigaxWorldConfig.locations[locationIndex].position = pos
744
  obj:RemoveFromParent()
745
  end
746
  end
 
783
  pathfinding:createPathfindingMap()
784
 
785
  gigax:setConfig(gigaxWorldConfig)
786
+
787
  local randomNames = { "aduermael", "soliton", "gdevillele", "caillef", "voxels", "petroglyph" }
788
  Player.Avatar:load({ usernameOrId = randomNames[math.random(#randomNames)] })
789
  end