Jump to content

Random map changer


hippokittie
 Share

Recommended Posts

Hey so I have been messing around with the map changer that came with leadwerks (copied it and renamed it so I have the original still) to choose between random seed maps (initial starting areas the rest is generated) but when it tried to change maps it crashes or gives me a lua stack overflow issue. Is there something wrong with my code? Here it is.

--[[
This script will act as a trigger to change the current map.
Place this at the end of your map to make the player progress
to the next level.
]]--
Script.mapname={}
Script.mapname[0] = "" --string "Map Name"
Script.mapname[1] = "" --string "Map Name"
Script.mapname[2] = "" --string "Map Name"
Script.mapname[3] = "" --string "Map Name"
function Script:Start()
self.enabled=true
    math.randomseed(Time:Millisecs())
math.random();math.random();math.random();
    self.counter = 0
end
function Script:Collision(entity, position, normal, speed)
changemapname = math.random(0,3)
end
function Script:Enable()--in
if self.enabled==false then
 self.enabled=true
 self:CallOutputs("Enable")
end
end
function Script:Disable()--in
if self.enabled then
 self.enabled=false
 self:CallOutputs("Disable")
end
end

Will Hall

Morphodox Studios

Link to comment
Share on other sites

I haven't tried it but i think it is not possible to make attributes like this directly into a lua table.

 

you might need to make normal variables instead and add these later to your lua table.

 

(all code untested)

Script.mapfile0 = ""--path "Map File 0" "Map file:map"
Script.mapfile1 = ""--path "Map File 1" "Map file:map"
Script.mapfile2 = ""--path "Map File 2" "Map file:map"
Script.mapfile3 = ""--path "Map File 3" "Map file:map"

 

and then inside

Script:Start()

 

local maxMaps = 3
self.mapname = {}
for n=0,maxMaps do
if _G["mapfile"..tostring(n)] ~= "" then
mapname[n] = _G["mapfile"..tostring(n)]
end
end

 

EDIT: forget the last code since that only works for global variables.

But i guess you get what i mean.

Edited by beo6
Link to comment
Share on other sites

I haven't tried it but i think it is not possible to make attributes like this directly into a lua table.

 

you might need to make normal variables instead and add these later to your lua table.

 

(all code untested)

Script.mapfile0 = ""--path "Map File 0" "Map file:map"
Script.mapfile1 = ""--path "Map File 1" "Map file:map"
Script.mapfile2 = ""--path "Map File 2" "Map file:map"
Script.mapfile3 = ""--path "Map File 3" "Map file:map"

 

and then inside

Script:Start()

 

local maxMaps = 3
self.mapname = {}
for n=0,maxMaps do
if _G["mapfile"..tostring(n)] ~= "" then
mapname[n] = _G["mapfile"..tostring(n)]
end
end

 

EDIT: forget the last code since that only works for global variables.

But i guess you get what i mean.

 

so I would change the map selection back to the default? then call the table later? or would I set it as you have above and put the name of the map directly in the quotes? I have a similar code (what I took the random from) for random spawns. I adjusted it with the trigger touch to make this.

Will Hall

Morphodox Studios

Link to comment
Share on other sites

i don't know what you mean with

put the name of the map directly in the quotes?

 

but after you assigned the maps each into its own variable you can assign these into a table.

 

Here is a working script now.

--[[
This script will act as a trigger to change the current map.
Place this at the end of your map to make the player progress
to the next level.
]]--
Script.mapfile0 = ""--path "Map File 0" "Map file:map"
Script.mapfile1 = ""--path "Map File 1" "Map file:map"
Script.mapfile2 = ""--path "Map File 2" "Map file:map"
Script.mapfile3 = ""--path "Map File 3" "Map file:map"
function Script:Start()
self.mapname = {}
   math.randomseed(Time:Millisecs())
if self.mapfile0 ~= "" then
 self.mapname[1] = self.mapfile0
end
if self.mapfile1 ~= "" then
 self.mapname[2] = self.mapfile1
end
if self.mapfile2 ~= "" then
 self.mapname[3] = self.mapfile2
end
if self.mapfile3 ~= "" then
 self.mapname[4] = self.mapfile3
end
end
function Script:Collision(entity, position, normal, speed)
local changeMapNr = math.random(1,#self.mapname)
if changemapname == nil then

 --fix for changemap part in default App.lua
 local changeToMapFileFix = string.gsub(self.mapname[changeMapNr], ".map$","")
 changeToMapFileFix = string.gsub(changeToMapFileFix, "^.*/","")

 changemapname = changeToMapFileFix
end
end

 

However i would change the changemap part in the App.lua to accept not only a mapname but the path including the file extension.

Then you could remove the "fix for changemap part in default App.lua" part and still have the file selectors in the editor.

Link to comment
Share on other sites

Thank beo6 that's helpful. I am going to be adding in a bunch of seeds, so this will help a lot :D. I was told not to mess with the app.lua though, so would it be fine just to tweek this code a bit? I am going to be adding in a load screen image as well so it doesn't look frozen :P

Will Hall

Morphodox Studios

Link to comment
Share on other sites

You can tweak the code how you want.

 

Another small thing you should add is a check which entity type collides with it.

Currently everything that collides with the trigger will start the mapchange. But you will most likely only want to have the player change the map.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...