Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: chief1983 on February 19, 2008, 09:48:47 pm

Title: This old menu script
Post by: chief1983 on February 19, 2008, 09:48:47 pm
Ok, I'm pretty sure I got all the function calls updated, but I'm not very good with Lua and might be trying to access something incorrectly, I don't know, but the script doesn't seem to be doing anything at all.  So I don't know if there's something else fundamental about the script that needs to change, or what.  If someone could just peek, and see if there's anything that stands out that would be good.

Code: [Select]
#State Hooks
$State: GS_STATE_MAIN_MENU
$Hook: [

   if init == nil then

   randomChoice = {"BTL-A4 Y-Wing","T-65c X-Wing","T.I.E. Fighter","TIE/In Interceptor"} --Put your ship classes in quotes here


-- getShipClass seems to be replaced with ShipClass[]
   numChoices = table.getn(randomChoice)
--   randomShip = tb.getShipClass(randomChoice[math.random(1,numChoices)])
   randomShip = tb.ShipClasses[randomChoice[math.random(1,numChoices)]]
   shipName = randomShip.Name
   init = 42
   end

   logo = "fotg"   --This is the name of the logo you want. No extension needed

   imgWidth = gr.getImageWidth(logo)
   imgHeight = gr.getImageHeight(logo)
   screenWidth = gr.getScreenWidth()
   screenHeight = gr.getScreenHeight()
   renderX1 = screenWidth * 0.01
   renderX2 = screenWidth * 0.8
   renderY1 = screenHeight * 0.1
   renderY2 = screenHeight * 0.9
   rendermidX = (renderX1+renderX2)/2
   imageX = (screenWidth*0.5)-imgWidth/2
   imageY = 0



   rotConst = 7 --Modify this to make it turn faster to slower

   if rotate_pct then
      rotate_pct = rotate_pct +  rotConst*ba.getFrametime()
      if rotate_pct > 100 then
         rotate_pct = rotate_pct - 100
      end
   else
      rotate_pct = 40
   end

   randomShip:renderTechModel(renderX1, renderY1, renderX2, renderY2, rotate_pct)
   gr.setColor(255,255,255)
   gr.drawString(shipName,rendermidX-gr.getStringWidth(shipName)/2,renderY2)

   --Handle using the middle mouse to force random ship selection
   --Because we can only tell whether the button was down, we have to check for it last frame
   --by setting the variable middle_was_down
--ms.isButtonDown became io.isMouseButtonDown, and takes an enumeration now
   if not middle_was_down then
--      middle_was_down = ms.isButtonDown("Middle")
      middle_was_down = io.isMouseButtonDown(MOUSE_MIDDLE_BUTTON)
      force_random = middle_was_down
--   elseif ms.isButtonDown("Middle")==true then
   elseif io.isMouseButtonDown(MOUSE_MIDDLE_BUTTON)==true then
      middle_was_down = true
      force_random = false
   else
      middle_was_down = false
      force_Random = false
   end


   --Function to handle a section every frame
   section = function(name, event, num)
      --MENU COLOR
      margin = gr.getScreenHeight()/6
      gr.setColor(255, 255, 255)

      --Get corner coordinates for this box
      x1 = gr.getScreenWidth()-180
      y1 = margin*num+20
      x2 = gr.getScreenWidth()-21
      y2 = margin*num+55

      --When the mouse is OVER this section...
-- ms.getX and getY are now in io, as io.getMouseX and getMouseY
--      if ms.getX() > x1 and ms.getX() < x2 and ms.getY() > y1 and ms.getY() < y2 then
      if io.getMouseX() > x1 and io.getMouseX() < x2 and io.getMouseY() > y1 and io.getMouseY() < y2 then
         --Draw the dark green insides
         gr.setColor(96, 96, 96)
         gr.drawRectangle(x1, y1, x2, y2, true, false)

         --Draw the little target lines now
         gr.setColor(255, 255, 255)
         x = x1+(x2-x1)/2
         y = margin*num

         --Top target line
         gr.drawLine(x, y, x, y+15)

         --Bottom target line
         y = margin*num+65
         gr.drawLine(x, y, x, y+15)

         --Left target line
         x = gr.getScreenWidth()-200
         y = margin*num+40
         gr.drawLine(x, y, x+15, y)

         --Right target line
         x = gr.getScreenWidth()-16
         gr.drawLine(x, y, x+15, y)

         --Handle the button click
--         if ms.isButtonDown("Left") then
         if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
            ba.setEvent(event)
            gr.drawRectangle(x1, y1, x2, y2, false, false)
         end
      end

      --Draw the outline
      gr.drawRectangle(x1, y1, x2, y2, false, false)

      --Color should always be pure green, so I'll skip setting the color for the name
      gr.drawString(name, x1 + ( (x2-x1) - gr.getStringWidth(name) ) / 2, margin*num+35)
   end

   section("Ready Room", "GS_EVENT_NEW_CAMPAIGN", 0)
   section("Campaign Room", "GS_EVENT_CAMPAIGN_ROOM", 1)
   section("Tech Room", "GS_EVENT_TECH_MENU", 2)
   section("Barracks", "GS_EVENT_BARRACKS_MENU", 3)
   section("Options", "GS_EVENT_OPTIONS_MENU", 4)
   section("Exit", "GS_EVENT_QUIT_GAME", 5)

   gr.drawImage(logo, imageX, imageY)

]
#End
Title: Re: This old menu script
Post by: WMCoolmon on February 20, 2008, 01:31:51 am
"State Hooks" was removed because Conditional scripting made it redundant.

Code: [Select]
#Conditional Hooks
$State: GS_STATE_MAIN_MENU
$On Frame: [
     -- Code goes here
]
#End

Should work exactly the same as the old state hooks.
Title: Re: This old menu script
Post by: chief1983 on February 20, 2008, 09:56:11 am
That was my guess, something there had changed, but couldn't find a good example of what to change it to.  Thanks a bunch :)