A little problem with commands

Blitz3D Forums/Blitz3D Beginners Area/A little problem with commands

I can't seem to get my "shooting" code to work.. Please take a look and help me out. I think it might be something with the Update(renderworld) command but I'm not sure. Also, I'd like some good fog, if anyone has any recommendations?
Type Timer
	Field start
	Field timeOut
	Field vel_start#;=90
	Field vel_down#;=-2
End Type

;System
Global AppFPS =45
Global screen_width% = 1024
Global screen_height% = 768
Global screen_halfwidth% = screen_width/2
Global screen_halfheight% = screen_height/2
Global camHeight#=4.5  ; default height of the camera behind player
Global camDist#=-7 ; default distance of the camera behind player
Global dest_xang# 
Global dest_yang# 
Global pl_gravity#=-.5
Global pl_jump=0
Global Jump_Move#=0
Global Move_For_Back#
Global Move_Left_Right#
Global Move_Slow#=.1
Global which_one=0
Global player
Global playerattack
Global revolverman
Global shotgun
Global revolver

;CONST
Const C_PLAYER=1, C_LEVEL=2, C_BULLET=3,C_ENEMY=4

AppTitle "Italia"
HidePointer

;Screen
Graphics3D screen_width,screen_height,32,1
SetBuffer BackBuffer()

CreateWorld()

;bullets
Type bullettype
	Field entityhandle
End Type

Type badguytype
	Field entityhandle
	Field state
End Type

;CAMERA
camera =CreateCamera()

;Player Pivot
plpivot=CreatePivot()
EntityType plpivot, C_PLAYER
;EntityRadius plpivot,1.8,3
PositionEntity plpivot, 0, 3,0

;Player, now a cube but you can change for a nice model
;Player=CreateCube(plpivot)
;ScaleEntity player,1,3,.7
;MoveEntity player,0,1,0
;EntityColor Player,255,0,255


which_one = 0
player=LoadMesh("C:\Documents and Settings\Chad\Desktop\game\mobster\player.b3d",plpivot)
ScaleEntity player,.08,.08,.08
MoveEntity player,0,1,0

playerattack=LoadMesh("C:\Documents and Settings\Chad\Desktop\game\mobster\playerattack.b3d",plpivot)
ScaleEntity playerattack,.08,.08,.08
MoveEntity playerattack,0,1,0

revolverman=LoadMesh("C:\Documents and Settings\Chad\Desktop\game\mobster\revolverman.b3d",plpivot)
ScaleEntity revolverman,.08,.08,.08
MoveEntity revolverman,0,1,0

EntityAlpha player,1
EntityAlpha playerattack,0
EntityAlpha revolverman,0

;Bullet Mesh
bulletmesh=CreateCone()
RotateMesh bulletmesh,90,0,0
ScaleEntity bulletmesh,1,.1,.1
EntityType bulletmesh, C_BULLET
EntityRadius bulletmesh, 0.01


If mouse1
	bullet.bullettyp New bullettype
	bullet\entityhandle = CopyEntity(bulletmesh)
	PositionEntity bullet\entityhandle, EntityX(playerattack, 1), EntityY(playerattack, 1), EntityZ(playerattack, 1)
	RotateEntity bullet\entityhandle, EntityPitch(playerattack, 1), EntityYaw(playerattack, 1), EntityRoll(playerattack,1)
	ResetEntity bullet\entityhandle
EndIf

For thisbullet.bullettype = Each bullettype
MoveEntity thisbullet\entityhandle, 0, 0, 2
If Abs(EntityX(thisbullet\entityhandle, 1)) > 10000
FreeEntity thisbullet\entityhandle
Delete thisbullet
ElseIf Abs(EntityZ(thisbullet\entityhandle, 1)) > 10000
FreeEntity thisbullet\entityhandle
Delete thisbullet
ElseIf Abs(EntityZ(thisbullet\entityhandle, 1)) > 10000
FreeEntity thisbullet\entityhandle
Delete thisbullet
EndIf
Next

;I'm using 2 pivots for camera controlling
;Pivot for the camera controlling
;One Front of the player,
FrontPivot=CreatePivot(plpivot)
PositionEntity Frontpivot,0,4,10

