Author Topic: iPad Custom Level [HELP, Very Beginner]  (Read 15214 times)

0 Members and 1 Guest are viewing this topic.

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
iPad Custom Level [HELP, Very Beginner]
« on: May 01, 2012, 05:23:15 AM »
Since I don't have the PC version of this game, I only have the iPad version, and would love to start creating my custom levels, I would like to create a full 25 level story which replaces the original story, but suprise suprise, I don't know much about scripting.

There is hope though, from looking through the .lua file of say level 4, I have been playing around with the attributes and seedlings of the asteroids and i'd say I understand that, but from the level_4.lua file I'll upload some code I don't understand, and hopefully someone will be kind enough to help me.

Code: [Select]
function LevelSetup()
if IsiOS() then
SetSpeedSwitchAvailable(false)
end

Some of you may laugh, because this is the start of the scripting, but is this just the speed setting at the top left? and because it says false it means it's not visible/usabe?

Code: [Select]
Globals():Get("Asteroids"):Set("RadiusPowerRule",1.2)
Globals():Get("Asteroids"):Set("SizeFromEnergy",120)
Globals():Get("Asteroids"):Set("SizeFromStrength",120)
Globals():Get("Asteroids"):Set("SizeFromSpeed",120)
Globals():Get("Asteroids"):Set("CoreHealthPowerRule",2.5)
Globals():Get("Asteroids"):Set("SendPowerRule",2.5)

I just don't get these lines of codes, I know it's to do with the Asteroids, but i'm not understanding the PowerRule?

Code: [Select]
Globals():Get("Structures"):Set("LevelDuration1",25)
Globals():Get("Structures"):Set("LevelDuration2",60)
Globals():Get("Structures"):Set("LevelDuration3",120)
Globals():Get("Structures"):Set("LevelDuration4",180)
Globals():Get("Structures"):Set("SpawnTime1",27)
Globals():Get("Structures"):Set("SpawnTime2",22)
Globals():Get("Structures"):Set("SpawnTime3",17)
Globals():Get("Structures"):Set("SpawnTime4",17)

I can guess? But i'd rather be told the real thing.

Code: [Select]
Globals():Get("Game"):Set("MinAsteroidSeparation",1500)
Globals():Get("Game"):Set("MaxAsteroidNeighbourDist",3500)
Globals():Get("Game"):Set("GreysProbability",0.15)

Help. :/

Code: [Select]
AddAsteroidRing(4, 0, 0, 1700, 6500)
Is this something to do with position?

Code: [Select]
-- Asteroid 4
a = AddAsteroidWithAttribs(4000,-3500, 0.7,0.7,0.7)
a.Owner = 1
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
a:AddSeedlings(30)
a.Moveable = false

I'll tell you first what I understand from this...
Code: [Select]
-- Asteroid 4                                     =   Just a name? not that important?
a = AddAsteroidWithAttribs(4000,-3500, 0.7,0.7,0.7)      =   (X , Y, 0-1 energy, 0-1 strength, 0-1 speed)
a.Owner = 1                                   =  0 - Empty 1 - ME 2+ - other factions, depends on max factions I set with the globals():?
s = a:AddDysonTree()                              =  s = a:AddDysonTree() simply adds a dysontree (I know the other add codes aswell, such as defence trees and that)
s:LevelUp()                                         = Don't really understand this, does it automatically level up the dyson tree?
s:LevelUp()
s = a:AddDysonTree()
s:LevelUp()
s:LevelUp()
a:AddSeedlings(30)                               = Starts with 30 seedlings
a.Moveable = false                                = Don't know?

Code: [Select]
asteroidID = GetRandomRange( 6, 8 )

?

Code: [Select]
stage = 0

function LevelLogic()
StartLevelLogic()

GetEmpire(1):UpdateAsteroidLists()
GetEmpire(0):UpdateAsteroidLists()
GetEmpire(2):UpdateAsteroidLists()

No idea?

I don't really want to add text at the moment so is the following useful to me at the moment?

