Character customization?

Blitz3D Forums/Blitz3D Beginners Area/Character customization?

Cubed Inc.(Posted 2010) [#1]
I'm trying to add character costumization in my game.

So with the help of the forums, I was able to attach head pieces and hair to the players head, but I'm trying to make it so that you can change from one head peice or hair to the next by pressing the arrow keys.

How could I do this?


Rob the Great(Posted 2010) [#2]

;Load both of the meshes for the clothing
Global headpiece1 = LoadMesh("TheFirstHeadPieceHere.b3d")
Global headpiece2 = LoadMesh("TheSecondHeadPieceHere.b3d")

;Hide the second head piece for now
HideEntity headpiece2

;Set up a variable to switch through multiple clothing sets
Global headpieceindex = 1

;And another variable for your maximum headpiece count
Global maxheadpiece = 2 ;Change this number to match the number of headpieces you have

;After your character is loaded, attach it to the 'head' bone as you did in the previous thread

While Not KeyDown(1) ;main loop here

   ;do all of your game stuff here

   ;call the function below
   UpdateCharacterClothing()

Wend ;End the main loop

;In your functions list, include this:
Function UpdateCharacterClothing()

   If KeyDown(LEFTKEY)   ;I can't remember the Scancode value for the left key
      headpieceindex = headpieceindex - 1   ;Move Index Pointer Left
   EndIf

   If KeyDown(RIGHTKEY)   ;I can't remember the Scancode value for the right key
      headpieceindex = headpieceindex + 1   ;Move Index Pointer Right
   EndIf

   If headpieceindex <= 0
      headpieceindex = 0   ;Don't let the pointer fall below 0
   EndIf

   If headpieceindex >= maxheadpiece
      headpieceindex = maxheadpiece   ;Don't let the pointer go above the maximum
   Endif

   If headpieceindex = 1
      ShowEntity headpiece1   ;Put on the headpiece1
   Else   ;If the headpieceindex is NOT equal to 1
      HideEntity headpiece1   ;Take off the headpiece1
   EndIf

   If headpieceindex = 2
      ShowEntity headpiece2   ;Put on the headpiece2
   Else   ;If the headpieceindex is NOT equal to 2
      HideEntity headpiece2   ;Take off the headpiece2
   EndIf

   ;Repeat the 'if' statements above as needed for every headpiece
   ;Note that the code above will take off ALL headpieces if headpieceindex = 0

End Function


Here's one way I just thought of. It may be a lot easier to use types if you have a lot of headpieces. That, or else you could call another function for all of those repeating 'if' statements and pass on the numbers through it to check as arguments.

I'll also have you know that this is probably the first time I've ever used the 'Else' statement, since I can remember that you're especially fond of that command. Due to the fact that I'm so new to that command, it may not work perfectly, but this was more or less to demonstrate concept.

Let me know if it doesn't make sense.


stanrol(Posted 2010) [#3]
kinda like RuneScape.


_PJ_(Posted 2010) [#4]
If you have this 'index' of headpieces, And, presumably, you would maybe know the limits i.e. how many headpieces you have or a maximum number possible to have, then why not use an Array?

  If KeyDown(203)   ;I can't remember the Scancode value for the left key
HideEntity headpiece[headpieceindex]; Hide current headpiece now since its gonna change
      headpieceindex = headpieceindex - 1   ;Move Index Pointer Left
   EndIf

   If KeyDown(205)   ;I can't remember the Scancode value for the right key
HideEntity headpiece[headpieceindex]; Hide current headpiece now since its gonna change
      headpieceindex = headpieceindex + 1   ;Move Index Pointer Right
   EndIf

   If (headpieceindex > (headpiecemax-1)) then headpieceindex= 0
   If (headpieceindex < 0) then headpieceindex=(headpiecemax-1)

   ShowEntity headpiece[headpieceindex]   ;Put on the headpiece[n]