Author Topic: i really thought i was done with scripting...  (Read 3981 times)

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
i really thought i was done with scripting...
« on: 2006-01-15, 04:56:17 PM »
... especially the hit points part, but apparently not so (assumming its not too much trouble, which you can decide upon reading my request).

anyway, do you think it would be possible to make this script (my current script)
Code: [Select]
' ======== INITIAL STARTUP SCRIPT (Number 0) =========

Sub Player_OnPlayInit()
   HostObj.StartScript = 1
End Sub

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16

#Split == Runtime Script (Number 1)

Option Explicit

Dim XOff, YOff
Dim P2OffsetX, P2OffsetY
Dim P2Actions, intSprTwo
Dim ScrollerSprite
Dim Hits(16), i
ScrollerSprite = -1
intSprTwo = -1

For i = 0 To 3
   Set Hits(i) = New Hit
   Hits(i).Hit "5-0TheMoon","MJW" & i + 1,2
Next
For i = 4 To 16
   Set Hits(i) = New Hit
   Hits(i).Hit "5-0TheMoon", "MJS" & mid(cstr(i + 97), 2), 3
Next

Const nSprWidth = 41
Const nSprHeight = 75

'Sub Player_OnPlayInit()
   Dim oMap 'i,
   Dim oNewSpecial
   For i = 0 To UBound(Hits)
      Set oNewSpecial = NewSpecialFunction
      Set oMap = ProjectObj.Maps(Hits(i).getMap())
      oNewSpecial.FuncType = 7 ' SPECIAL_EVENT
      oNewSpecial.Flags = 8 ' INTFL_RAISEEVENT
      oNewSpecial.Name = "COL_" & Hits(i).getSprite()
      oMap.AddSpecial (HostObj.AsObject(oNewSpecial))
   Next
'End Sub

Sub Display_KeyDown(KeyCode, Shift)
' E=69, S=83, D=68, F=70
If KeyCode = 69 Then P2Actions = P2Actions Or ACTION_UP
If KeyCode = 83 Then P2Actions = P2Actions Or ACTION_LEFT
If KeyCode = 68 Then P2Actions = P2Actions Or ACTION_DOWN
If KeyCode = 70 Then P2Actions = P2Actions Or ACTION_RIGHT
End Sub

Sub Display_KeyUp(KeyCode, Shift)
If KeyCode = 69 Then P2Actions = P2Actions And Not ACTION_UP
If KeyCode = 83 Then P2Actions = P2Actions And Not ACTION_LEFT
If KeyCode = 68 Then P2Actions = P2Actions And Not ACTION_DOWN
If KeyCode = 70 Then P2Actions = P2Actions And Not ACTION_RIGHT
End Sub

Sub Player_OnAfterMoveSprites()

    If ProjectObj.GamePlayer.rMap.Name = "4-2SpaceFlight" And YOff = 0 Then
        YOff = 15003 - ProjectObj.GamePlayer.rMap.ViewHeight
    End If

    Dim oMap, oPlayer, oLayer, nLyrWid, nLyrHgt, i
    Set oPlayer = ProjectObj.GamePlayer
    Set oMap = oPlayer.rMap

    If ProjectObj.GamePlayer.rMap.Name = "5-0TheMoon" Then
        oPlayer.ScrollMarginX = 292
        oPlayer.ScrollMarginY = 196
    End If

'Two Player Stuff

    If ProjectObj.GamePlayer.rMap.Name <> "0-4LevelSelect" Then
        intSprTwo = -1
        oPlayer.ScrollMarginY = 185
    Else
        Set oLayer = oMap.MapLayer(1)
        If intSprTwo < 0 Then
            For i = 0 To oLayer.SpriteCount - 1
                If oLayer.Sprite(i).rDef.Name = "Player2" Then intSprTwo = i
            Next
        End If
        With oLayer.Sprite(intSprTwo)
            oPlayer.ScrollMarginY = 62
            If .ProcessAction(P2Actions) Then
                .CurState = (.CurState Mod (.rDef.Template.StateCount \ 2)) _
                            + .rDef.Template.StateCount \ 2
                .CurFrame = .CurFrame Mod .rDef.StateFrameCount(.CurState)
            Else
                .CurState = (.CurState Mod (.rDef.Template.StateCount \ 2))
            End If
            oMap.ViewTop = 240
            If P2OffsetX + oPlayer.ScrollMarginX > .X Then
                P2OffsetX = .X - oPlayer.ScrollMarginX
            End If
            If P2OffsetX + oMap.ViewWidth - oPlayer.ScrollMarginX < .X + nSprWidth Then
                P2OffsetX = .X - oMap.ViewWidth + oPlayer.ScrollMarginX + nSprWidth
            End If
            If P2OffsetY + oPlayer.ScrollMarginY > .Y Then
                P2OffsetY = .Y - oPlayer.ScrollMarginY
            End If
            If P2OffsetY + oMap.ViewHeight - oPlayer.ScrollMarginY < .Y + nSprHeight Then
                P2OffsetY = .Y - oMap.ViewHeight + oPlayer.ScrollMarginY + nSprHeight
            End If
            If P2OffsetX < 0 Then P2OffsetX = 0
            If P2OffsetY < 0 Then P2OffsetY = 0
            nLyrWid = oLayer.Columns * 32
            nLyrHgt = oLayer.Rows * 32
            If P2OffsetX > nLyrWid - oMap.ViewWidth Then P2OffsetX = nLyrWid - oMap.ViewWidth
            If P2OffsetY > nLyrHgt - oMap.ViewHeight Then P2OffsetY = nLyrHgt - oMap.ViewHeight
            oMap.Draw P2OffsetX, P2OffsetY, False
            oMap.ViewTop = 0
        End With
    End If