;One behind player
;This pivot controlls the collisions and "finds" the right position of the camera behind player
Backpivot=CreatePivot(plpivot)
EntityRadius Backpivot,1
EntityType BackPivot, C_PLAYER


Collisions C_PLAYER, C_LEVEL ,2,2
Collisions C_BULLET, C_ENEMY ,2,1
Collisions C_BULLET, C_LEVEL ,2,1
Collisions C_PLAYER, C_ENEMY ,1,2

; -------------
; Main loop
; -------------
FramePeriod = 1000 / AppFPS
FrameTime = MilliSecs () - FramePeriod
While Not KeyHit(1)
 
; --------------------------
	; Frame rate limiting
	; --------------------------
	Repeat
		FrameElapsed = MilliSecs () - FrameTime
	Until FrameElapsed

	FrameTicks = FrameElapsed / FramePeriod
	FrameTween# = Float (FrameElapsed Mod FramePeriod) / Float (FramePeriod)

	; -----------------------
	; Update tweening
	; -----------------------
	For FrameLimit = 1 To FrameTicks
		If FrameLimit = FrameTicks Then
			CaptureWorld
		EndIf
		FrameTime = FrameTime + FramePeriod
		
              UpdateCamera(plpivot,MouseXSpeed(),MouseYSpeed(), Frontpivot, Backpivot, Camera)
              UpdatePosition(plpivot)
              UpdateWorld
		
		;Possibly move below this next
		
		Next
		
For thisbullet = Each bullettype
If CountCollisions (thisbullet\entityhandle) > 0
enemyhit = EntityCollided(thisbullet\entityhandle, 3)
If enemyhit = EntityCollided(thisbullet\entityhandle, 3)
If enemyhit > 0 Then KillBadGuy(enemyhit)
FreeEntity thisbullet\entityhandle
Delete thisbullet
EndIf
Next
     
  RenderWorld FrameTween
  ; Crosshair
  Text screen_halfwidth%, screen_halfheight%, "+"

  Flip 0

Wend

End


