Jump to content

Genebris

Members
  • Posts

    517
  • Joined

  • Last visited

Posts posted by Genebris

  1. I don't think that's possbile, but if you want you can create a pivot point with a script, save as prefab and parent it to entities you want to add script to. Obviously you will need to use self.entity:GetParent() in this script instead of self.entity.

  2. Not sure if this can help you, but I have made basic dungeon generation shown on this video:

    I have five models (painted in different colors in video) and specified each enter and exit spot with pivot point.

    Here is code:

     

     

    
    

    Script.startPivot="" --entity

    Script.dungeon={}

    Script.names={"d1", "d2l", "d2r", "d3l", "d3r"} --Names of all possible dungeon segments to check AABB intersection

    Script.d1="Prefabs/Dungeon/d1.pfb"

    Script.d2l="Prefabs/Dungeon/d2l.pfb"

    Script.d2r="Prefabs/Dungeon/d2r.pfb"

    Script.d3l="Prefabs/Dungeon/d3l.pfb"

    Script.d3r="Prefabs/Dungeon/d3r.pfb"

    Script.currentR=0

    Script.nextR=0

    Script.j=0

    Script.i=0

    Script.s=0

    Script.allDungeonSegments={}

     

    --Debug

    function Script:Start()

    --math.randomseed(10)

    end

     

    function Script:UpdateWorld()

    if App.window:KeyHit(Key.G) then self:Use() end

    end

     

    function Script:Use()

    self:GenerateDungeon()

    end

     

     

     

    function Script:GenerateDungeon() --main generation function

    self.currentR=0

    self.nextR=0

    self.i=0

    self.j=0

    player:ConsoleLog("Generation started. Countentities = "..App.world:CountEntities())

    self:DeleteAllDungeonSegments()

    player:ConsoleLog("All segments deleted. Countentities = "..App.world:CountEntities())

    self.dungeon={}

     

    self.dungeon[0]=self:CreateSegment(self:GetRandomPart()) --Create first dungeon element

    self.dungeon[0]:SetRotation(0,self.currentR,0,true)

    local pos = self.dungeon[0]:FindChild("Enter"):GetPosition(true)

    local previousPos = self.startPivot:GetPosition(true)

    local dPos = pos-previousPos

    self.dungeon[0]:SetPosition(pos-dPos, true)

     

    local result = true --Create main path

    self.dungeon, result=self:GeneratePath(100, self.dungeon) --If this function failed to generate dungeon we still need to save it, but we sholdn't proceed further

    if not result then

    self:GenerateDungeon() --Failed to generate dungeon, starting again

    return

    end

     

    --Generate forks

    self:GenerateForks()

    end

     

    function Script:GeneratePath(amount, startingTable, emergencyLimit)

    if not emergencyLimit then emergencyLimit=200 end

    local dungeon={}

    dungeon=startingTable

    local emergencyCounter=0

    local i=#dungeon+1

    self.intersectionFound=false

    while i<=amount do

    emergencyCounter=emergencyCounter+1

    --System:Print(emergencyCounter.." i="..i)

    if emergencyCounter>emergencyLimit then --reached limit of retries, generate again

    return dungeon, false --still need to return current dungeon to be able to clear it

    end

    dungeon=self:CreateSegment(self:GetRandomPart())

    local yRotation=dungeon[i-1]:GetRotation(true).y+self:GetExtraRotation(dungeon[i-1])

    dungeon:SetRotation(0,yRotation,0,true)

    pos = dungeon:FindChild("Enter"):GetPosition(true)

    previousPos = dungeon[i-1]:FindChild("Exit"):GetPosition(true)

    dPos = pos-previousPos

    dungeon:SetPosition(dungeon:GetPosition(true)-dPos, true)

     

    --Check AABB

    local aabb=dungeon:GetAABB(Entity.GlobalAABB)

    local j=1

    local maximum=#self.allDungeonSegments

    while j<=maximum do

    --System:Print(j)

    if self.allDungeonSegments[j]~=dungeon and self.allDungeonSegments[j]~=dungeon[i-1] and self.allDungeonSegments[j]~=dungeon[i-2] then

    if aabb:IntersectsAABB(self.allDungeonSegments[j]:GetAABB(Entity.GlobalAABB)) then

    System:Print(dungeon:GetKeyValue("name").." intersects with "..self.allDungeonSegments[j]:GetKeyValue("name"))

    if i<4 then

    return dungeon, false

    else

    System:Print("Three steps back")

    self:DeleteSegment(dungeon)

    System:Print("Deleted last segment")

    dungeon=nil

    self:DeleteSegment(dungeon[i-1])

    System:Print("Deleted i-1")

    dungeon=nil

    self:DeleteSegment(dungeon[i-2])

    System:Print("Deleted i-2")

    dungeon=nil

    i=i-3

    j=1000--maximum+1

    end

    end

    end

    j=j+1

    end

    i=i+1

    --System:Print("End of I loop. i="..i)

    end

    return dungeon, true --returning true if managed to generate dungeon properly

    end

     

    function Script:GenerateForks()

    local i=1

    while i <= #self.dungeon do

    if self.dungeon:GetKeyValue("name")=="d1" and math.random(0, 20)==0 then

    local matrix=self.dungeon:GetMatrix(true)

    self:DeleteSegment(self.dungeon)

    self.dungeon={}

    self.dungeon[0]=self:CreateSegment(self:GetRandomPart(4,5))

    self.dungeon[0]:SetMatrix(matrix, true)

    self.dungeon[1]=self:CreateSegment(self:GetRandomPart())

     

    local yRotation=self.dungeon[0]:GetRotation(true).y+self:GetExtraRotation(self.dungeon[0]) --second element

    self.dungeon[1]:SetRotation(0,yRotation,0,true)

    pos = self.dungeon[1]:FindChild("Enter"):GetPosition(true)

    previousPos = self.dungeon[0]:FindChild("Exit2"):GetPosition(true)

    dPos = pos-previousPos

    self.dungeon[1]:SetPosition(self.dungeon[1]:GetPosition(true)-dPos, true)

     

    --local dungeon

    --local result

    local dungeon, result = self:GeneratePath(15, self.dungeon, 30)

    if not result then

    self:DeleteSegment(dungeon[#dungeon])

    self.dungeon=dungeon

    else

    self.dungeon=dungeon

    end

    end

    i=i+1

    end

    end

     

    --other function

    function Script:GetRandomPart(minimum, maximum) --Choose random element

    if not minimum then minimum=0; maximum=3 end

    local r=math.random(minimum, maximum)

    if r==1 or r==0 then

    return self.d1

    elseif r==2 then

    return self.d2r

    elseif r==3 then

    return self.d2l

    elseif r==4 then

    return self.d3r

    elseif r==5 then

    return self.d3l

    end

    end

     

    function Script:GetExtraRotation(name)

    name=name:GetKeyValue("name")

    if name=="d2r" or name=="d3r" then

    return (90)

    elseif name=="d2l" or name=="d3l" then

    return (-90)

    end

    return 0 --all other segments return 0

    end

     

    function Script:CreateSegment(name)

    local entity=Prefab:Load(name)

    table.insert (self.allDungeonSegments, entity)

    return entity

    end

     

    function Script:DeleteSegment(entity)

    local i=1

    local maximum=#self.allDungeonSegments

    while i<=maximum do

    if self.allDungeonSegments==entity then

    local temp = self.allDungeonSegments

    table.remove (self.allDungeonSegments, i)

    --self.allDungeonSegments=0

    temp:Release()

    i=maximum

    end

    i=i+1

    end

    end

     

    function Script:DeleteAllDungeonSegments()

    for i=1, #self.allDungeonSegments do

    self.allDungeonSegments:Release()

    end

    self.allDungeonSegments={}

    end

     

    function Script:IsDungeonSegment(name) --not needed

    name=name:GetKeyValue("name")

    for i=1, #self.names do

    if self.names==name then return true end

    end

    return false

    end

     

     

    • Upvote 6
  3. Something weird is happening. I have two objects with the scame script on them. Here is the code:

    
    

    Script.enabled=0 --bool "enabled"

    Script.int=0

    Script.tab={1}

     

    function Script:UpdateWorld()

    System:Print("------------starts "..self.entity:GetKeyValue("name"))

    System:Print("int="..self.int)

    System:Print("#="..#self.tab)

    System:Print("[#]="..self.tab[#self.tab])

    if not self.enabled then return end

    self.int=self.int+1

    self.tab[#self.tab+1]=math.random(1,9)

    System:Print("-----------END "..self.entity:GetKeyValue("name"))

    end

    It has boolean variable which is set to true for one entity and to false for another entity in the editor.

    it also has one number variable (int) and one table (tab). Script with "enabled" entity ads +1 to int variable and one extra table element with random value each update.

    And here is what I get in output:

     

    ------------starts Pivot 1 (enabled)

    int=0

    #=1

    [#]=1

    -----------END Pivot 1 (enabled)

    ------------starts Pivot 2 (disabled)

    int=0

    #=2

    [#]=4

     

    ------------starts Pivot 1 (enabled)

    int=1

    #=2

    [#]=4

    -----------END Pivot 1 (enabled)

    ------------starts Pivot 2 (disabled)

    int=0

    #=3

    [#]=8

     

    ------------starts Pivot 1 (enabled)

    int=2

    #=3

    [#]=8

    -----------END Pivot 1 (enabled)

    ------------starts Pivot 2 (disabled)

    int=0

    #=4

    [#]=7

     

    ------------starts Pivot 1 (enabled)

    int=3

    #=4

    [#]=7

    -----------END Pivot 1 (enabled)

    ------------starts Pivot 2 (disabled)

    int=0

    #=5

    [#]=9

    ...

     

    (Added space after each update for easier reading)

    As you can see int variable increases in "enabled" entity and doesn't change in "disabled". Also disabled entity doesn't print last ("---END") line, so it is really disabled.

    But for some reason the table changes for both of those entities. It has same amount of elements and the last element is the same (it was generated randomly) for both scripts.

     

    Can you please explain me what is going on here?

  4. -Can you make randomly generated Worlds?

    -How big can the Worlds be? / Can I put 2 or more World Maps (4096x4096) together to get an bigger Map?

    You can make randomly generated levels, but you can't involve terrain into this as there are currently no methods to edit terrain at runtime (correct me if i'm wrong please). But you can also create a terrain in the editor and dynamically put objects onto it at runtime.

    The world size isn't limited, but terrain size is limited by 4000x4000 and you can't have more than 1 terrain.

    I wouldn't try making huge open worlds like Skyrim on Leadwerks. At least not with Lua only.

     

    -Are there any other Programs I must think of to buy when I use the Engine, for example to model something or make textures?

    For modelling you can use Blender which is free and has everything you could ever need. But you will need image editor such as Photoshop to work with textures.

    For exporting from blender use blender exporter. It's more convenient than exporting FBX.

  5. At this point I am not seeing any killer feature in Steam networking that would want me to tie networking to Steam. We'll probably set up our own server for matchmaking, as well as provide the tools to create your own, if you wish.

    Does this mean you can make a multiplayer game entierly on Steamworks and it will work without even enabling Steam client (and ofc without getting game greenlit)? Doesn't steam need to recognise your game at least as Spacewar?

  6. Yes, that's not realistic, but I'm making a a monster that has a black smoke instead of head and when he runs he leaves a long trail of particles behind instead of having thick smoke in place of head.

    I'll make simple particles system myself and upload to workshop if it works.

  7. Everything you named is not hard to do. The only problem I see is different footsteps while walking on terrain: you won't be able to check the texture you are standing on. But if you use different objects with different materials instead of terrain (and I think you don't really need terrain because player will be sneaking inside buildings and not in the forest at least most of the time), then there should be no problem to change footsteps.

  8. Easiest way:

    Place your key on a table mark it as hidden in it's properties (Appearance tab). Add this script to your lever:

    
    

    Script.key=nil --entity "Key"

    function Script:Use()

    self.key:Show()

    end

    And drag the key from scene tree window to a script variable field called "Key".

  9. Never had a problem with upadtes that forced me to redesign everything from scratch. And I'm sure noone else had. Because it's simply not possible. I have once got FPSPlayer script restored to default because of update, so I simply took backup file from script directory and made another player script that won't be updated. Few times App.lua was updated, I always was able to simply take backup file from it's dirrectory.

×
×
  • Create New...