Weapon Select
Blitz3D Forums/Blitz3D Programming/Weapon Select
| ||
So i am trying to make a prop system for my game so i can pick up and store values which result in the character holding them. But there seems to be problems with it... it seems to work fine at first and the objects start to disappear and such. when i pick up an object it shows the type and what slot. I can change the slot by pressing the number keys. Right now there are only 2 objects and 2 slots. Can anyone spot any problems. I know the code is sloppy and i used weird collision stuff and no types but this is my first "game" and i am trying to do stuff that i can comprehend. I would love help from anyone.Function UpdateProps( p.Player ) If KeyDown(2) Then WeaponSelect=1 If KeyDown(3) Then WeaponSelect=2 Select WeaponSelect Case 1 If weaponslot1$<>"" Then objweild$=weaponslot1$ Case 2 If weaponslot2$<>"" Then objweild$=weaponslot2$ End Select playercollis=CountCollisions(p\entity) If EntityCollided(p\entity,TYPE_AXE)>0 sendtext$="Pick up weapon?" AddWeapon(CollisionEntity(p\entity,playercollis),"axe") Else sendtext$=axe+"-"+orange+"-"+WeaponSelect+"-"+objweild$ EndIf If EntityCollided(p\entity,TYPE_ORANGE)>0 sendtext$="Pick up orange?" AddWeapon(CollisionEntity(p\entity,playercollis),"orange") Else sendtext$=axe+"-"+orange+"-"+WeaponSelect+"-"+objweild$ EndIf If khj=1 Then DropWeapon() End Function Function AddWeapon(entityid,objtype$) If entityid<>land If WeaponSelect=1 And weaponslot1$="" Or WeaponSelect=2 And weaponslot2$="" Select objtype$ Case "axe" Select WeaponSelect Case 1 axe=1 objweild$="axe" HideEntity entityid weaponslot1$="axe" Case 2 axe=1 objweild$="axe" HideEntity entityid weaponslot2$="axe" End Select Case "orange" orange=1 objweild$="orange" HideEntity entityid Select WeaponSelect Case 1 orange=1 objweild$="orange" HideEntity entityid weaponslot1$="orange" Case 2 orange=1 objweild$="orange" HideEntity entityid weaponslot2$="orange" End Select End Select EndIf EndIf End Function Function DropWeapon() Select objweild$ Case "axe" ShowEntity axe1 PositionEntity axe1,playerx,playery,playerz axe=0 Select WeaponSelect Case 1 weaponslot1$="" Case 2 weaponslot2$="" End Select objweild$="" Case "orange" ShowEntity orange1 PositionEntity orange1,playerx,playery,playerz orange=0 Select WeaponSelect Case 1 weaponslot1$="" Case 2 weaponslot2$="" End Select objweild$="" End Select End Function |
| ||
Comment your code :) Should be a reflex, especially if it's your first game :) |
| ||
Edit : Never mind again i do need help :) |
| ||
Is this good?;update weapons/objects(player type) Function UpdateProps( p.Player ) ;choose between weapon slots If KeyDown(2) Then WeaponSelect=1 If KeyDown(3) Then WeaponSelect=2 Select WeaponSelect Case 1 If weaponslot1$<>"" Then objweild$=weaponslot1$ Case 2 If weaponslot2$<>"" Then objweild$=weaponslot2$ End Select ;p\entity is player mesh playercollis=CountCollisions(p\entity) If EntityCollided(p\entity,TYPE_AXE)>0 ;a function that displays text sendtext$="Pick up weapon?" AddWeapon(CollisionEntity(p\entity,playercollis),"axe") Else ;a function that displays text sendtext$=axe+"-"+orange+"-"+WeaponSelect+"-"+objweild$ EndIf If EntityCollided(p\entity,TYPE_ORANGE)>0 ;a function that displays text sendtext$="Pick up orange?" AddWeapon(CollisionEntity(p\entity,playercollis),"orange") Else ;a function that displays text sendtext$=axe+"-"+orange+"-"+WeaponSelect+"-"+objweild$ EndIf ;If key j hit Then... If khj=1 Then DropWeapon() End Function Function AddWeapon(entityid,objtype$) ;defines the weild variable and tells the program that you just picked ;up a weapon and what slot it is in If entityid<>land If WeaponSelect=1 And weaponslot1$="" Or WeaponSelect=2 And weaponslot2$="" Select objtype$ Case "axe" Select WeaponSelect Case 1 axe=1 objweild$="axe" HideEntity entityid weaponslot1$="axe" Case 2 axe=1 objweild$="axe" HideEntity entityid weaponslot2$="axe" End Select Case "orange" orange=1 objweild$="orange" HideEntity entityid Select WeaponSelect Case 1 orange=1 objweild$="orange" HideEntity entityid weaponslot1$="orange" Case 2 orange=1 objweild$="orange" HideEntity entityid weaponslot2$="orange" End Select End Select EndIf EndIf End Function Function DropWeapon() ;checks what the weilded object is and places objects on ground under player Select objweild$ Case "axe" ShowEntity axe1 PositionEntity axe1,playerx,playery,playerz axe=0 Select WeaponSelect Case 1 weaponslot1$="" Case 2 weaponslot2$="" End Select objweild$="" Case "orange" ShowEntity orange1 PositionEntity orange1,playerx,playery,playerz orange=0 Select WeaponSelect Case 1 weaponslot1$="" Case 2 weaponslot2$="" End Select objweild$="" End Select End Function |
| ||
i didn't understand your problem actually? what is it? you cant select an objects? |
| ||
Well i can pickup the items but when i keep dropping them and switching them to different slots sometimes a weapon disappears or randomly move to the players location... |
| ||
I don't now exactly what type of game this is going to be, but in a FPS or TPS I would suggest not to use Collision to pick a weapon up, it's just a waste of performence. Instead use EntityDistance. A pivot at your players feet location is handy for a number of things, including Dictance checks for things that should be picked up automaticly. Simply parse an array that holds the handles of the items and check the distances. No idea about slots, dropping things etc. Maybe use a stack for these things. So when you drop something, all higher items on the stack will move down one slot. Every new item is put on top of the stack by default. Moving things from one slot to an other slot may be realized the same way: first by removing the item from the stack, then shrink the stack, then insert a new slot at the wanted position, then put the removed item into the new slot. Not sure if I really do understand what you're talking about, anyway :) Make sure to get rid of the "sometimes..randomly" problems. I think not to use Collisions + Types in situations where it's not neccessary anyway might help to do so. And don't use too much String Comparation. Instead use varaibles with names that are making sense. Eg. instead of If A$="Orange" try: Orange=123:If A=Orange etc. It's much faster. |