Code: [Select]
--
-- Mission text
--
if IsiOS() then
WaitReal(1)
Message("04_01", true, 1.0, "Top")
WaitMessage(true)
SetSpeedSwitchAvailable(true)
Message("04_GOAL", true, 1.0, "Left")
else
MessageBox("04_01")
WaitDialog()
end

--
-- Artifact intro
--
if IsiOS() then
WaitMessage(true)
WaitReal(2)

Message("04_ARTIFACT", true, 1.0, "Top")

if GetLevelHasTimeRecorded() then
SetHelpAvailableStoryMode("res/iOS_ArtifactIntroduce.png",512, "iOS_ArtifactIntroduce")
end

WaitMessage(true)
WaitReal(1)

if not GetLevelHasTimeRecorded() then
ImageBox("res/iOS_ArtifactIntroduce.png",512, "iOS_ArtifactIntroduce")
WaitDialog()
SetHelpAvailableStoryMode("res/iOS_ArtifactIntroduce.png",512, "iOS_ArtifactIntroduce")
end
else
ImageBox("res/Artifact1.png",256,"ArtifactIntroduce")
WaitDialog()
end

-- stay here until stage is not zero - this is set when a certain asteroid is REVEALED (see below)
while stage == 0 do
CheckConditions()
coroutine.yield()
end

WaitGame(3)

--
-- Another seedling empire???
--
if IsiOS() then
Message("04_02", true, 1.0, "Top")
else
MessageBox("04_02")
WaitDialog()
end

while GameRunning() do
CheckConditions()
coroutine.yield()
end
end


function CheckConditions()
if gameFinished then
return
end

if GetEmpire(1):GetNumOwnedAsteroids() >= 9 and GetEmpire(0).Defeated and GetEmpire(2).Defeated then
if IsiOS() then
GameOver(true, "")
Message("04_win", true, 1.0, "Centre")
WaitMessage(false)
MessageBox("HintGoal")
WaitDialog()
Quit(true)
else
GameOver(true, "04")
end
end

if GetEmpire(1).NumDysonTrees == 0 and GetEmpire(1).NumSeedlings == 0 then
GameOver(false, "04")
end
end


function OnAsteroidRevealed(id, owner)
if id == 9 and owner == 1 and stage == 0 then
GetAsteroid(9):SetGraceTime(5)
stage = 1
end
end


Again to whoever has taken their precious time to help me, thank you, it won't be underappreciated.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 27
  • Posts: 1,523
  • They'll eat you next!
  • Eufloria: Yes
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #1 on: May 01, 2012, 08:25:20 PM »
Oh wow, new functions :D

A lot of the codes are already covered by Annikk in the beginner guide, go check it out! :)
The other codes I guess you'll need to experiment with or wait for A||R to answer :)

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 21
  • Posts: 929
  • Eufloria: Yes
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #2 on: May 02, 2012, 01:16:44 AM »
The other codes I guess you'll need to experiment with or wait for A||R to answer :)

Bitwise, short-circuiting?

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #3 on: May 02, 2012, 01:21:12 AM »
Hey Aino, firstly thanks for replying :)

And most of the code is kind of the same but a bit different from looking at Annikk.exe's guide, I've emailed an Admin/Mod, can't remember who, they posted something about iPad level testing, i'll see what happens.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 27
  • Posts: 1,523
  • They'll eat you next!
  • Eufloria: Yes
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #4 on: May 02, 2012, 01:26:15 AM »
The other codes I guess you'll need to experiment with or wait for A||R to answer :)

Bitwise, short-circuiting?

You mean the ||? That's or in java :P

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 27
  • Posts: 1,523
  • They'll eat you next!
  • Eufloria: Yes
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #5 on: May 02, 2012, 01:37:12 AM »
It's time to break this thing down:

This is the most complicated one:
(click to show/hide)