Function updatecamera(ent,mxs#, mys#, pivot1, pivothatso, camera)
;ent : Player pivot
;mxs: MouseXmove
;mys: MouseYmove
;pivot1: pivot before player
;pivothatso: pivot behind player
;Camera: 

    MoveMouse screen_halfwidth%, screen_halfheight%
  
    ; Limit of the "look up", "look down"  
    If dest_xang + mys > 120 Or dest_xang + mys < -45 Then ;
        mys=0 
    EndIf


      dest_xang# = dest_xang + mys

      ; When the player looks up, the front pivot moves UP, when looks down the back pivot moves down
      TranslateEntity pivot1,0,-MYS#*.15,0
 
     angle#=  Sin(EntityPitch(camera))*6
      tempkkammag#=camheight + (angle*.8)
      tempkkamtav#=   camdist  + Abs( angle) 

      dest_yang# = dest_yang - (mxs*.5)
 
       RotateEntity ent, 0, dest_yang,0
     
        dx#=(EntityX(pivothatso,True)-EntityX(camera,True)) *.1
	dy#=(EntityY(pivothatso,True)-EntityY(camera,True)) *.9
	dz#=(EntityZ(pivothatso,True)-EntityZ(camera,True)) *.1
	
	TranslateEntity camera,dx,dy,dz
        PointEntity camera,pivot1
	PositionEntity pivothatso,0,0,0
	ResetEntity pivothatso

       	PositionEntity pivothatso,0,tempkkammag,tempkkamtav
End Function

;=========================FOG
myfogtex=CreateTexture(128,128,2 Or 48)
SetBuffer TextureBuffer(myfogtex)
LockBuffer()
For j=25 To 127
For i=25 To 127
trans=(j-48)*4
If trans<0 Then trans=0
If trans>255 Then trans=255
;WritePixelFast i,j, GetRGB(120,50,150) Or (trans Shl 24)
Next
Next
UnlockBuffer()
SetBuffer BackBuffer()

myfog=CreateCylinder(4,0,plpivot)
RotateMesh myfog,0,45,9
EntityAlpha myfog,0.1
EntityFX myfog,1
EntityTexture myfog,myfogtex
ScaleEntity myfog,50,25,50
FlipMesh myfog
Dim myfogb(10)
For i=0 To 3
myfogb(i)=CopyEntity(myfog,myfog)
scale#=1+(.1*Float(i))
ScaleEntity myfogb(i),scale#,scale#,scale#
EntityAlpha myfogb(i),.3*i
EntityParent myfogb(i),myfog
Next


Function UpdatePosition(ent)
;MOVEMENT
If pl_jump=0
  If KeyDown(200) Or KeyDown(17) Then 
	Move_For_Back=.3
  End If
  If KeyDown (208) Or KeyDown(31) Then
	Move_For_Back=-.2
  End If
  If KeyDown(203) Or KeyDown(30) Then 
      Move_Left_Right=-.2
  End If
  If KeyDown (205) Or KeyDown(32) Then
       Move_Left_Right=.2
  End If
EndIf

If KeyHit(18) Then
	which_one=which_one+1
	Select (which_one Mod 3)
		Case 0
			EntityAlpha player,1
			EntityAlpha playerattack,0
			EntityAlpha revolverman,0
		Case 1
			EntityAlpha playerattack,1
			EntityAlpha player,0
			EntityAlpha revolverman,0
		Case 2
			EntityAlpha revolverman,1
			EntityAlpha player,0
			EntityAlpha playerattack,0
			End Select
	EndIf

;If MouseHit(1) Then
;	which_one=which_one+1
;	Select (which_one Mod 2)
;		Case 0
;			EntityAlpha player,1
;			EntityAlpha playerattack,0
;		Case 1
;			EntityAlpha playerattack,1
;			EntityAlpha player,0
;			End Select
;	EndIf



If ( MouseHit(2)  Or KeyHit(57))  And pl_jump=0
     t.Timer = JumpTimer (1500)
    ;When jumps slides in the air doesn't stop quickly
     Move_Slow#=.999
     pl_jump=1
EndIf


If jump_timeout()=1
    pl_jump=0
   ;when goes stops quickly
    Move_Slow#=.1
EndIf

   MoveEntity ent, Move_Left_Right, Jump_Move, Move_For_Back
  TranslateEntity ent,0,pl_gravity,0

  ;Smooth movement
  move_left_right = move_left_right * move_slow
  move_for_back = move_for_back  * move_slow

End Function

Function JumpTimer.timer (timeOut)
	t.Timer = New Timer
	t\start   = MilliSecs ()
	t\timeOut = t\start + timeOut
        t\vel_start#=90
        t\vel_down#=-2
	Return t
End Function

; Check for timeout:
Function Jump_TimeOut ()
	For test.timer= Each timer
		If test\timeOut < MilliSecs ()
 		       Jump_move=0
			Delete test
			Return 1
	      Else
	           Jump_Move=Sin(test\vel_start#)
	            test\vel_start=test\vel_start#- test\vel_down#
        	   Return 0
       	EndIf
     Next		
End Function


Function CreateWorld()
;Light
light=CreateLight(1,town)
PositionEntity light ,0,150,0

light2=CreateLight(2)
PositionEntity light2,29.5,0,44.5

;Plan
plan=CreatePlane()
EntityColor plan,255,0,0
EntityType plan, C_LEVEL

Function KillBadGuy(enemyhit)
	For thisbadguy.badguytype = Each Badguytype
	If enemyhit = thisbadguy\entityhandle
		If thisbadguy\state <> 5
		thisbadguy\state = 5 ;dead
		EntityType thisbadguy\entityhandle, 0
		RotateEntity thisbadguy\entityhandle,90,0,0
		TranslateEntity thisbadguy\entityhandle, 0, -1, 0
		Exit
		EndIf
		EndIf
		Next
		Endfunction


The shooting code did not work because it wasn't in the main loop:
Type Timer
	Field start
	Field timeOut
	Field vel_start#;=90
	Field vel_down#;=-2
End Type

;System
Global AppFPS =45
Global screen_width% = 1024
Global screen_height% = 768
Global screen_halfwidth% = screen_width/2
Global screen_halfheight% = screen_height/2
Global camHeight#=4.5  ; default height of the camera behind player
Global camDist#=-7 ; default distance of the camera behind player
Global dest_xang# 
Global dest_yang# 
Global pl_gravity#=-.5
Global pl_jump=0
Global Jump_Move#=0
Global Move_For_Back#
Global Move_Left_Right#
Global Move_Slow#=.1
Global which_one=0
Global player
Global playerattack
Global revolverman
Global shotgun
Global revolver

;CONST
Const C_PLAYER=1, C_LEVEL=2, C_BULLET=3,C_ENEMY=4

AppTitle "Italia"

;Screen
Graphics3D screen_width,screen_height,32,3
SetBuffer BackBuffer()

CreateWorld()

;bullets
Type bullettype
	Field entityhandle
End Type

Global bullet.bullettype

Type badguytype
	Field entityhandle
	Field state
End Type

;CAMERA
camera =CreateCamera()
MoveEntity camera, 0, 5, -5

;Player Pivot
plpivot=CreatePivot()
EntityType plpivot, C_PLAYER
;EntityRadius plpivot,1.8,3
PositionEntity plpivot, 0, 3,0

;Player, now a cube but you can change for a nice model
;Player=CreateCube(plpivot)
;ScaleEntity player,1,3,.7
;MoveEntity player,0,1,0
;EntityColor Player,255,0,255


which_one = 0
player=LoadMesh("C:\Documents and Settings\Chad\Desktop\game\mobster\player.b3d",plpivot)
ScaleEntity player,.08,.08,.08
MoveEntity player,0,1,0

playerattack=LoadMesh("C:\Documents and Settings\Chad\Desktop\game\mobster\playerattack.b3d",plpivot)
ScaleEntity playerattack,.08,.08,.08
MoveEntity playerattack,0,1,0

revolverman=LoadMesh("C:\Documents and Settings\Chad\Desktop\game\mobster\revolverman.b3d",plpivot)
ScaleEntity revolverman,.08,.08,.08
MoveEntity revolverman,0,1,0

EntityAlpha player,1
EntityAlpha playerattack,0
EntityAlpha revolverman,0

;Bullet Mesh
bulletmesh=CreateCone()
RotateMesh bulletmesh,90,0,0
ScaleEntity bulletmesh,1,.1,.1
EntityType bulletmesh, C_BULLET
EntityRadius bulletmesh, 0.01

;I'm using 2 pivots for camera controlling
;Pivot for the camera controlling
;One Front of the player,
FrontPivot=CreatePivot(plpivot)
PositionEntity Frontpivot,0,4,10

;One behind player
;This pivot controlls the collisions and "finds" the right position of the camera behind player
Backpivot=CreatePivot(plpivot)
EntityRadius Backpivot,1
EntityType BackPivot, C_PLAYER


Collisions C_PLAYER, C_LEVEL ,2,2
Collisions C_BULLET, C_ENEMY ,2,1
Collisions C_BULLET, C_LEVEL ,2,1
Collisions C_PLAYER, C_ENEMY ,1,2

; -------------
; Main loop
; -------------
FramePeriod = 1000 / AppFPS
FrameTime = MilliSecs () - FramePeriod
While Not KeyHit(1)


mouse1 = MouseHit(1)
If mouse1 Then
	bullet.bullettype = New bullettype
	bullet\entityhandle = CopyEntity(bulletmesh)
	PositionEntity bullet\entityhandle, EntityX(camera), EntityY(camera), EntityZ(camera)
	RotateEntity bullet\entityhandle, EntityPitch(camera), EntityYaw(camera), EntityRoll(camera)
	ResetEntity bullet\entityhandle
EndIf

For thisbullet.bullettype = Each bullettype
MoveEntity thisbullet\entityhandle, 0, 0, 0.1
If Abs(EntityX(thisbullet\entityhandle, 1)) > 10000
FreeEntity thisbullet\entityhandle
Delete thisbullet
ElseIf Abs(EntityZ(thisbullet\entityhandle, 1)) > 10000
FreeEntity thisbullet\entityhandle
Delete thisbullet
ElseIf Abs(EntityZ(thisbullet\entityhandle, 1)) > 10000
FreeEntity thisbullet\entityhandle
Delete thisbullet
EndIf
Next

RenderWorld
Flip

Wend

End

While Not KeyHit(1)
 
	; --------------------------
	; Frame rate limiting
	; --------------------------
	Repeat
		FrameElapsed = MilliSecs () - FrameTime
	Until FrameElapsed

	FrameTicks = FrameElapsed / FramePeriod
	FrameTween# = Float (FrameElapsed Mod FramePeriod) / Float (FramePeriod)

	; -----------------------
	; Update tweening
	; -----------------------
	For FrameLimit = 1 To FrameTicks
		If FrameLimit = FrameTicks Then
			CaptureWorld
		EndIf
		FrameTime = FrameTime + FramePeriod
		
              UpdateCamera(plpivot,MouseXSpeed(),MouseYSpeed(), Frontpivot, Backpivot, Camera)
              UpdatePosition(plpivot)
              UpdateWorld
		
		;Possibly move below this next
		
		Next
		
;For thisbullet = Each bullettype
;If CountCollisions (thisbullet\entityhandle) > 0
;enemyhit = EntityCollided(thisbullet\entityhandle, 3)
;If enemyhit = EntityCollided(thisbullet\entityhandle, 3)
;If enemyhit > 0 Then KillBadGuy(enemyhit)
;FreeEntity thisbullet\entityhandle
;Delete thisbullet
;EndIf
;Next
     
  RenderWorld FrameTween
  ; Crosshair
  Text screen_halfwidth%, screen_halfheight%, "+"

  Flip

Wend

End


;=========================FOG
myfogtex=CreateTexture(128,128,2 Or 48)
SetBuffer TextureBuffer(myfogtex)
LockBuffer()
For j=25 To 127
For i=25 To 127
trans=(j-48)*4
If trans<0 Then trans=0
If trans>255 Then trans=255
;WritePixelFast i,j, GetRGB(120,50,150) Or (trans Shl 24)
Next
Next
UnlockBuffer()
SetBuffer BackBuffer()

myfog=CreateCylinder(4,0,plpivot)
RotateMesh myfog,0,45,9
EntityAlpha myfog,0.1
EntityFX myfog,1
EntityTexture myfog,myfogtex
ScaleEntity myfog,50,25,50
FlipMesh myfog
Dim myfogb(10)
For i=0 To 3
myfogb(i)=CopyEntity(myfog,myfog)
scale#=1+(.1*Float(i))
ScaleEntity myfogb(i),scale#,scale#,scale#
EntityAlpha myfogb(i),.3*i
EntityParent myfogb(i),myfog
Next


Function UpdatePosition(ent)
;MOVEMENT
If pl_jump=0
  If KeyDown(200) Or KeyDown(17) Then 
	Move_For_Back=.3
  End If
  If KeyDown (208) Or KeyDown(31) Then
	Move_For_Back=-.2
  End If
  If KeyDown(203) Or KeyDown(30) Then 
      Move_Left_Right=-.2
  End If
  If KeyDown (205) Or KeyDown(32) Then
       Move_Left_Right=.2
  End If
EndIf

If KeyHit(18) Then
	which_one=which_one+1
	Select (which_one Mod 3)
		Case 0
			EntityAlpha player,1
			EntityAlpha playerattack,0
			EntityAlpha revolverman,0
		Case 1
			EntityAlpha playerattack,1
			EntityAlpha player,0
			EntityAlpha revolverman,0
		Case 2
			EntityAlpha revolverman,1
			EntityAlpha player,0
			EntityAlpha playerattack,0
			End Select
	EndIf

;If MouseHit(1) Then
;	which_one=which_one+1
;	Select (which_one Mod 2)
;		Case 0
;			EntityAlpha player,1
;			EntityAlpha playerattack,0
;		Case 1
;			EntityAlpha playerattack,1
;			EntityAlpha player,0
;			End Select
;	EndIf



If ( MouseHit(2)  Or KeyHit(57))  And pl_jump=0
     t.Timer = JumpTimer (1500)
    ;When jumps slides in the air doesn't stop quickly
     Move_Slow#=.999
     pl_jump=1
EndIf


If jump_timeout()=1
    pl_jump=0
   ;when goes stops quickly
    Move_Slow#=.1
EndIf

   MoveEntity ent, Move_Left_Right, Jump_Move, Move_For_Back
  TranslateEntity ent,0,pl_gravity,0

  ;Smooth movement
  move_left_right = move_left_right * move_slow
  move_for_back = move_for_back  * move_slow

End Function

Function JumpTimer.timer (timeOut)
	t.Timer = New Timer
	t\start   = MilliSecs ()
	t\timeOut = t\start + timeOut
        t\vel_start#=90
        t\vel_down#=-2
	Return t
End Function

; Check for timeout:

Function CreateWorld()
;Light
light=CreateLight(1,town)
PositionEntity light ,0,150,0

light2=CreateLight(2)
PositionEntity light2,29.5,0,44.5

;Plan
plan=CreatePlane()
EntityColor plan,255,0,0
EntityType plan, C_LEVEL

End Function


Function KillBadGuy(enemyhit)
	For thisbadguy.badguytype = Each Badguytype
	If enemyhit = thisbadguy\entityhandle
		If thisbadguy\state <> 5
		thisbadguy\state = 5 ;dead
		EntityType thisbadguy\entityhandle, 0
		RotateEntity thisbadguy\entityhandle,90,0,0
		TranslateEntity thisbadguy\entityhandle, 0, -1, 0
		Exit
		EndIf
		EndIf
		Next
End Function


Function updatecamera(ent,mxs#, mys#, pivot1, pivothatso, camera)
;ent : Player pivot
;mxs: MouseXmove
;mys: MouseYmove
;pivot1: pivot before player
;pivothatso: pivot behind player
;Camera: 

    MoveMouse screen_halfwidth%, screen_halfheight%
  
    ; Limit of the "look up", "look down"  
    If dest_xang + mys > 120 Or dest_xang + mys < -45 Then ;
        mys=0 
    EndIf


      dest_xang# = dest_xang + mys

      ; When the player looks up, the front pivot moves UP, when looks down the back pivot moves down
      TranslateEntity pivot1,0,-MYS#*.15,0
 
     angle#=  Sin(EntityPitch(camera))*6
      tempkkammag#=camheight + (angle*.8)
      tempkkamtav#=   camdist  + Abs( angle) 

      dest_yang# = dest_yang - (mxs*.5)
 
       RotateEntity ent, 0, dest_yang,0
     
        dx#=(EntityX(pivothatso,True)-EntityX(camera,True)) *.1
	dy#=(EntityY(pivothatso,True)-EntityY(camera,True)) *.9
	dz#=(EntityZ(pivothatso,True)-EntityZ(camera,True)) *.1
	
	TranslateEntity camera,dx,dy,dz
        PointEntity camera,pivot1
	PositionEntity pivothatso,0,0,0
	ResetEntity pivothatso

       	PositionEntity pivothatso,0,tempkkammag,tempkkamtav
End Function



Function Jump_TimeOut ()
	For test.timer= Each timer
		If test\timeOut < MilliSecs ()
 		       Jump_move=0
			Delete test
			Return 1
	      Else
	           Jump_Move=Sin(test\vel_start#)
	            test\vel_start=test\vel_start#- test\vel_down#
        	   Return 0
       	EndIf
     Next		
End Function


Function LoadMesh(t$, parent = 0)

	Return CreateCube(parent)
	
End Function

A way to implement fog is to use the B3d fog commands.
These commands are used for that:
CameraFogRange camera, 5, 50 ;set fog range
CameraFogMode camera, 1 ;turn fog on
CameraFogColor camera, 255, 0, 0 ;color fog
CameraClsColor camera, 255, 0, 0 ;color backg

; ID: 559
; Author: jfk
; Date: 2003-01-25 20:37:32
; Title: Shoot'em
; Description: Simple FPS Shooting / Impact Example

; Simple FPS Shooting Example
Graphics3D 1024,768,16,2
SetBuffer BackBuffer()

Collisions 1,2,2,2
Collisions 2,1,1,1
Collisions 3,2,2,1 ; for bullets > enviroment check

player=CreatePivot()
PositionEntity player,-15,2,-30
EntityRadius player,.6
EntityType player,1

camera=CreateCamera( player )
CameraRange camera,.1,200
CameraClsColor camera,0,0,30
PositionEntity camera,0,1,0
TranslateEntity camera,0,2,0 ; eyes height

light=CreateLight()
LightColor light,32,32,32
TurnEntity light,45,45,0

light=CreateLight()
LightColor light,32,32,32
TurnEntity light,45,-45,0

;mesh=LoadMesh( "level.b3d" )

;------replace this block by the above Level-Loading ; probalby adjust scaling etc.
mesh=CreateCube(): ScaleEntity mesh,100,1,100
testtex=CreateTexture(128,128)
SetBuffer TextureBuffer(testtex)
For i=0 To 10000 ; draw 10001 dots on a texture created on the fly
  Color Rand(255),Rand(255),Rand(255) ; in random colors
  Plot 4+Rand(120),4+Rand(120)
Next
SetBuffer BackBuffer()
EntityTexture mesh,testtex
Dim fillers(10)
For i=0 To 10
  fillers(i)=CreateCube()
  EntityTexture fillers(i),testtex
  ScaleEntity fillers(i),Rand(20),Rand(100),Rand(20)
  PositionEntity fillers(i),Rand(-50,50),0,Rand(-50,50)
  EntityType fillers(i),2
Next
;------end block


EntityFX mesh,1
EntityType mesh,2

sp#=.5
ey#=EntityY(player)

; load mesh
;gun=LoadMesh("weapons-ammo/h-pistol-static.3ds")


;------replace this block by the above Gun-Loading
gun=CreateCube(camera):ScaleEntity gun,1,1,10
;---

;..PositionEntity gun,-14.5,2.3,-29.5 ; adjust these as you want
PositionEntity gun,.3,-.2,.5
RotateEntity gun,0,20,20

ScaleEntity gun,.15,.15,.5
EntityParent gun,camera
EntityRadius gun,1
EntityOrder gun,-1
;
;sky=LoadSkyBox( "grass" )
;EntityParent sky,camera

;create bullets
maxbull=100 ; max. number of bullets active
currbull=0
bulletspeed#=3.0
reload_after=30
Dim bullet(maxbull),bulljob(maxbull),mustset(maxbull) ; bullets array, bullet job flag array, collision reset flag array
For i=0 To maxbull
  bullet(i)=CreateCylinder() ; <<
  HideEntity bullet(i)
  EntityType bullet(i),3
  EntityRadius bullet(i),.05
  ScaleEntity bullet(i),.2,.2,.5
  RotateMesh bullet(i),90,0,0
Next
; so now we have bullet(0) to bullet(100) - these are 101 bullets

boom=CreateSphere() ; used as a impact mark
EntityAlpha boom,0.5

;make ammo
;pistolammo=LoadMesh("weapons-ammo/H-A_Shot-Static.3DS")
pistolammo=CreateCylinder() ; use yours

PositionEntity pistolammo,-0.5,2.5,-26.8

p_angle#=0 ; player angle
reloading=0
; ----------------------------------------MAINLOOP----------------------------------------
While Not KeyHit(1)
  
  If KeyHit(17)
    wire=1-wire
    WireFrame wire
  EndIf
  
  yv#=EntityY(player)-ey
  ey=EntityY(player)
  
  If KeyHit(57) Then yv=.1
  
  MoveEntity player,0,yv-.005,0 ; gravity
  
  p_angle#=(p_angle#-mxs#)  ; angle...
  If p_angle#>360 Then
    p_angle#=p_angle#-360
    p_smooth_angle#=p_smooth_angle#-360
  EndIf
  If p_angle#<0 Then
    p_angle#=p_angle#+360
    p_smooth_angle#=p_smooth_angle#+360
  EndIf
  
  c_angle#=(c_angle#+mys#)
  If c_angle#>360 Then
    c_angle#=c_angle#-360
    c_smooth_angle#=c_smooth_angle#-360
  EndIf
  If c_angle#<0 Then
    c_angle#=c_angle#+360
    c_smooth_angle#=c_smooth_angle#+360
  EndIf
  
  p_smooth_angle#=p_smooth_angle#-((p_smooth_angle#-p_angle#)/2.5)
  c_smooth_angle#=c_smooth_angle#-((c_smooth_angle#-c_angle#)/2.5)
  
  RotateEntity player,0,p_smooth_angle#,0
  RotateEntity camera,c_smooth_angle#,0,0
  
  If KeyDown(200) Then MoveEntity player,0,0,sp
  If KeyDown(208) Then MoveEntity player,0,0,-sp
  
  ; fire
  If MouseDown(1)=1 And MilliSecs()>=time_for_a_bullet
    time_for_a_bullet=MilliSecs()+133
    mag=mag+1
    If mag>=reload_after Then ; need to reload?
      time_for_a_bullet=MilliSecs()+1000 ; reload - no fire for 1 second
      mag=0
      reloading=1
    Else
      reloading=0
    EndIf
    ; launch bullet, probably play a gun sound
    EntityType bullet(currbull),0 ; force no collision to position at the guns xyz
    mustset(currbull)=1; remember this
    PositionEntity bullet(currbull),EntityX(gun,1),EntityY(gun,1),EntityZ(gun,1),1
    RotateEntity bullet(currbull),EntityPitch(gun,1),EntityYaw(gun,1),EntityRoll(gun,1),1
    MoveEntity bullet(currbull),0,0,-1.8
    ShowEntity bullet(currbull)
    bulljob(currbull)=1
    currbull=currbull+1
    If currbull>maxbull Then
      currbull=0
    EndIf
  EndIf
  If MilliSecs()>=time_for_a_bullet
    reloading=0 ; end reload phase anyway
  EndIf
  
  ; bullets in the air?
  For i=0 To maxbull
    If bulljob(i)<>0 ; is this bullet flying?
      If mustset(i)=1
        EntityType bullet(i),3 ; re-enable collison if required
        mustset(i)=0
      EndIf
      MoveEntity bullet(i),0,0,bulletspeed#
      If CountCollisions(bullet(i))>0
        hit_here=CollisionEntity(bullet(i),1) ; bullet hit wich entity?
        If hit_here<>0
          ; did you hit a lame multyplayer mesh? hit_here has its entity handle (that mesh needs EntityType 2)
          ; probalby play impact sound, start a particle  effect ...
          boomx#=CollisionX(bullet(i),1)
          boomy#=CollisionY(bullet(i),1)
          boomz#=CollisionZ(bullet(i),1)
          bulljob(i)=0 ; deactivate bullet
          EntityType bullet(i),0 ; collison off
          HideEntity bullet(i)
          ;impact happened Right here: (using a sphere to mark this point temporary - could be exlosion...)
          PositionEntity boom,boomx#,boomy#,boomz#,1
        EndIf
      EndIf
      If EntityDistance(bullet(i),gun)>100; bullet far away?
        HideEntity bullet(i)
        bulljob(i)=0 ; deactivate bullet
        EntityType bullet(i),0 ; collison off
      EndIf
    EndIf
  Next
  
  ;RotateEntity sky,0,0,0,True
  UpdateWorld
  RenderWorld
  Text 0,16,"Triangles Rendered:"+TrisRendered()
  Text 0,32,"Camera Position: "+EntityX(camera,1)+" "+EntityY(camera,1)+" "+EntityZ(camera,1)
  If reloading=1 Then Text GraphicsWidth()/2,GraphicsHeight()/2,"RELOADING",1,1
  mxs#=MouseXSpeed()/4.0
  mys#=MouseYSpeed()/4.0
  MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
  Flip
Wend
This is the example that helped me the best... JFK is a genius!!! I had to model my own crossbow and bolts and change quite a bit of code but whoa!!!

This is IN the Code archives...

Very nice, thanks Rook :-D