'Automatic Scrolling Stuff
    If ProjectObj.GamePlayer.rMap.Name = "2-4BonusLevel" Then
        XOff = XOff + 1
        With ProjectObj.GamePlayer
            If .PlayerSprite.X <= XOff Then
                If .PlayerSprite.DX < 0 Then .PlayerSprite.DX = 1
                .PlayerSprite.DX = .PlayerSprite.rDef.Template.MoveSpeed
                If .PlayerSprite.X < XOff - .PlayerSprite.Width / 2 Then
                    XOff = 1
                End If
            End If
            .rMap.Draw XOff, YOff
        End With
    End If

   
    If ProjectObj.GamePlayer.rMap.Name = "4-2SpaceFlight" Then
        oPlayer.ScrollMarginX = 5
        oPlayer.ScrollMarginY = 5
        If ScrollerSprite < 0 Then
            ScrollerSprite = FindScrollerSprite
        End If
       
        If ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer.SpriteCount <= ScrollerSprite Then
            ScrollerSprite = FindScrollerSprite
        End If
   
        If ScrollerSprite >= 0 Then
            If Left(ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer.Sprite(ScrollerSprite).rDef.Name, 8) <> "Scroller" Then
                ScrollerSprite = FindScrollerSprite
            End If
        End If
   
        With ProjectObj.GamePlayer
            .MapScrollX = .PlayerSprite.rDef.rLayer.Sprite(ScrollerSprite).X
            .MapScrollY = .PlayerSprite.rDef.rLayer.Sprite(ScrollerSprite).Y
            If .PlayerSprite.Y > .MapScrollY + .rMap.ViewHeight - .ScrollMarginY - .PlayerSprite.Height Then
                .PlayerSprite.DY = -.PlayerSprite.rDef.Template.MoveSpeed
            ElseIf .PlayerSprite.Y < .MapScrollY + .ScrollMarginY Then
                .PlayerSprite.DY = .PlayerSprite.rDef.Template.MoveSpeed
            End If
            If .PlayerSprite.X > .MapScrollX + .rMap.ViewWidth - .ScrollMarginX - .PlayerSprite.Width Then
                .PlayerSprite.DX = -.PlayerSprite.rDef.Template.MoveSpeed
            ElseIf .PlayerSprite.X < .MapScrollX + .ScrollMarginX Then
                .PlayerSprite.DX = .PlayerSprite.rDef.Template.MoveSpeed
            End If
        End With
    End If
End Sub

Function FindScrollerSprite()
   Dim i
   With ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer
      For i = 0 To .SpriteCount - 1
         If Left(.Sprite(i).rDef.Name, 8) = "Scroller" Then
            FindScrollerSprite = i
            Exit Function
         End If
      Next
   End With
   FindScrollerSprite = -1
End Function

Sub Player_OnControllerMove(OldActions, NewActions)

'Jumping Player
  With ProjectObj.GamePlayer.PlayerSprite
      If (Not OldActions) And NewActions And ACTION_BUTTON2 Then
          If (.rDef.SolidTest(.X, .Y + .Height) Or .rDef.SolidTest(.X + .Width - 1, .Y + .Height)) Or (Not .pRideOnRef Is Nothing) Then
              .DY = -.rDef.Template.JumpHeight
          End If
      End If
  End With
End Sub

Class Hit
   Private hMap
   Private hSpriteName
   Private hHPs
   Public Sub Hit(Map, SpriteName, HPs)
      hMap = Map
      hSpriteName = SpriteName
      hHPs = HPs
   End Sub

   Public Function getMap()
      getMap = hMap
   End Function

   Public Function getSprite()
      getSprite = hSpriteName
   End Function

   Public Function getHPs()
      getHPs = hHPs
   End Function

End Class

