player game modes settable with /gmode; spec not really ready yet

This commit is contained in:
Ben Russell (300178622) 2013-02-01 21:30:12 +13:00
parent b74c9a4127
commit d3c20a1edc
6 changed files with 122 additions and 56 deletions

View File

@ -136,13 +136,18 @@ Iceball Base Mod:
note, for C->S pid MUST be 0x00 note, for C->S pid MUST be 0x00
0x05 pid team weapon score.s16 kills.s16 deaths.s16 name.z squad.z: (S->C) @ 0x05 pid team weapon mode score.s16 kills.s16 deaths.s16 name.z squad.z: (S->C) @
adds player to server adds player to server
note, this can be used to update a player on the server note, this can be used to update a player on the server
"weapon" can be one of these: "weapon" can be one of these:
1: rifle 1: rifle
"mode" can be one of these:
1: normal player
2: map editor
3: spectator
yeah that's it really. yeah that's it really.
@ -283,4 +288,4 @@ Iceball Base Mod:
send squadchat message send squadchat message
0x1F team score.u16 (S->C) @ 0x1F team score.u16 (S->C) @
update team scores update team scores

View File

@ -520,16 +520,17 @@ function h_tick_main(sec_current, sec_delta)
plr.set_orient_recv(ya, xa, keys) plr.set_orient_recv(ya, xa, keys)
end end
elseif cid == 0x05 then elseif cid == 0x05 then
-- 0x05 pid team weapon score.s16 kills.s16 deaths.s16 name.z squad.z: (S->C) -- 0x05 pid team weapon mode score.s16 kills.s16 deaths.s16 name.z squad.z: (S->C)
local pid, tidx, wpn, score, kills, deaths, name, squad local pid, tidx, wpn, mode, score, kills, deaths, name, squad
pid, tidx, wpn, score, kills, deaths, name, squad, pkt pid, tidx, wpn, mode, score, kills, deaths, name, squad, pkt
= common.net_unpack("Bbbhhhzz", pkt) = common.net_unpack("Bbbbhhhzz", pkt)
if players[pid] then if players[pid] then
-- TODO: update wpn/name -- TODO: update wpn/name
players[pid].squad = (squad ~= "" and squad) or nil players[pid].squad = (squad ~= "" and squad) or nil
players[pid].name = name players[pid].name = name
players[pid].team = tidx players[pid].team = tidx
players[pid].mode = mode
players[pid].recolor_team() players[pid].recolor_team()
else else
players[pid] = new_player({ players[pid] = new_player({
@ -539,6 +540,7 @@ function h_tick_main(sec_current, sec_delta)
squad = (squad ~= "" and squad) or nil, squad = (squad ~= "" and squad) or nil,
team = tidx, team = tidx,
weapon = wpn, weapon = wpn,
mode = mode,
pid = pid, pid = pid,
}) })
end end

View File

