FAQ  •  Register  •  Login

How do I run this

<<

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Sun Mar 09, 2014 6:45 pm

How do I run this

I dont understand BF terminology, since I am not actually a coder. I did teach myself how to make Random Maps in Age of Empires II, but that's a diff game. the following reads easily to me

  Code:
start_random
  percent_chance    25
  #define       WINTER
  percent_chance    25
  #define       SPRING
  percent_chance    25
  #define       SUMMER
  percent_chance    25
  #define       AUTUMN
end_random

if WINTER
base_terrain        ICE
elseif SPRING
base_terrain        ICE
elseif SUMMER      
base_terrain        WATER
else
base_terrain        WATER
endif
 



So THAT I understand. I don't understand LUA. All I want to do is basically, in a way I understand using the above example (Totally imaginary_

  Code:

start_random
  percent_chance 50
  #define REPAIR
  percent_chance 50
  #define ENERGY
end_random

if REPAIR
create_object RepairItem 0 0 10
elseif ENERGY
create_object EnergyItem 0 0 10
else
create_object RepairItem 0 0 10
create_object EnergyItem 0 0 10
endif
 

I just want to create a repairitem or energyitem at such and such coordinate with a regen time of 10 (or 20.. or 30)
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

kaen

User avatar

Posts: 209

Joined: Thu Jun 14, 2012 11:54 am

Post Sun Mar 09, 2014 7:09 pm

Re: How do I run this

  Code:

if math.random() > .5 then
  bf:addItem(RepairItem.new(point.new(0, 0)))
else
  bf:addItem(EnergyItem.new(point.new(0, 0)))
end
 


math.random() gives you a random number between 0 and 1.0, so there's a fifty percent chance of each.
bobdaduck wrote:Next, the moon!

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

tazinator

Posts: 352

Joined: Fri Jul 05, 2013 7:35 pm

Post Sun Mar 09, 2014 7:52 pm

Re: How do I run this

  Code:

if math.random() > .5 then
  bf:addItem(RepairItem.new(point.new(0, -1020)))
  bf:addItem(RepairItem.new(point.new(0, 1020)))
  bf:addItem(RepairItem.new(point.new(1020, 0)))
  bf:addItem(RepairItem.new(point.new(-1020, 0)))
else
  bf:addItem(EnergyItem.new(point.new(0, -1020)))
  bf:addItem(EnergyItem.new(point.new(0, 1020)))
  bf:addItem(EnergyItem.new(point.new(1020, 0)))
  bf:addItem(EnergyItem.new(point.new(-1020, 0)))
end
 


--RepairItem 0 -1020 45
--RepairItem 0 1020 45
--RepairItem 1020 0 45
--RepairItem -1020 0 45
--local item = RepairItem.new()



note sure how to use the following code you have givin me. I would like to implement it, read more to see why.
  Code:
--[[
local item = RepairItem.new()item:setRegenTime(0)bf:addItem(item)
]]
--
 


I want to try something more advanced

I want to make the script run everytime a repair or energy item is grabbed. after I grab the energyitem, a repairitem spawns after 30 seconds. or maybe even a burst. That's the fun of it.
Play my new level! Two different teams fight over a nexus: One mainly defends while the other attacks! is fun
viewtopic.php?f=33&p=21002#p21002
<<

watusimoto

Site Admin

Posts: 1558

Joined: Tue Feb 23, 2010 7:07 pm

Location: Quartz's mom's house

Post Tue Mar 11, 2014 3:09 am

Re: How do I run this

First step is to put your code in a function, then get it to run once when the level is created. That will confirm that it basically works.

it should look something like this:

function yourfunction()
yourcodehere
end

function main()
yourfunction()
end

Once that works, the next step is to create a timer to call yourfunction(). Start the timer in main(). Look at the docs and see if you can figure it out (http://bitfighter.org/luadocs/class_timer.html).

The final step will be to have a trigger launch the timer. I'm not sure how to do that off the top of my head, but come back when you have the above working.

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 2 guests