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