Author Topic: Scripting Woes!!  (Read 5135 times)

ingumc

  • Visitor
  • *
  • Posts: 2
    • View Profile
Scripting Woes!!
« on: 2006-02-26, 05:49:18 AM »
Hi, it's my first time posting here. Hope everyone's doing well. I'm working on a game, and am having some trouble with the VBS script. What I'm trying to do is for the player to use an item on an enemy sprite, and the enemy sprite will switch to another sprite for like 3 seconds, and then switch back to its original sprite. Problem I'm having difficulty with is how to let the game know which sprite was affected by the item. In this case, there are multiple patrolling enemies, and the intention is to have the affected enemy sprite return to its original path after the effect of the item wears off.

The approach I took is to compare all the active sprites in the layer, find the missing enemy sprite by number and then spawn him at the trigger location. Another problem is deleting a sprite by definition name, maybe it's just syntax (hopefully). It's certainly easier to just kill an enemy instead of all this, but that's not the direction I want to take.

Please help!

Thanks...



*******This takes place when the special function (TimerBlinded) is run to raise an event as indicated in item 2 above

If objSpecial.Name = "TimerBlinded" Then

           'Stores the position of the blinded guard
           MaceX = ProjectObj.GamePlayer.TriggerX
           MaceY = ProjectObj.GamePlayer.TriggerY

           'Sets the flag to start the BlindTimer
           BlindFlag = 1
        End If


*******This is part of the main code

If BlindFlag = 1 Then

       'Starts the timer for the blinded effect
       BlindTimer = BlindTimer + 1

       'Checks the timer for the blinded effect to wear off
       If BlindTimer > 180 Then

          With ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer

          'Do loop to check which guard was blinded
          Do While (BlindFlag = 1)

             Dim nIdx, GuardNum

             'For loop to check the sprites in the layer to see which guard was blinded
             For GuardNum = 1 to 7

                'Checks each sprite in the layer and if a guard # is found, exit the For loop and go to the next guard
                For nIdx = 0 to .SpriteCount - 1

--------------------I think there's a syntax error for the sprite compare here---------------------------

                   If .Sprite(nIdx) Is .Sprite = ("Guard" & CStr(GuardNum)) Then
                      nIdx = 0
                      Exit For
                   End If

                   'If the guard # isn't found after checking all the sprites, that's the guard affected and exit the Do loop
                   If nIdx = .SpriteCount -1 Then
                      Exit Do
                   End If

                Next

             Next

          Loop

          End With

----------------------This section is working, I tested with a set sprite and it spawns at the proper location--------------------------

          Dim GuardCheck, GuardSprMace

          'Stores which guard was blinded
          GuardCheck = ("Guard" & Cstr(GuardNum))

          'Switches back to the original guard sprite
          With ProjectObj.GamePlayer
          Set GuardSprMace = ProjectObj.GamePlayer.rMap.SpriteDefs(GuardCheck).MakeInstance
              .PlayerSprite.rDef.rLayer.AddSprite HostObj.AsObject(GuardSprMace)
              GuardSprMace.X = MaceX
              GuardSprMace.Y = MaceY

-----------------------Something wrong here, I can't seem to delete the sprite by definition name---------------------

          .rMap.RemoveSpriteDef("Blinded")

          End With

          'Resets the Blind flag and timer
          BlindFlag = 0
          BlindTimer = 0
       End If
    End If

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Scripting Woes!!
« Reply #1 on: 2006-02-26, 11:02:34 AM »
Perhaps if you describe in more subjective terms what you are trying to accomplish, such as what exactly is going on in the game, it may be easier to find a different way to do this.  Something that comes to mind is how you are finding the sprite can be greatly simplified.  Using Player_OnSpritesCollide, you are given the sprite index of each sprite involved in the collision, so you don't have to search for it.

Then, my question is, what happens when the enemy sprite is hit by this item?  Do they switch to another sprite that follows a different path for a while?  And you want them to go back to the first path afterwards?  That should be easy.  Creating a sprite anywhere that is set to follow a path (not relative to start position) will automatically go towards that path then start following it.
Edward Dassmesser

ingumc

  • Visitor
  • *
  • Posts: 2
    • View Profile
Re: Scripting Woes!!
« Reply #2 on: 2006-02-26, 03:33:59 PM »
Here's what I'm trying to accomplish. There are seven patrolling enemies in the game, that will chase the player if he comes within a certain range. The only way to "reset hate" is to use an item that can be picked up in the level. When the item is used on the enemy by changing the player sprite to an item use animation and defining the collision definition from that (use item sprite colliding with enemy sprite), the enemy will switch from the regular patrolling one to a sprite that shows that the item affected him (stays at the position of the collision) for 3 seconds. After the time has passed, the enemy will revert back to the original sprite and return to his path.
My issue is how to know which one of the seven enemies the player used the item on. This is so that after the item effect has passed, I will still have all seven enemies patrolling all the seven paths. Hope that helps?  :)
If I use Player_OnSpritesCollide, how do I access the two sprites involved in the collision?

Thanks!

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Scripting Woes!!
« Reply #3 on: 2006-02-26, 05:06:29 PM »
Take a look at the refference to get the exact function signature, but you are passed the sprite index of each sprite, which you can use thus:

Code: [Select]
set sprA = ProjectObj.GamePlayer.rMap.MapLayer(ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer).Sprite(ClsASprIdx)
set sprB = ProjectObj.GamePlayer.rMap.MapLayer(ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer).Sprite(ClsBSprIdx)
Edward Dassmesser

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Scripting Woes!!
« Reply #4 on: 2006-02-27, 08:27:02 AM »
Correction: the rLayer property refers to the layer itself, not just the index.  Therefore you can simplify that:
Code: [Select]
Set sprA = ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer.Sprite(ClsASprIdx)
Set sprB = ProjectObj.GamePlayer.PlayerSprite.rDef.rLayer.Sprite(ClsASprIdx)