because I find it a bit confusing myself, I'll give you the code I use:
camera:
cx# = camera position x()
cy# = camera position y()
cz# = camera position z()
ca# = camera angle y()
`center and hide mouse
hide mouse
position mouse screen width() / 2, screen height() / 2
`crosshair
line screen width() / 2 - 5, screen height() / 2, screen width() / 2 + 5, screen height() / 2
line screen width() / 2, screen height() / 2 - 5, screen width() / 2, screen height() / 2 + 5
`forwards (w)
IF keystate( 17 ) = 1
cx# = newxvalue( cx#, ca#, spd# )
cz# = newzvalue( cz#, ca#, spd# )
position camera cx#, cy#, cz#
ENDIF
`backwards (s)
IF keystate(31)=1
cx#=newxvalue(cx#,wrapvalue(ca#-180),spd#)
cz#=newzvalue(cz#,wrapvalue(ca#-180),spd#)
position camera cx#,cy#,cz#
ENDIF
`left (a)
IF keystate(30)=1
cx#=newxvalue(cx#,wrapvalue(ca#-90),spd#)
cz#=newzvalue(cz#,wrapvalue(ca#-90),spd#)
position camera cx#,cy#,cz#
ENDIF
`right (d)
IF keystate(32)=1
cx#=newxvalue(cx#,wrapvalue(ca#+90),spd#)
cz#=newzvalue(cz#,wrapvalue(ca#+90),spd#)
position camera cx#,cy#,cz#
ENDIF
rem camera rotation
yrotate camera camera angle y() + mousemovex() * 0.3
xrotate camera camera angle x() + mousemovey() * 0.3
rem stops mouse from going upside down
IF wrapvalue( camera angle x( 0 ) ) > 80 AND wrapvalue( camera angle x( 0 ) ) < 180 THEN xrotate camera 0, 80
IF wrapvalue( camera angle x( 0 ) ) > 180 AND wrapvalue( camera angle x( 0 ) ) < 280 THEN xrotate camera 0, 280
RETURN
Make sure you define "spd#"
.