Sub Player_OnSpecialFunction(SpecialObj)
   Dim i, layer, idx, spr

   For i = 0 To UBound(Hits)
   spr = Hits(i).getSprite()
   If Left(SpecialObj.Name, 4 + Len(spr)) = "COL_" & spr Then
      Set spr = FindSpriteByDef(spr, layer, idx)
      If spr.UserData > Hits(i).getHPs() Or spr.UserData < 0 Then spr.UserData = 0
      spr.UserData = spr.UserData + 1
      If spr.UserData = Hits(i).getHPs() Then
         layer.RemoveSprite (idx)
      End If
   End If
Next
End Sub

Function FindSpriteByDef(SpriteName, ByRef oLayer, ByRef oSprIndex)
   Dim i, j, oMap
   With ProjectObj.GamePlayer.rMap
      For i = 0 To .LayerCount - 1
         For j = 0 To .MapLayer(i).SpriteCount() - 1
            If .MapLayer(i).Sprite(j).rDef.Name = SpriteName Then
               Set oLayer = .MapLayer(i)
               oSprIndex = j
               Set FindSpriteByDef = oLayer.Sprite(j)
            End If
         Next
      Next
   End With
End Function

HostObj.SinkObjectEvents ProjectObj.GamePlayer, "Player"
HostObj.SinkObjectEvents CurrentDisplay, "Display"
HostObj.ConnectEventsNow()
include sprites on map "6-1ConanTheRebel" (layer Main), begining with "ConanWater*" take 5 hits, and begining with "JarFly*" and "JarDrv*" take 3 hits? (the * would mostlikely just be a number)
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: i really thought i was done with scripting...
« Reply #1 on: 2006-01-16, 10:18:04 PM »
Somewhat simple, yes.  Just add this code below the two for loops (the part that looks very similar to this).  Note that you'll need to change a couple of things.  This is assuming that there are fewer than 10 of each sprite.  Just change XA, XB and XC to the number of each sprite below.  (or you can do the addition yourself to save a few CPU cycles every frame if you want.  If there are 10 or more of any sprites you'll have to modify the code to work the way the MJS sprites did.  (it would be a good idea to do so to make sure I did the math right.  Then the numbers should line up (For i = 17 to 19, 20 to 23, 24 to 29 for example)

Code: [Select]
For i = 17 To 17 + XA
   Set Hits(i) = New Hit
   Hits(i).Hit "6-1ConanTheRebel","ConanWater" & i - 16,5
Next
For i = 18 + XA To 18 + XA + XB
   Set Hits(i) = New Hit
   Hits(i).Hit "6-1ConanTheRebel","JarDrv" & i - (17 + XA), 3
Next
For i = 19 + XA + XB To 19 + XA + XB + XC
   Set Hits(i) = New Hit
   Hits(i).Hit "6-1ConanTheRebel","JarFly" & i - (18 + XA + XB), 3
Next
Edward Dassmesser

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
Re: i really thought i was done with scripting...
« Reply #2 on: 2006-01-16, 10:32:48 PM »
nah there wont be more than 10 of each at once, i believe that there will only be 4 of each JarFly/Drv, and only 1 ConanWater. when i say only 4 and only 1, i mean at once.
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
Re: i really thought i was done with scripting...
« Reply #3 on: 2006-01-22, 09:43:16 AM »
ok, so instead of adding 3 more sprites, im just adding 1 more, so instead of adding
[code]
For i = 17 To 17 + XA
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: i really thought i was done with scripting...
« Reply #4 on: 2006-01-22, 10:58:35 AM »
Something like that.  You want to be continuous in the Hit objects you're defining, so do the first loop instead:

Code: [Select]
For i = 17 To 17 + XA
   Set Hits(i) = New Hit
   Hits(i).Hit "6-1ConanTheRebel","JarDrv" & i - (16), 3
Next
Where XA is the number of JarDrv sprites you are creating.

Yes, it is the last 3 that sets the number of hitpoints for the sprite.  Also, I forgot one other thing.  In the line
Code: [Select]
Dim Hits(16), i You need to change it to
Code: [Select]
Dim Hits(16 + XA), i Again, where XA is the number of JarDrv sprites you are creating.
Edward Dassmesser

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
Re: i really thought i was done with scripting...
« Reply #5 on: 2006-01-22, 02:21:32 PM »
creating at once, or in total? because ther would only ever be one on screen at once, but i have no way of knowing how many would be created in total, since its another "random attack" thing.
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy

billybob884

  • Contributor
  • Fanatic
  • **
  • Posts: 355
    • AOL Instant Messenger - billybob884
    • View Profile
Re: i really thought i was done with scripting...
« Reply #6 on: 2006-01-22, 04:52:26 PM »
ok, the script works, now just one* more problem to sort out.




*...   for now...
"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." :: Hitchhiker's Guide to the Galaxy