GetEmpire(1):UpdateAsteroidLists() is Updating the Asteroid List (i.e how many asteroid the empire has, which asteroids, if the empire is defeated and other stuff).
SetSpeedSwitchAvailable(true) is probably allowing to change the speed in-game, like the developers mode +/-.
WaitReal(1) is, I think, to stop everything. 1 should be 1 millisecond, not a second.
Message("04_01", true, 1.0, "Top") is probably Message(Text, Clickable???, Size, Position(Text Based))(I'm not certain about this, do some experiementation! :D)
IsiOS() doesn't need any explanation.

The rest is very well known code.
I also bet this is how it will look after the update :)
« Last Edit: May 02, 2012, 01:46:44 AM by Aino »

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #6 on: May 03, 2012, 02:59:56 AM »
Well here we go, this is the basic level isn't it.

Code: [Select]
function LevelSetup()
SetBackdropColour(240/255,221/255,163/255)

Globals():Get("Asteroids"):Set("MaxTrees",1)
Globals():Get("Asteroids"):Set("MinRadius",90)
Globals():Get("Asteroids"):Set("MaxRadius",100)
Globals():Get("Asteroids"):Set("RadiusPowerRule",1.1)
Globals():Get("Asteroids"):Set("SizeFromEnergy",120)
Globals():Get("Asteroids"):Set("SizeFromStrength",120)
Globals():Get("Asteroids"):Set("SizeFromSpeed",120)
Globals():Get("Asteroids"):Set("MinCoreHealth",50)
Globals():Get("Asteroids"):Set("MaxCoreHealth",175)
Globals():Get("Asteroids"):Set("CoreHealthPowerRule",2)
Globals():Get("Asteroids"):Set("MinSendDistance",2400)
Globals():Get("Asteroids"):Set("MaxSendDistance",6000)
Globals():Get("Asteroids"):Set("SendPowerRule",3.2)

Globals():Get("Structures"):Set("LevelDuration1",15)
Globals():Get("Structures"):Set("LevelDuration2",30)
Globals():Get("Structures"):Set("LevelDuration3",60)
Globals():Get("Structures"):Set("LevelDuration4",100)
Globals():Get("Structures"):Set("SpawnTime1",15)
Globals():Get("Structures"):Set("SpawnTime2",12)
Globals():Get("Structures"):Set("SpawnTime3",10)
Globals():Get("Structures"):Set("SpawnTime4",8)

Globals():Get("Flowers"):Set("Available",0)

Globals():Get("StructuresDefense"):Set("TreeCost",10000)
Globals():Get("StructuresDefense"):Set("LevelDuration1",100000)

Globals():Get("Game"):Set("EnemyFactionsMin",0)
Globals():Get("Game"):Set("EnemyFactionsMax",0)
Globals():Get("Game"):Set("MinAsteroidSeparation",1500)
Globals():Get("Game"):Set("MaxAsteroidNeighbourDist",6000)
Globals():Get("Game"):Set("GreysProbability",0)

-- Asteroid 1
a = AddAsteroidWithAttribs(2200,6000, 0.2,1.0,0.3)
a.Owner = 1
a:AddSeedlings(10)
a.Moveable = false

SetDefenseTreeButtonAvailable(false)
SetFlowerDefenseButtonAvailable(false)
SetFlowerSeederButtonAvailable(false)
SetTerraformingButtonAvailable(false)
SetBeaconButtonAvailable(false)

if IsiOS() then
SetEnemyInfoAvailable(false)

SetSpeedSwitchAvailable(false)
SetSendModeScoutAvailable(false)
SetSendModeUnitsSelectorAvailable(false)
else
SetEnemyInfoAvailable(false)
SetCoreInfoAvailable(false)
end

SetCameraPositionToAsteroidID(0)
SetCameraZoomNow(50)
end

It doesn't complete yet, as in, theres no code to say if all enemies are defeated then I have completed the level, but I don't want that in yet. I want to play around with a few things, but I do have a question.

I had a look at the lua reference and I can't find help on the Zoom function, The...

Code: [Select]
SetCameraPositionToAsteroidID(0)
SetCameraZoomNow(50)

