simplify script
Browse files
cubzh.lua
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
Modules = {
|
2 |
gigax = "github.com/GigaxGames/integrations/cubzh:cdfd9a2",
|
3 |
pathfinding = "github.com/caillef/cubzh-library/pathfinding:f8c4315",
|
|
|
4 |
}
|
5 |
|
6 |
Config = {
|
@@ -302,40 +303,7 @@ findLocationByName = function(targetName, config)
|
|
302 |
end
|
303 |
end
|
304 |
|
305 |
-
function generateWorld()
|
306 |
-
local nbIslands = 20
|
307 |
-
local minSize = 4
|
308 |
-
local maxSize = 7
|
309 |
-
local dist = 750
|
310 |
-
local safearea = 200
|
311 |
-
floating_islands_generator:onReady(function()
|
312 |
-
for i = 1, nbIslands do
|
313 |
-
local island = floating_islands_generator:create(math.random(minSize, maxSize))
|
314 |
-
island:SetParent(World)
|
315 |
-
island.Scale = Map.Scale
|
316 |
-
island.Physics = PhysicsMode.Disabled
|
317 |
-
local x = math.random(-dist, dist)
|
318 |
-
local z = math.random(-dist, dist)
|
319 |
-
while (x >= -safearea and x <= safearea) and (z >= -safearea and z <= safearea) do
|
320 |
-
x = math.random(-dist, dist)
|
321 |
-
z = math.random(-dist, dist)
|
322 |
-
end
|
323 |
-
island.Position = {
|
324 |
-
x + (Map.Width * 0.5) * Map.Scale.X,
|
325 |
-
math.random(300) - 150,
|
326 |
-
z + (Map.Depth * 0.5) * Map.Scale.Z,
|
327 |
-
}
|
328 |
-
local t = x + z
|
329 |
-
LocalEvent:Listen(LocalEvent.Name.Tick, function(dt)
|
330 |
-
t = t + dt
|
331 |
-
island.Position.Y = island.Position.Y + math.sin(t) * 0.02
|
332 |
-
end)
|
333 |
-
end
|
334 |
-
end)
|
335 |
-
end
|
336 |
-
|
337 |
Client.OnWorldObjectLoad = function(obj)
|
338 |
-
print("OBJECT DID LOAD:", obj.Name)
|
339 |
if obj.Name == "pirate_ship" then
|
340 |
obj.Scale = 1
|
341 |
end
|
@@ -375,7 +343,14 @@ Client.OnStart = function()
|
|
375 |
})
|
376 |
|
377 |
gigaxWorldConfig.locations[4].position = Number3(Map.Width * 0.5, Map.Height - 2, Map.Depth * 0.5) * Map.Scale
|
378 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
379 |
|
380 |
local ambience = require("ambience")
|
381 |
ambience:set(ambience.dusk)
|
@@ -396,6 +371,10 @@ Client.OnStart = function()
|
|
396 |
|
397 |
pathfinding:createPathfindingMap()
|
398 |
|
|
|
|
|
|
|
|
|
399 |
gigax:setConfig(gigaxWorldConfig)
|
400 |
end
|
401 |
|
@@ -435,86 +414,3 @@ Client.OnChat = function(payload)
|
|
435 |
content = msg,
|
436 |
})
|
437 |
end
|
438 |
-
|
439 |
-
-- Module floating islands
|
440 |
-
|
441 |
-
floating_islands_generator = {}
|
442 |
-
|
443 |
-
local cachedTree
|
444 |
-
|
445 |
-
local COLORS = {
|
446 |
-
GRASS = Color(19, 133, 16),
|
447 |
-
DIRT = Color(107, 84, 40),
|
448 |
-
STONE = Color.Grey,
|
449 |
-
}
|
450 |
-
|
451 |
-
local function islandHeight(x, z, radius)
|
452 |
-
local distance = math.sqrt(x * x + z * z)
|
453 |
-
local normalizedDistance = distance / radius
|
454 |
-
local maxy = -((1 + radius) * 2 - (normalizedDistance ^ 4) * distance)
|
455 |
-
return maxy
|
456 |
-
end
|
457 |
-
|
458 |
-
floating_islands_generator.onReady = function(_, callback)
|
459 |
-
Object:Load("knosvoxel.oak_tree", function(obj)
|
460 |
-
cachedTree = obj
|
461 |
-
callback()
|
462 |
-
end)
|
463 |
-
end
|
464 |
-
|
465 |
-
floating_islands_generator.create = function(_, radius)
|
466 |
-
local shape = MutableShape()
|
467 |
-
shape.Pivot = { 0.5, 0.5, 0.5 }
|
468 |
-
for z = -radius, radius do
|
469 |
-
for x = -radius, radius do
|
470 |
-
local maxy = islandHeight(x, z, radius)
|
471 |
-
shape:AddBlock(COLORS.DIRT, x, -2, z)
|
472 |
-
shape:AddBlock(COLORS.GRASS, x, -1, z)
|
473 |
-
shape:AddBlock(COLORS.GRASS, x, 0, z)
|
474 |
-
if maxy <= -3 then
|
475 |
-
shape:AddBlock(COLORS.DIRT, x, -3, z)
|
476 |
-
end
|
477 |
-
for y = maxy, -3 do
|
478 |
-
shape:AddBlock(COLORS.STONE, x, y, z)
|
479 |
-
end
|
480 |
-
end
|
481 |
-
end
|
482 |
-
|
483 |
-
xShift = math.random(-radius, radius)
|
484 |
-
zShift = math.random(-radius, radius)
|
485 |
-
for z = -radius, radius do
|
486 |
-
for x = -radius, radius do
|
487 |
-
local maxy = islandHeight(x, z, radius) - 2
|
488 |
-
shape:AddBlock(COLORS.DIRT, x + xShift, -2 + 2, z + zShift)
|
489 |
-
shape:AddBlock(COLORS.GRASS, x + xShift, -1 + 2, z + zShift)
|
490 |
-
shape:AddBlock(COLORS.GRASS, x + xShift, 0 + 2, z + zShift)
|
491 |
-
if maxy <= -3 + 2 then
|
492 |
-
shape:AddBlock(COLORS.DIRT, x + xShift, -3 + 2, z + zShift)
|
493 |
-
end
|
494 |
-
for y = maxy, -3 + 2 do
|
495 |
-
shape:AddBlock(COLORS.STONE, x + xShift, y, z + zShift)
|
496 |
-
end
|
497 |
-
end
|
498 |
-
end
|
499 |
-
|
500 |
-
for i = 1, math.random(1, 2) do
|
501 |
-
local obj = Shape(cachedTree, { includeChildren = true })
|
502 |
-
obj.Position = { 0, 0, 0 }
|
503 |
-
local box = Box()
|
504 |
-
box:Fit(obj, true)
|
505 |
-
obj.Pivot = Number3(obj.Width / 2, box.Min.Y + obj.Pivot.Y + 4, obj.Depth / 2)
|
506 |
-
obj:SetParent(shape)
|
507 |
-
require("hierarchyactions"):applyToDescendants(obj, { includeRoot = true }, function(o)
|
508 |
-
o.Physics = PhysicsMode.Disabled
|
509 |
-
end)
|
510 |
-
local coords = Number3(math.random(-radius + 1, radius - 1), 0, math.random(-radius + 1, radius - 1))
|
511 |
-
while shape:GetBlock(coords) do
|
512 |
-
coords.Y = coords.Y + 1
|
513 |
-
end
|
514 |
-
obj.Scale = math.random(70, 150) / 1000
|
515 |
-
obj.Rotation.Y = math.random(1, 4) * math.pi * 0.25
|
516 |
-
obj.LocalPosition = coords
|
517 |
-
end
|
518 |
-
|
519 |
-
return shape
|
520 |
-
end
|
|
|
1 |
Modules = {
|
2 |
gigax = "github.com/GigaxGames/integrations/cubzh:cdfd9a2",
|
3 |
pathfinding = "github.com/caillef/cubzh-library/pathfinding:f8c4315",
|
4 |
+
floating_island_generator = "github.com/caillef/cubzh-library/floating_island_generator:82d22a5",
|
5 |
}
|
6 |
|
7 |
Config = {
|
|
|
303 |
end
|
304 |
end
|
305 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
306 |
Client.OnWorldObjectLoad = function(obj)
|
|
|
307 |
if obj.Name == "pirate_ship" then
|
308 |
obj.Scale = 1
|
309 |
end
|
|
|
343 |
})
|
344 |
|
345 |
gigaxWorldConfig.locations[4].position = Number3(Map.Width * 0.5, Map.Height - 2, Map.Depth * 0.5) * Map.Scale
|
346 |
+
|
347 |
+
floating_island_generator:generateIslands({
|
348 |
+
nbIslands = 20,
|
349 |
+
minSize = 4,
|
350 |
+
maxSize = 7,
|
351 |
+
safearea = 200, -- min dist of islands from 0,0,0
|
352 |
+
dist = 750, -- max dist of islands
|
353 |
+
})
|
354 |
|
355 |
local ambience = require("ambience")
|
356 |
ambience:set(ambience.dusk)
|
|
|
371 |
|
372 |
pathfinding:createPathfindingMap()
|
373 |
|
374 |
+
-- gigax:setConfig(gigaxWorldConfig)
|
375 |
+
end
|
376 |
+
|
377 |
+
Client.OnPlayerJoin = function()
|
378 |
gigax:setConfig(gigaxWorldConfig)
|
379 |
end
|
380 |
|
|
|
414 |
content = msg,
|
415 |
})
|
416 |
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|