FAQ  •  Register  •  Login

Levelgens during maps?

<<

Platinutonium

Posts: 1

Joined: Sat Oct 13, 2012 8:39 am

Post Wed Jan 09, 2013 1:17 pm

Levelgens during maps?

I noticed there was no tutorial for the new feature, levelgens being active during maps. Could a tutorial be made? I had a great idea for a Rabbit level and want to make switches and gates.

Also, can levelgens be used to:

-Make switches that remove or add objects?

-Make objects appear or disappear after a set amount of time?

-Make hostile bots appear and start wreaking havoc?
<<

kaen

User avatar

Posts: 209

Joined: Thu Jun 14, 2012 11:54 am

Post Wed Jan 09, 2013 2:30 pm

Re: Levelgens during maps?

Platinutonium wrote:-Make switches that remove or add objects?


I'm new to all of this, but here's the quick and dirty. The new levelgen stuff works through the "levelgen:subscribe()" mechanism. This function takes a member the following enum as its argument:

  Code:
Event.ShipSpawned
Event.ShipKilled
Event.PlayerJoined
Event.PlayerLeft
Event.MsgReceived
Event.NexusOpened
Event.NexusClosed
Event.ShipEnteredZone
Event.ShipLeftZone


The argument describes what "event" you want to listen for. There are no switches in Bitfighter, so the solution is to use zones, and have your switching action in the ShipEnteredZone event. So here's an example


  Code:
function main()
  levelgen:subscribe(Event.ShipEnteredZone)
end

function onShipEnteredZone (ship, zone)
  logprint("Ship " .. ship:getId() .. " entered zone " .. zone:getId())
  -- do some stuff
end


The fist important part of this is the function main, where you put the code to be executed when the level is first loaded. Next, by calling   levelgen:subscribe(Event.ShipEnteredZone) you're telling Bitfighter that you want to do something when any ship enters any zone. Bitfighter then looks for a function with a specific name of the form "on<Event Name>". In this case, onShipEnteredZone. The name of the function is determined by the event, and must match perfectly. When Bitfighter sees that a ship has entered a zone, it will call your onShipEnteredZone function.

Now, notice that onShipEnteredZone takes two arguments (which Bitfighter passes to it when it's called). These arguments are different for each function, (see http://bitfighter.org/wiki/index.php/Pr ... ned_events [somewhat outdated]). In this case, the arguments are lua instances of the ship and zone involved in the event. This way you can test which zone or ship is involved in the event.

If you want to use it as a switch, you'll need a global variable (to keep track of whether your "switch" is on or off). Remember that global variables must be defined in the main function:

  Code:
function main()
  levelgen:subscribe(Event.ShipEnteredZone)
  -- set our global variable's starting value
  isOn = false
end

function onShipEnteredZone (ship, zone)
  if isOn then
      logprint("On")
  else
      logprint("Off")
  end
  -- this will set isOn to true if it is false, and to false if it is true
  isOn = not isOn
end
 


To add an item, use
  Code:
levelgen:addItem(ResourceItem.new(), 0, 0)

and replace ResourceItem with the name of the type of item you want to spawn

(I don't know about removing items, or spawning hostile bots)

To do something after a set amount of time:

  Code:
function main()
  Timer:scheduleOnce(doThisLater, 2000)
end

function doThisLater()
  levelgen:addItem(ResourceItem.new(), 0, 0)
end


scheduleOnce takes a function (or some other stuff, but it's complicated) and a delay as its argument. The function can be named pretty much anything you want, since you tell it which function to call. The delay is in milliseconds, so 2000 means 2 seconds.
bobdaduck wrote:Next, the moon!

└────────┘
⎈⎈⎈⎈
┌────────┐
<<

amgine

Posts: 1399

Joined: Thu Apr 19, 2012 2:57 pm

Post Fri Jan 11, 2013 1:50 pm

Re: Levelgens during maps?

how do you make a zone that would kill somone instantly if they touched it.
Bitfighter Forever.
<<

watusimoto

Site Admin

Posts: 1558

Joined: Tue Feb 23, 2010 7:07 pm

Location: Quartz's mom's house

Post Sat Jan 12, 2013 4:28 am

Re: Levelgens during maps?

Platinutonium wrote:I noticed there was no tutorial for the new feature, levelgens being active during maps.


You are right -- this is a new feature, and there is no tutorial for that reason. We are still actively developing this aspect of the game, and as such documentation is lagging behind. Waaay behind.

Much of the robot scripting docs in the wiki apply (events are the same in bots and levelgens, for example), though even that is now a bit dated. We also have a more up to date but waaaay less organized documentation project available here:

http://bitfighter.org/luadocs/index.html

This is documentation built automatically from the Bitfighter source, but formatting is still lacking and parts are highly disorganized. But the class model and methods available for different objects are largely up-to-date.

Finally, if you have specific ideas, come chat with us in IRC, and if what you want to do requires additional functionality to be added to Bitfighter, we would certainly consider doing so.

Return to General Map/Server

Who is online

Users browsing this forum: No registered users and 1 guest

cron