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