@ -126,6 +126,23 @@ command_register({
end end
}) })
command_register({
command = "gmode",
permission = "gmode",
usage = "/gmode #; where 1=normal, 2=editor, 3=spectate",
func = function(plr, plrid, sockfd, prms, msg)
if table.getn(prms) == 1 then
local n = math.floor(tonumber(prms[1]))
if n >= 1 and n <= 3 then
plr.mode = n
plr.update_score()
end
else
commands.help.func(plr, plrid, sockfd, {"gmode"})
end
end
})
command_register({ command_register({
command = "teleport", command = "teleport",
permission = "teleport", permission = "teleport",

View File

@ -213,7 +213,9 @@ function server.hook_tick(sec_current, sec_delta)
if x >= 0 and x < xlen and z >= 0 and z < zlen then if x >= 0 and x < xlen and z >= 0 and z < zlen then
if y >= 0 and y <= ylen-3 then if y >= 0 and y <= ylen-3 then
if plr.blocks > 0 and map_is_buildable(x,y,z) then if plr.blocks > 0 and map_is_buildable(x,y,z) then
plr.blocks = plr.blocks - 1 if plr.mode == PLM_NORMAL then
plr.blocks = plr.blocks - 1
end
map_block_set(x,y,z,ct,cr,cg,cb) map_block_set(x,y,z,ct,cr,cg,cb)
net_broadcast(nil, common.net_pack("BHHHBBBB", net_broadcast(nil, common.net_pack("BHHHBBBB",
0x08,x,y,z,cb,cg,cr,ct)) 0x08,x,y,z,cb,cg,cr,ct))
@ -326,9 +328,9 @@ function server.hook_tick(sec_current, sec_delta)
name = (name ~= "" and name) or name_generate() name = (name ~= "" and name) or name_generate()
plr.set_health_damage(0, 0xFF800000, plr.name.." changed teams", nil) plr.set_health_damage(0, 0xFF800000, plr.name.." changed teams", nil)
plr.team = tidx plr.team = tidx
net_broadcast(nil, common.net_pack("BBBBhhhzz", net_broadcast(nil, common.net_pack("BBBBBhhhzz",
0x05, plr.pid, 0x05, plr.pid,
plr.team, plr.weapon, plr.team, plr.weapon, plr.mode,
plr.score, plr.kills, plr.deaths, plr.score, plr.kills, plr.deaths,
plr.name, plr.squad)) plr.name, plr.squad))
net_broadcast(nil, common.net_pack("BIz", 0x0E, 0xFF800000, net_broadcast(nil, common.net_pack("BIz", 0x0E, 0xFF800000,
@ -350,9 +352,9 @@ function server.hook_tick(sec_current, sec_delta)
for i=1,players.max do for i=1,players.max do
local plr = players[i] local plr = players[i]
if plr then if plr then
common.net_send(sockfd, common.net_pack("BBBBhhhzz", common.net_send(sockfd, common.net_pack("BBBBBhhhzz",
0x05, i, 0x05, i,
plr.team, plr.weapon, plr.team, plr.weapon, plr.mode,
plr.score, plr.kills, plr.deaths, plr.score, plr.kills, plr.deaths,
plr.name, plr.squad)) plr.name, plr.squad))
common.net_send(sockfd, common.net_pack("BBfffBB", common.net_send(sockfd, common.net_pack("BBfffBB",
@ -387,9 +389,9 @@ function server.hook_tick(sec_current, sec_delta)
end end
-- relay this player to everyone -- relay this player to everyone
net_broadcast(nil, common.net_pack("BBBBhhhzz", net_broadcast(nil, common.net_pack("BBBBBhhhzz",
0x05, cli.plrid, 0x05, cli.plrid,
plr.team, plr.weapon, plr.team, plr.weapon, plr.mode,
plr.score, plr.kills, plr.deaths, plr.score, plr.kills, plr.deaths,
plr.name, plr.squad)) plr.name, plr.squad))
net_broadcast(nil, common.net_pack("BBfffBB", net_broadcast(nil, common.net_pack("BBfffBB",
@ -443,7 +445,9 @@ function server.hook_tick(sec_current, sec_delta)
, 0x18, cli.plrid, cr, cg, cb)) , 0x18, cli.plrid, cr, cg, cb))
end end
elseif cid == 0x1B and plr and plr.grenades > 0 then elseif cid == 0x1B and plr and plr.grenades > 0 then
plr.grenades = plr.grenades - 1 if plr.mode == PLM_NORMAL then
plr.grenades = plr.grenades - 1
end
local x,y,z,vx,vy,vz,fuse local x,y,z,vx,vy,vz,fuse
x,y,z,vx,vy,vz,fuse, pkt = common.net_unpack("hhhhhhH", pkt) x,y,z,vx,vy,vz,fuse, pkt = common.net_unpack("hhhhhhH", pkt)
local n = new_nade({ local n = new_nade({

View File

@ -15,6 +15,10 @@
along with Ice Lua Components. If not, see <http://www.gnu.org/licenses/>. along with Ice Lua Components. If not, see <http://www.gnu.org/licenses/>.
]] ]]
PLM_NORMAL = 1
PLM_SPECTATE = 2
PLM_EDITOR = 3
function new_player(settings) function new_player(settings)
local this = {} this.this = this this.this.this = this this = this.this local this = {} this.this = this this.this.this = this this = this.this
@ -25,6 +29,7 @@ function new_player(settings)
this.alive = false this.alive = false
this.spawned = false this.spawned = false
this.zooming = false this.zooming = false
this.mode = settings.mode or PLM_NORMAL
this.mdl_block = common.model_new(1) this.mdl_block = common.model_new(1)
this.mdl_block = common.model_bone_new(this.mdl_block) this.mdl_block = common.model_bone_new(this.mdl_block)
@ -325,9 +330,9 @@ function new_player(settings)
end end
function this.update_score() function this.update_score()
net_broadcast(nil, common.net_pack("BBBBhhhzz", net_broadcast(nil, common.net_pack("BBBBBhhhzz",
0x05, this.pid, 0x05, this.pid,
this.team, this.weapon, this.team, this.weapon, this.mode,
this.score, this.kills, this.deaths, this.score, this.kills, this.deaths,
this.name, this.squad)) this.name, this.squad))
end end
@ -379,6 +384,10 @@ function new_player(settings)
end end
function this.damage(amt, kcol, kmsg, enemy) function this.damage(amt, kcol, kmsg, enemy)
if this.mode ~= PLM_NORMAL then
return nil
end
return this.set_health_damage( return this.set_health_damage(
this.health - amt, kcol, kmsg, enemy) this.health - amt, kcol, kmsg, enemy)
end end
@ -443,6 +452,9 @@ function new_player(settings)
end end
function this.grenade_damage(amt, enemy) function this.grenade_damage(amt, enemy)
if enemy.mode ~= PLM_NORMAL then
return nil
end
--print("damage",this.name,part,amt) --print("damage",this.name,part,amt)
local midmsg = " grenaded " local midmsg = " grenaded "
if this.team == enemy.team and this ~= enemy then if this.team == enemy.team and this ~= enemy then
@ -466,7 +478,7 @@ function new_player(settings)
end end
function this.intel_pickup(intel) function this.intel_pickup(intel)
if this.has_intel or intel.team == this.team then if this.mode ~= PLM_NORMAL or this.has_intel or intel.team == this.team then
return false return false
end end
@ -685,7 +697,7 @@ function new_player(settings)
this.dangx = (nax - this.angx) this.dangx = (nax - this.angx)
-- apply delta angles -- apply delta angles
if MODE_DRUNKCAM_LOCALTURN and this.dangy ~= 0 then if (this.mode ~= PLM_NORMAL or MODE_DRUNKCAM_LOCALTURN) and this.dangy ~= 0 then
this.angx = this.angx + this.dangx this.angx = this.angx + this.dangx
local fx,fy,fz -- forward local fx,fy,fz -- forward
@ -754,7 +766,7 @@ function new_player(settings)
fwx,fwy,fwz = sya*cxa, sxa, cya*cxa fwx,fwy,fwz = sya*cxa, sxa, cya*cxa
if client and this.alive and (not this.t_switch) then if client and this.alive and (not this.t_switch) then
if this.ev_lmb then if this.ev_lmb and this.mode ~= PLM_SPECTATE then
if this.tool == TOOL_BLOCK and this.blx1 then if this.tool == TOOL_BLOCK and this.blx1 then
if (not this.t_newblock) and this.blocks > 0 then if (not this.t_newblock) and this.blocks > 0 then
if this.blx1 >= 0 and this.blx1 < xlen and this.blz1 >= 0 and this.blz1 < zlen then if this.blx1 >= 0 and this.blx1 < xlen and this.blz1 >= 0 and this.blz1 < zlen then
@ -766,7 +778,9 @@ function new_player(settings)
this.blk_color[2], this.blk_color[2],
this.blk_color[1], this.blk_color[1],
1)) 1))
this.blocks = this.blocks - 1 if this.mode == PLM_NORMAL then
this.blocks = this.blocks - 1
end
this.t_newblock = sec_current + MODE_DELAY_BLOCK_BUILD this.t_newblock = sec_current + MODE_DELAY_BLOCK_BUILD
this.t_switch = this.t_newblock this.t_switch = this.t_newblock
end end
@ -776,7 +790,7 @@ function new_player(settings)
if (not this.t_newspade1) then if (not this.t_newspade1) then
-- see if there's anyone we can kill -- see if there's anyone we can kill
local d = this.bld2 or 5 -- NOTE: cannot spade through walls anymore. Sorry guys :/ local d = this.bld2 or 4 -- NOTE: cannot spade through walls anymore. Sorry guys :/
local hurt_idx = nil local hurt_idx = nil
local hurt_part = nil local hurt_part = nil
local hurt_part_idx = 0 local hurt_part_idx = 0
@ -829,14 +843,16 @@ function new_player(settings)
elseif this.tool == TOOL_NADE then elseif this.tool == TOOL_NADE then
if (not this.t_newnade) and this.grenades > 0 then if (not this.t_newnade) and this.grenades > 0 then
if (not this.t_nadeboom) then if (not this.t_nadeboom) then
this.grenades = this.grenades - 1 if this.mode == PLM_NORMAL then
this.grenades = this.grenades - 1
end
this.t_nadeboom = sec_current + MODE_NADE_FUSE this.t_nadeboom = sec_current + MODE_NADE_FUSE
end end
end end
else else
end end
elseif this.ev_rmb then elseif this.mode ~= PLM_SPECTATE and this.ev_rmb then
if this.tool == TOOL_BLOCK and this.blx3 and this.alive then if this.tool == TOOL_BLOCK and this.blx3 and this.alive then
local ct,cr,cg,cb local ct,cr,cg,cb
ct,cr,cg,cb = map_block_pick(this.blx3, this.bly3, this.blz3) ct,cr,cg,cb = map_block_pick(this.blx3, this.bly3, this.blz3)
@ -874,28 +890,38 @@ function new_player(settings)
mvx = mvx - 1.0 mvx = mvx - 1.0
end end
if this.ev_crouch then if this.mode == PLM_NORMAL then
if this.grounded and not this.crouching then if this.ev_crouch then
if MODE_SOFTCROUCH then this.jerkoffs = this.jerkoffs - 1 end if this.grounded and not this.crouching then
this.y = this.y + 1 if MODE_SOFTCROUCH then this.jerkoffs = this.jerkoffs - 1 end
this.y = this.y + 1
end
this.crouching = true
end end
this.crouching = true if this.ev_jump and this.alive and (MODE_CHEAT_FLY or this.grounded) then
end this.vy = -7
if this.ev_jump and this.alive and (MODE_CHEAT_FLY or this.grounded) then this.ev_jump = false
this.vy = -7 if client then
this.ev_jump = false client.wav_play_global(wav_jump_up, this.x, this.y, this.z)
if client then end
client.wav_play_global(wav_jump_up, this.x, this.y, this.z) end
else
if this.ev_crouch then
mvy = mvy + 1.0
end
if this.ev_jump then
mvy = mvy - 1.0
end end
end end
-- normalise mvx,mvz -- normalise mvx,mvy,mvz
local mvd = math.max(0.00001,math.sqrt(mvx*mvx + mvz*mvz)) local mvd = math.max(0.00001,math.sqrt(mvx*mvx + mvy*mvy + mvz*mvz))
mvx = mvx / mvd mvx = mvx / mvd
mvy = mvy / mvd
mvz = mvz / mvd mvz = mvz / mvd
-- apply tool speedup -- apply tool speedup
if this.tool == TOOL_SPADE or this.tool == TOOL_BLOCK then if this.mode == PLM_NORMAL and (this.tool == TOOL_SPADE or this.tool == TOOL_BLOCK) then
mvx = mvx * 1.25 mvx = mvx * 1.25
mvz = mvz * 1.25 mvz = mvz * 1.25
end end
@ -904,25 +930,28 @@ function new_player(settings)
local mvspd = 8.0 local mvspd = 8.0
local mvchange = 10.0 local mvchange = 10.0
mvx = mvx * mvspd mvx = mvx * mvspd
mvy = mvy * mvspd
mvz = mvz * mvspd mvz = mvz * mvspd
-- apply extra slowdowns -- apply extra slowdowns
if not this.grounded then if this.mode == PLM_NORMAL then
mvx = mvx * 0.6 if not this.grounded then
mvz = mvz * 0.6 mvx = mvx * 0.6
mvchange = mvchange * 0.3 mvz = mvz * 0.6
end mvchange = mvchange * 0.3
if inwater then end
mvx = mvx * 0.6 if inwater then
mvz = mvz * 0.6 mvx = mvx * 0.6
end mvz = mvz * 0.6
if this.crouching then end
mvx = mvx * 0.5 if this.crouching then
mvz = mvz * 0.5 mvx = mvx * 0.5
end mvz = mvz * 0.5
if this.zooming or this.ev_sneak then end
mvx = mvx * 0.5 if this.zooming or this.ev_sneak then
mvz = mvz * 0.5 mvx = mvx * 0.5
mvz = mvz * 0.5
end
end end
-- apply rotation -- apply rotation
@ -930,7 +959,11 @@ function new_player(settings)
this.vx = this.vx + (mvx - this.vx)*(1.0-math.exp(-sec_delta*mvchange)) this.vx = this.vx + (mvx - this.vx)*(1.0-math.exp(-sec_delta*mvchange))
this.vz = this.vz + (mvz - this.vz)*(1.0-math.exp(-sec_delta*mvchange)) this.vz = this.vz + (mvz - this.vz)*(1.0-math.exp(-sec_delta*mvchange))
this.vy = this.vy + 2*9.81*sec_delta if this.mode == PLM_NORMAL then
this.vy = this.vy + 2*9.81*sec_delta
else
this.vy = this.vy + (mvy - this.vy)*(1.0-math.exp(-sec_delta*mvchange))
end
local ox, oy, oz local ox, oy, oz
local nx, ny, nz local nx, ny, nz
@ -1620,7 +1653,11 @@ function new_player(settings)
y = h-48} y = h-48}
local function health_update(options) local function health_update(options)
this.health_text.text = ""..this.health if this.mode == PLM_NORMAL then
this.health_text.text = ""..this.health
else
this.health_text.text = ""
end
end end
this.ammo_text = scene.textfield{ this.ammo_text = scene.textfield{

View File

@ -24,6 +24,7 @@
"kick", "kick",
"tempban", "tempban",
"teleport", "teleport",
"gmode",
"goto" "goto"
] ]
}, },
@ -35,4 +36,4 @@
] ]
} }
} }
} }