Weapon Switch

Blitz3D Forums/Blitz3D Programming/Weapon Switch

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Don't use EntityCollided() for something simple like that. Use a distance check ... look at this. I didn't test it or anything just a codesketch but it should work.


;====== TYPES =============================================

Type playerCharacter

     Field playerMesh, guns[5], haveGun[5], currentGun

End Type

Type gunInLevel

     Field gunMesh, gunType

End Type

;==========================================================

;====== SETUP =============================================

For i = 2 to 5

     gIL.gunInLevel = New gunInLevel
     gIL\gunMesh = LoadMesh("Gun" + i + ".b3d")
     gIL\gunType = i
     PositionEntity(gIL\gunMesh, goodPlaceX(), goodPlaceY(), goodPlaceZ())

Next

pC.playerCharacter = New playerCharacter
pC\playerMesh = LoadMesh("Hand.b3d")

pC\currentGun = 1
pC\haveGun[pC\currentGun] = True
For i = 1 to 5

     pC\guns[i] = LoadMesh("Gun" + i + ".b3d")
     PositionEntity(pC\guns[i], LooksGoodX(), LooksGoodY(), LooksGoodZ())
     If i > 1 Then HideEntity(pC\guns[i])

Next

;==========================================================

;====== SOMEWHERE IN YOUR LOGIC ===========================

For gIL.gunInLevel = Each gunInLevel

     If EntityDistance(gIL\gunMesh, pC\mesh) <= 1
          PickUpGun(gIL\gunType, Handle(pC.playerCharacter))
     EndIf

Next

SwitchGun(Handle(pC.playerCharacter))

;==========================================================

;====== GUN FUNCTIONS =====================================

Function PickUpGun(gun, player)

     pC.playerCharacter = Object.playerCharacter(player)
     pC\haveGun[gun] = True
     HideEntity(pC\guns[pC\currentGun])
     pC\currentGun = gun
     ShowEntity(pC\guns[pC\currentGun])

End Function

Function SwitchGun(player)

     pC.playerCharacter = Object.playerCharacter(player)
     If KeyHit(2) and pC\haveGun[1]
          HideEntity(pC\guns[pC\currentGun])
          pC\currentGun = 1
          ShowEntity(pC\guns[pC\currentGun])
     EndIF
     If KeyHit(3) and pC\haveGun[2]
          HideEntity(pC\guns[pC\currentGun])
          pC\currentGun = 2
          ShowEntity(pC\guns[pC\currentGun])
     EndIF
     If KeyHit(4) and pC\haveGun[3]
          HideEntity(pC\guns[pC\currentGun])
          pC\currentGun = 3
          ShowEntity(pC\guns[pC\currentGun])
     EndIF
     If KeyHit(5) and pC\haveGun[4]
          HideEntity(pC\guns[pC\currentGun])
          pC\currentGun = 4
          ShowEntity(pC\guns[pC\currentGun])
     EndIF
     If KeyHit(6) and pC\haveGun[5]
          HideEntity(pC\guns[pC\currentGun])
          pC\currentGun = 5
          ShowEntity(pC\guns[pC\currentGun])
     EndIF

End Function

;==========================================================