Author Topic: Hit Points script  (Read 8663 times)

GameZealot

  • Guest
Hit Points script
« on: 2006-04-01, 12:13:13 PM »
Hey everyone!

Do you guys think you can make me a script for H.P.?  I have no clue on how to script and this hit ponits thing would work out perfectly!

I need it where three different KINDS of enemies(for example:  There is a gunner class and there are 4 of them; there is a rocket class and there are two of them.  Basically, gunner and rocket are the different kinds of enemies but there will be multiple enemies for each class.  I hope that wasn't too confusing...) can have there own H.P.  And, if possible, if I can edit the amount for different stages of badguys.  I know this sounds like a BIG request but if you guys don't mind, I could really use the help.

Thanks! :)

sam

  • Fanatic
  • ***
  • Posts: 303
  • This statement is false.
    • MSN Messenger - samlancashire@hotmail.com
    • View Profile
    • samlancashire.com
    • Email

GameZealot

  • Guest
Re: Hit Points script
« Reply #2 on: 2006-04-01, 12:25:29 PM »
Cool, thanks man!

sam

  • Fanatic
  • ***
  • Posts: 303
  • This statement is false.
    • MSN Messenger - samlancashire@hotmail.com
    • View Profile
    • samlancashire.com
    • Email
Re: Hit Points script
« Reply #3 on: 2006-04-01, 12:30:41 PM »
there's tons of scripts in the FAQ/Tutorial section of gamedev.sf.net

GameZealot

  • Guest
Re: Hit Points script
« Reply #4 on: 2006-04-01, 12:38:22 PM »
Shoot... I tried out that script and it didn't work for me... I change the names I was suppose to change.  Could I get a little more help this? :(

sam

  • Fanatic
  • ***
  • Posts: 303
  • This statement is false.
    • MSN Messenger - samlancashire@hotmail.com
    • View Profile
    • samlancashire.com
    • Email
Re: Hit Points script
« Reply #5 on: 2006-04-01, 12:52:03 PM »
well, I don't know much about scripting so you'll have to wait until one of the pros come along :)

sam

  • Fanatic
  • ***
  • Posts: 303
  • This statement is false.
    • MSN Messenger - samlancashire@hotmail.com
    • View Profile
    • samlancashire.com
    • Email
Re: Hit Points script
« Reply #6 on: 2006-04-01, 12:55:58 PM »
did you do the other stuff it said to do?
Quote
To make it work you MUST: Create a collision definition between a sprite of the enemy class and a sprite of the weapon class (where the enemy class is class A) which activates COL_<ADef>*

GameZealot

  • Guest
Re: Hit Points script
« Reply #7 on: 2006-04-01, 01:29:10 PM »
Yes, I did this but it still doesn't work...

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Hit Points script
« Reply #8 on: 2006-04-02, 01:08:05 AM »
Post the script with your changes, along with what exactly each change you made means (at least, what you think it means).  Then we can see what's up.
Edward Dassmesser

GameZealot

  • Guest
Re: Hit Points script
« Reply #9 on: 2006-04-02, 09:18:15 AM »
Alright, sorry for taking so long!  Here is the script and the changes I thought were necessary, rather I thought the guide line for this meant.
<------------------------------------------------------------------>

Code: [Select]
Option Explicit

'-----Initialize Sprites-----
Dim Hits(2), i
for i = 0 to 2
   set Hits(i) = new Hit
   Hits(i).Hit "LevelOne","Evil" & i, 5
next
'-----End Initialization-----

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_OnPlayInit()
   Dim i, oMap
   Dim oNewSpecial
   for i = 0 to ubound(Hits)
      Set
      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 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.ConnectEventsNow()
ProjectObj.GamePlayer.Play 16
<----------------------------------------------------------->

I only changed the "Map1" and "Enemy" text from the code.  I thought that by changing the name "Map1" in the script would let the computer know which map I am refering to; I changed the "Enemy" text to the name of one of my sprites(which I thought you could have more) and I assumed that it would recognize the enemy but it seems the the script only crashes.  I hope you can make sense of that jibberish, I honestly don't know what I am talking about. 

What do you think I am doing wrong?
Also, sorry for the huge post...
« Last Edit: 2006-04-02, 09:30:46 AM by GameZealot »

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Hit Points script
« Reply #10 on: 2006-04-02, 11:44:24 AM »
This set of lines:

for i = 0 to 2
   set Hits(i) = new Hit
   Hits(i).Hit "LevelOne","Evil" & i, 5
next


Makes 3 new enemy Hitpoint counters for enemies named "Evil0", "Evil1", and "Evil2" each with 5 hitpoints, on map "Level1".  If the name of your sprite is just "Evil" you just have to create a single one.  The code above is using a loop to create multiple counters.  If you want to create each one individually, it would look like this:


   set Hits(i) = new Hit
   Hits(i).Hit "LevelOne","Evil0", 5
   set Hits(i) = new Hit
   Hits(i).Hit "LevelOne","Evil1", 5
   set Hits(i) = new Hit
   Hits(i).Hit "LevelOne","Evil2", 5


This does the same thing, but without using the loop.  So for it to work for a sprite named "Evil":

Code: [Select]
   set Hits(i) = new Hit
   Hits(i).Hit "LevelOne","Evil", 5
Edward Dassmesser

StarCraft

  • Guest
Re: Hit Points script
« Reply #11 on: 2006-04-02, 12:31:38 PM »
Hey!!

  I'm really sorry about butting into this topic, but I have a request that relates to this one, so I thought it would have been worthless to start a new topic...

Anyways, I need it so that each of these "Evil"s (Evil0, Evil1, Evil2; for example) to have a very small bar above there sprite that shows up red.  As you deplete their HP, the bar drains and the background is black!!  I think this would be so cool!

Okay...I'll try to reiterate myself:

  I need it put into that script of "Multiple Hit Points" that each of the enemies with an individual counter of Hit Points also has a red bar above their head!  Okay, I hope that made it easier to understand!  If you could do this, then you will be my favorite person in the WHOLE WORLD!

thanks!

durnurd

  • Lead Lemming
  • Expert
  • Fanatic
  • *****
  • Posts: 1234
  • Games completed so far: 0
    • MSN Messenger - durnurd@hotmail.com
    • View Profile
    • Find My Ed
Re: Hit Points script
« Reply #12 on: 2006-04-02, 03:37:33 PM »
Unfortunately, there is no native function to VBScript, BMDXCtls, or GameDev that allows drawing directly on the drawing surface.  This means, if you want to draw a Hitpoint bar directly on the drawing surface, you would have to:

A) Program through VB itself and wrap around GameDev,
B) Use something called dynacall.dll to dynamically call an API to draw on a drawing surface directly (provided by BMDXCtls's GetDC() method),
C) Change BMDXCtls to allow directly drawing on its surface, or
D) use the DrawText method of BMDXCtls to draw some facsimile of a hitpoint bar

Other methods include creating sprites with different frames for each different hitpoint level and altering them dynamically in the script, creating a "Hitpoint Bar" layer and drawing the bars on that layer in script using tiles, or possibly just drawing the hitpoints as an inventory item that moves around the screen with the sprite.

This last method seems the easiest out of all of these, however it would still take a lot of work.  You would need a different inventory item for each sprite, they would all have to have a blank name, and the script would have to handle placing them correctly, only drawing them if they are on the screen.
Edward Dassmesser

StarCraft

  • Guest
Re: Hit Points script
« Reply #13 on: 2006-04-02, 03:51:34 PM »
Well....okay...that sounds a little out of my league.  i have one final question, Mr. Programmer.  Would it be possible to just draw the hitpoint bar in the inventory; but it only displays the HP for the sprite that is being attacked at the moment?  Kind of like Diablo II (I hope you've played it before!)?

Say there are three monsters.  A troll, a human and a bird.  They all have hitpoint bars, but not drawn directly over them, they are 'hidden' so to say.  You attack the troll and it's HP displays at the top of the HUD (Heads up display).  It shows that the bar has been depleted by 1.  When you move over to the human and attack him, his HP is displayed where the Troll's hp was, only it is redrawn over it, or something.  I hope this makes sense!!

thanks for you help anyway, programmer.

StarCraft

  • Guest
Re: Hit Points script
« Reply #14 on: 2006-04-02, 04:54:48 PM »
Help?

I tried the script, and all it does is crash on line 39; char 11: Syntax error or something!  I can't get it to work!!

Wait scratch that, it's line 39, character 10: syntax error.  What in the good world does that mean!?
« Last Edit: 2006-04-02, 05:02:07 PM by StarCraft »