Is fine, Later i'd like to add some text (need to find where thats stored on iPad first). Back on to the zoom thing, I don't want the user to be able to zoom out from (50) yet? How would I go about doing that?

The help is appreciated?
   
EDIT:: Found were the text is stored, it's a land.csv file that is easily opened with excel.
« Last Edit: May 03, 2012, 03:21:58 AM by Tomfloria »

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 27
  • Posts: 1,523
  • They'll eat you next!
  • Eufloria: Yes
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #7 on: May 03, 2012, 03:58:16 AM »
Is fine, Later i'd like to add some text (need to find where thats stored on iPad first). Back on to the zoom thing, I don't want the user to be able to zoom out from (50) yet? How would I go about doing that?

To do this:

Code: [Select]
if (GetCameraZoom() > 50) then
SetCameraZoomNow(50)
end

BTW, those () brackets in the if condition isn't needed in Lua. It's just a java habit :P

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #8 on: May 03, 2012, 04:15:21 AM »
Thank you Aino! Trying to get some text working now, hopefully get the first level done tonight, If I need any help i'll reply here or message you, since you're the helper.

Thank you! :)

EDIT::

You're code

Code: [Select]
if (GetCameraZoom() > 50) then
SetCameraZoomNow(50)
end

Seems to crash my level, is it supposed to look like this?

EDIT::

Also remember this is for the iPad, so it might need to be wrote differently?

Code: [Select]
SetCameraPositionToAsteroidID(0)
SetCameraZoomNow(10)
if (GetCameraZoom() > 50) then
SetCameraZoomNow(50)
end
« Last Edit: May 03, 2012, 05:30:05 AM by Tomfloria »

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 27
  • Posts: 1,523
  • They'll eat you next!
  • Eufloria: Yes
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #9 on: May 03, 2012, 05:42:00 AM »
Geee, how can I forget:
It's supposed to be in a while loop in levellogic, or the logic function that exists.

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #10 on: May 03, 2012, 06:08:01 AM »
So...

Code: [Select]
SetCameraPositionToAsteroidID(0)
SetCameraZoomNow(50)
end

function LevelLogic()
StartLevelLogic()

if (GetCameraZoom() > 50) then
SetCameraZoomNow(50)
end


Just a question.... That code you gave me, does it restrict zooming capabilities until I want the user to be able to use it?
« Last Edit: May 03, 2012, 06:14:22 AM by Tomfloria »

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 4
  • -Receive: 21
  • Posts: 929
  • Eufloria: Yes
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #11 on: May 03, 2012, 06:25:29 AM »
No, it doesn't. You'll need to add that in yourself. Try something like

Code: [Select]
if GetCameraZoom() > 50 and zoomRestricted then
    SetCameraZoomNow(50)
end

Of course, you will have to set zoomRestricted to TRUE at the start of the level and then FALSE when you want it unlocked.

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #12 on: May 03, 2012, 06:36:55 AM »
Where would I add zoomRestricted? or even, what would the code look like?

Also how do I change the text colour from black to white?
« Last Edit: May 03, 2012, 07:20:51 AM by Tomfloria »

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 4
  • -Receive: 27
  • Posts: 1,523
  • They'll eat you next!
  • Eufloria: Yes
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #13 on: May 03, 2012, 02:51:48 PM »
Your code should look something like this for the zoom capper:

Code: [Select]
SetCameraPositionToAsteroidID(0)
SetCameraZoomNow(50)
end

function LevelLogic()
StartLevelLogic()

zoomRestricted  = true
while GameRunning() do
if GetCameraZoom() > 50 and zoomRestricted then
SetCameraZoomNow(50)
end

coroutine.yield() --if you need this one....
end
end

Tomfloria

  • Shrub
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 232
  • First iOS modder :D
Re: iPad Custom Level [HELP, Very Beginner]
« Reply #14 on: May 03, 2012, 11:53:39 PM »
The code you give me crashes the level :/