I took the tempest plugin, and a space flight engine that I modified for my uses...yet i seem to be having some problems I just can't figure out. I've searched these forums for tips, and worked for days on this...i'm finally to the point to where i think i need to ask for help(my wife is giving me hell for spending so much time on it). I'm basically creating a MP space flight battle sim, and I feel i've made some progress, but i'm stuck in a couple places...here are my questions....
1) a radar box, I know i can use an overhead cam...but not sure how to create a small split screen in the corner to do it.
2) I am trying to get chat to working. I notice the messages flash to the players, but since it's in the middle of a loop, it's not time enough to read the message. I'm afraid to use any type of wait function because I dont want to slow the loop down. So the problem is that the messages dont stay on the screen long enough. (look for the message$ variable)
3) I can't see the other ships. I tested many simplified examples, yet the tfloat doesn't seem to be shared with the other players on the network. I've had it working with the MP script examples and even my own simplified scripts...but for some reason i'm having a hard time getting this to work. Not sure if i should do something with object 10 or not....i'm focusing on OURID. This part he really giving me a headache, though i'm sure it lies somewhere in the network function at the bottom of the script. HELP!
Anyway, i'm sure if i can figure these details out, i can figure out how to broadcast bullets, explosions, etc in MP...but until i get these problems fixed, i'm kinda at a standstill. I've already worked out a may/ship plug and play system using raw files(not included in this script), i've put alot of work into this. Any help would be appreciated, thanks in advance.
Here is my code....
remstart
set display mode 1024,768,16
autocam off
hide mouse
sync on
sync rate 60
backdrop on
remend
`Constants --------------------------------
#constant MAXPLAYERS 9
#constant SENDGAP 100
`------------------------------------------
camera_style = 1
`Types ------------------------------------
type playerstates
keyup as boolean
keydown as boolean
endtype
`------------------------------------------
`Data -------------------------------------
global OURID as integer
global LASTSENT as integer
global ywrap as float
global xwrap as float
global zwrap as float
global z# as float
global yA# as float
global x# as float
dim playerdata(MAXPLAYERS) as playerstates
`------------------------------------------
`Ask for choice of mode
print "1. Host"
print "2. Join"
Input "Choice: ", choice
`If no choice then quit
if choice=0 then end
`If choice is 1 then host a multiplayer game
if choice=1
`Ask for username
input "Nickname: ", nick$
`If either variable is empty, set a default
if nick$="" then nick$ = "Host"
`Host the multiplayer game
result = THost("", MAXPLAYERS, nick$)
`If hosting failed then report to user and quit
if not result
print "Failed to host game"
wait key
end
endif
`-----------------------------------------------
`Set our game information for people searching
`for games.
`
`The parameters are as follow:
`gameName$, gameType$, gameMap$, timeLeft
`(timeLeft is specified in milliseconds.)
`
`Custom parameters are planned.
TRegisterGame "Banana Snipers", "Team Deathmatch", "Dessert", 60*10
`-----------------------------------------------
endif
`If choice is 1 then join
if choice=2
`Ask for username
input "Nickname: ", nick$
`If variable is empty, set a default
if nick$="" then nick$ = "Client"
`Search for games on the LAN
TGetGameList
gameAmount = TGetGameAmount()
print "There are currently "+str$(gameAmount)+" games running."
print
`Display games ---------------------------------
`To get game information you use TGetGameData. The
`first parameter is the game number, the second
`parameter is the type of data you want to get.
`
`0 = Game name
`1 = Game type
`2 = Game map
`3 = Time left
`
`This function returns string data always, so if
`you want to use a value returned then you must
`first convert it to an integer using val().
for x=1 to gameAmount
gameName$ = TGetGameData(x, 0)
gameType$ = TGetGameData(x, 1)
gameMap$ = TGetGameData(x, 2)
gameTime$ = TGetGameData(x, 3)
print gameName$+" "+gameType$+" "+gameMap$+" "+gametime$
next x
`-----------------------------------------------
print
`Ask user which game they want to join
input "Enter game number to join: ", gameNum
if gameNum=0 then end
`Join the multiplayer game ---------------------
`This is another TJoin variation that lets you
`use a game number obtained from the games list.
result = TJoin(gameNum, nick$)
`-----------------------------------------------
`If joining failed then report to user and quit
if not result
print "Failed to join game"
wait key
end
endif
endif
`Retrieve our ID in the game and store it
OURID = TGetThisID()
set display mode 1024,768,16
autocam off
hide mouse
sync on
sync rate 60
backdrop on
`---------- CAMERA
camera_style = 1
`skybox
set camera range 2.5,50000
load object "sky/cielo.x",666
`position object 666,256,30,0
set object texture 666,2,1
set object light 666,0
set object cull 666,0
yrotate object 666,270
scale object 666,95000,95000,95000
set object collision off 666
`---------- SET LIGHTS
set ambient light 1
make light 1
position light 1,0,0,0
color light 1,255,0,0
set light range 1,600000
make light 2
position light 2,40000,0,40000
color light 2,255,255,255
set light range 2,300000
make light 3
color light 3,255,255,255
set light range 3,10000
set normalization on
`---------- CREATE PLAYER
`movement object (invicible)
make object cone 10,25
position object 10,50000,10000,50000
xrotate object 10,90
fix object pivot 10
hide object 10
`player object
`make object box 15,50,20,5
for x=1 to 9
load object "player/ship_1.x",x
xrotate object x,-90
scale object x,400,400,400
rem glue object to limb x, 10, 0
if not TPlayerExist(x) then hide object x
load image "player/spheremap.jpg",15
next x
glue object to limb OURID, 10, 0
load image "player/spheremap.jpg",15
set sphere mapping on OURID,15
`visor object
load image "player/visor_red.bmp",20
load image "player/visor.bmp",21
make object plain 20,50,50
texture object 20,20
set object light 20,0
ghost object on 20
fade object 20,50
xrotate object 20,90
glue object to limb 20, 10, 0
move object 20,-800
disable object zdepth 20
`visor ray object
make object box 21,5,5,5000
ghost object on 21
fade object 21,0
glue object to limb 21,OURID,0
move object 21,2500
`vars
speed# = 30
speed_max# = 30
speed_min# = 10
speed_chg# = 1
plyr_bank# = 0
plyr_turn# = 0
`---------- CREATE STANDARD BULLETS
load sound "player/fire.wav", 12
bullet_count = 1000
bullet_max = 1020
bullet_times = 0
bullet_timee = 10
dim bullet_life(2000)
bullet_end = 100
bullet_speed = 50
load image "player/bullet.jpg",1000
for a = 1000 to bullet_max
make object sphere a,40
`make object plain a,50,50
texture object a,1000
set object light a,0
ghost object on a
fade object a,100
hide object a
bullet_life(a) = 0
position object a,0,999999,0
next a
`----------- PREPARE EXPLOSIONS
dim shockwave_scale(520)
dim shockwave_fade(520)
shockwave_count = 500
load image "asteroids/shockwave.bmp",500
load sound "asteroids/hit.wav", 13
for a = 500 to 520
make object plain a,500,500
texture object a,500
ghost object on a
fade object a,200
hide object a
shockwave_scale(a) = 100
shockwave_fade(a) = 120
set object light a,1
`disable object zdepth a
next a
`LOAD LEVEL
nmi_count = 2000
dim nmi_status(3000)
dim nmi_rndx#(3000)
dim nmi_rndy#(3000)
dim nmi_rndz#(3000)
gosub LEVEL1
rem begin loop
do
`Show who is online
for x=1 to MAXPLAYERS
if TPlayerExist(x)
text 0, x*13, TGetPlayername(x)+"("+str$(x)+") is connected."
endif
next x
set cursor 0,0
rem HandleControls()
mx# = mousemovex()
my# = mousemovey()
mz# = mousemovez()
px# = object position x(10)
py# = object position y(10)
pz# = object position z(10)
rem SPEED control
if mz# > 0 then inc speed#,speed_chg#
if mz# < 0 then dec speed#,speed_chg#
if speed# > speed_max# then speed# = speed_max#
if speed# < speed_min# then speed# = speed_min#
move object 10,speed#
`LEFT/RIGHT
if mx# < 0 then plyr_turn# = curvevalue(-2, plyr_turn#, 10)
if mx# > 0 then plyr_turn# = curvevalue(2, plyr_turn#, 10)
if mx# = 0 then plyr_turn# = curvevalue(0, plyr_turn#, 10)
ywrap=wrapvalue(object angle y(10)+plyr_turn#)
yrotate object 10,wrapvalue(object angle y(10)+plyr_turn#)
`UP/DOWN
if my# < 0 then plyr_tilt# = curvevalue(1, plyr_tilt#, 20)
if my# > 0 then plyr_tilt# = curvevalue(-1, plyr_tilt#, 20)
if my# = 0 then plyr_tilt# = curvevalue(0, plyr_tilt#, 10)
xwrap=wrapvalue(object angle x(10)+plyr_tilt#)
xrotate object 10,wrapvalue(object angle x(10)+plyr_tilt#)
`SMOOTH BANKING
if mx# < 0 then plyr_bank# = curvevalue(50, plyr_bank#, 25)
if mx# > 0 then plyr_bank# = curvevalue(-50, plyr_bank#, 25)
if mx# = 0 then plyr_bank# = curvevalue(0, plyr_bank#, 25)
ywrap=plyr_bank#
yrotate object OURID,plyr_bank#
`1 - FOLLOW
if camera_style = 1
set camera to object orientation 10
position camera px#, py#+50, pz#
move camera -100
endif
`VISOR ON/OFF
hit = object collision(21,0)
if hit > 2000
texture object 20,21
else
texture object 20,20
endif
rem print hit
`SHOOT STANDARD BULLETS
if mouseclick() = 1
rem play sound 12
inc bullet_times
if bullet_times > bullet_timee
bullet_times = 0
inc bullet_count
if bullet_count > bullet_max then bullet_count = 1000
if object visible(bullet_count) = 0
position object bullet_count, px#, py#, pz#
point object bullet_count, limb position x(20,0), limb position y(20,0), limb position z(20,0)
show object bullet_count
endif
endif
endif
for a = 1000 to bullet_max
if object visible(a) = 1
move object a,bullet_speed
inc bullet_life(a)
`print bullet_life(a)
`CHECK FOR BULLET HIT
hit = object collision(a,0)
if hit > 2000
play sound 13
hide object hit
position object a,0,-999999,0
for b = 500 to 520
print str$(b)+" - "+str$(shockwave_scale(b))
if shockwave_scale(b) = 100
position object b,object position x(hit),object position y(hit),object position z(hit)
point object b,px#,py#,pz#
rotate object b,object angle x(b)+(-30+rnd(60)),object angle y(b)+(-30+rnd(60)),object angle z(b)+(-30+rnd(60))
show object b
position light 3,camera position x(),camera position y(),camera position z()
inc shockwave_scale(b)
exit
endif
next b
position object hit,0,999999,0
endif
endif
if bullet_life(a) > bullet_end then hide object a : bullet_life(a) = 0
next a
`---------- EXPLOSIONS!!!
`SHOCKWAVE
for b = 500 to 520
if shockwave_scale(b) > 100
scale object b, shockwave_scale(b), shockwave_scale(b), 100
inc shockwave_scale(b),15
fade object b,shockwave_fade(b)
dec shockwave_fade(b),1
roll object left b,0.5
if shockwave_fade(b) <= 0
shockwave_scale(b) = 100
shockwave_fade(b) = 120
hide object b
position light 3,0,0,0
endif
endif
next b
`SET SKYBOX POSITION
position object 666,camera position x(),camera position y(),camera position z()
gosub NMI_CONTROL
if shiftkey()=1 then gosub chat
if tgetmessage()=>1
message$=tgetstring()
sender=tgetsender()
text 0,50,message$
endif
tsync
sync
loop
`---------- SETUP LEVEL 1
LEVEL1:
`Debree
`ASTEROIDS
load image "asteroids/AST4.BMP",1999
load object "asteroids/asteroid_1.x",1996 : texture object 1996,1999
load object "asteroids/asteroid_2.x",1997 : texture object 1997,1999
load object "asteroids/asteroid_3.x",1998 : texture object 1998,1999
load object "asteroids/asteroid_4.x",1999 : texture object 1999,1999
for a = 2000 to 2250
clone object a,rnd(2)+1996
tmp_size = rnd(700)+300
scale object a,tmp_size,tmp_size,tmp_size
position object a,rnd(100000),rnd(20000),rnd(100000)
nmi_status(a) = 1
nmi_rndx#(a) = (-5+(rnd(9)+1))/5.0
nmi_rndy#(a) = (-5+(rnd(9)+1))/5.0
nmi_rndz#(a) = (-5+(rnd(9)+1))/5.0
next a
return
`---------- ENEMIE CONTROL
NMI_CONTROL:
`DEBREE
for a = 2000 to 2100
if nmi_status(a) = 1
rotate object a,wrapvalue(object angle x(a)+nmi_rndx#(a)),wrapvalue(object angle y(a)+nmi_rndy#(a)),wrapvalue(object angle z(a)+nmi_rndz#(a))
endif
next a
return
rem MP FUNCTIONS
function HandleMovement()
for x=1 to MAXPLAYERS
if OURID<>x and object exist(x)
if playerdata(x).keyup then move object x, 1
if playerdata(x).keydown then move object x, -1
endif
next x
endfunction
function HandleControls()
mx# = mousemovex()
my# = mousemovey()
mz# = mousemovez()
px# = object position x(10)
py# = object position y(10)
pz# = object position z(10)
rem SPEED control
if mz# > 0 then inc speed#,speed_chg#
if mz# < 0 then dec speed#,speed_chg#
if speed# > speed_max# then speed# = speed_max#
if speed# < speed_min# then speed# = speed_min#
move object 10,speed#
`LEFT/RIGHT
if mx# < 0 then plyr_turn# = curvevalue(-2, plyr_turn#, 10)
if mx# > 0 then plyr_turn# = curvevalue(2, plyr_turn#, 10)
if mx# = 0 then plyr_turn# = curvevalue(0, plyr_turn#, 10)
yrotate object 10,wrapvalue(object angle y(10)+plyr_turn#)
`UP/DOWN
if my# < 0 then plyr_tilt# = curvevalue(1, plyr_tilt#, 20)
if my# > 0 then plyr_tilt# = curvevalue(-1, plyr_tilt#, 20)
if my# = 0 then plyr_tilt# = curvevalue(0, plyr_tilt#, 10)
xrotate object 10,wrapvalue(object angle x(10)+plyr_tilt#)
`SMOOTH BANKING
if mx# < 0 then plyr_bank# = curvevalue(50, plyr_bank#, 25)
if mx# > 0 then plyr_bank# = curvevalue(-50, plyr_bank#, 25)
if mx# = 0 then plyr_bank# = curvevalue(0, plyr_bank#, 25)
yrotate object OURID,plyr_bank#
`1 - FOLLOW
if camera_style = 1
set camera to object orientation 10
position camera px#, py#+50, pz#
move camera -100
endif
remstart
if upkey() then move object OURID, 1
if downkey() then move object OURID, -1
if leftkey() then dec PLAYER_ANGLE_Y
if rightkey() then inc PLAYER_ANGLE_Y
yrotate object OURID, PLAYER_ANGLE_Y
remend
`This shows how the host can boot a player
if spacekey()
TKillPlayer 2
repeat : until not spacekey()
endif
`This shows how to disconnect
if shiftkey()
TDisconnect
repeat : until not shiftkey()
endif
endfunction
function HandleCamera()
xPos# = cos(270-PLAYER_ANGLE_Y) * 50 + object position x(OURID)
zPos# = sin(270-PLAYER_ANGLE_Y) * 50 + object position z(OURID)
position camera xPos#, 30, zPos#
point camera object position x(OURID), 5, object position z(OURID)
endfunction
function HandleNetwork()
`Player states
newPlayer = TNewPlayer()
if newPlayer>0
show object newPlayer
text 0, 70, "Player ID "+str$(newplayer)+ " has entered the game."
endif
`Send
if LASTSENT+SENDGAP<timer()
TPutFloat object position x(OURID)
TPutFloat object position z(OURID)
TPutFloat object position y(OURID)
rem TPutByte upkey()
rem TPutByte downkey()
TSendAll
LASTSENT = timer()
endif
`Receive
repeat
newMsg = TGetMessage()
if newMsg
from = TGetSender()
x# = TGetFloat()
z# = TGetFloat()
yA# = TGetFloat()
rem playerdata(from).keyup = TGetByte()
rem playerdata(from).keydown = TGetByte()
rem XVAL = x#
rem ZVAL = z#
rem YVAL = yA#
if object exist(from)
position object from, x#, yA#, z#
yrotate object from, yA#
zrotate object from, z#
xrotate object from, x#
endif
endif
until not newMsg
endfunction
chat:
input "Chat} ", chat$
tputstring chat$
tsendall
return