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,7 +136,7 @@ Iceball Base Mod:
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
note, this can be used to update a player on the server
@ -144,6 +144,11 @@ Iceball Base Mod:
"weapon" can be one of these:
1: rifle
"mode" can be one of these:
1: normal player
2: map editor
3: spectator
yeah that's it really.
0x06 pid: (S->C) @

View File

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

View File

@ -126,6 +126,23 @@ command_register({
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 = "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 y >= 0 and y <= ylen-3 then
if plr.blocks > 0 and map_is_buildable(x,y,z) then
if plr.mode == PLM_NORMAL then
plr.blocks = plr.blocks - 1
end
map_block_set(x,y,z,ct,cr,cg,cb)
net_broadcast(nil, common.net_pack("BHHHBBBB",
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()
plr.set_health_damage(0, 0xFF800000, plr.name.." changed teams", nil)
plr.team = tidx
net_broadcast(nil, common.net_pack("BBBBhhhzz",
net_broadcast(nil, common.net_pack("BBBBBhhhzz",
0x05, plr.pid,
plr.team, plr.weapon,
plr.team, plr.weapon, plr.mode,
plr.score, plr.kills, plr.deaths,
plr.name, plr.squad))
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
local plr = players[i]
if plr then
common.net_send(sockfd, common.net_pack("BBBBhhhzz",
common.net_send(sockfd, common.net_pack("BBBBBhhhzz",
0x05, i,
plr.team, plr.weapon,
plr.team, plr.weapon, plr.mode,
plr.score, plr.kills, plr.deaths,
plr.name, plr.squad))
common.net_send(sockfd, common.net_pack("BBfffBB",
@ -387,9 +389,9 @@ function server.hook_tick(sec_current, sec_delta)
end
-- relay this player to everyone
net_broadcast(nil, common.net_pack("BBBBhhhzz",
net_broadcast(nil, common.net_pack("BBBBBhhhzz",
0x05, cli.plrid,
plr.team, plr.weapon,
plr.team, plr.weapon, plr.mode,
plr.score, plr.kills, plr.deaths,
plr.name, plr.squad))
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))
end
elseif cid == 0x1B and plr and plr.grenades > 0 then
if plr.mode == PLM_NORMAL then
plr.grenades = plr.grenades - 1
end
local x,y,z,vx,vy,vz,fuse
x,y,z,vx,vy,vz,fuse, pkt = common.net_unpack("hhhhhhH", pkt)
local n = new_nade({

View File

@ -15,6 +15,10 @@
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)
local this = {} this.this = this this.this.this = this this = this.this
@ -25,6 +29,7 @@ function new_player(settings)
this.alive = false
this.spawned = false
this.zooming = false
this.mode = settings.mode or PLM_NORMAL
this.mdl_block = common.model_new(1)
this.mdl_block = common.model_bone_new(this.mdl_block)
@ -325,9 +330,9 @@ function new_player(settings)
end
function this.update_score()
net_broadcast(nil, common.net_pack("BBBBhhhzz",
net_broadcast(nil, common.net_pack("BBBBBhhhzz",
0x05, this.pid,
this.team, this.weapon,
this.team, this.weapon, this.mode,
this.score, this.kills, this.deaths,
this.name, this.squad))
end
@ -379,6 +384,10 @@ function new_player(settings)
end
function this.damage(amt, kcol, kmsg, enemy)
if this.mode ~= PLM_NORMAL then
return nil
end
return this.set_health_damage(
this.health - amt, kcol, kmsg, enemy)
end
@ -443,6 +452,9 @@ function new_player(settings)
end
function this.grenade_damage(amt, enemy)
if enemy.mode ~= PLM_NORMAL then
return nil
end
--print("damage",this.name,part,amt)
local midmsg = " grenaded "
if this.team == enemy.team and this ~= enemy then
@ -466,7 +478,7 @@ function new_player(settings)
end
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
end
@ -685,7 +697,7 @@ function new_player(settings)
this.dangx = (nax - this.angx)
-- 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
local fx,fy,fz -- forward
@ -754,7 +766,7 @@ function new_player(settings)
fwx,fwy,fwz = sya*cxa, sxa, cya*cxa
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 (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
@ -766,7 +778,9 @@ function new_player(settings)
this.blk_color[2],
this.blk_color[1],
1))
if this.mode == PLM_NORMAL then
this.blocks = this.blocks - 1
end
this.t_newblock = sec_current + MODE_DELAY_BLOCK_BUILD
this.t_switch = this.t_newblock
end
@ -776,7 +790,7 @@ function new_player(settings)
if (not this.t_newspade1) then
-- 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_part = nil
local hurt_part_idx = 0
@ -829,14 +843,16 @@ function new_player(settings)
elseif this.tool == TOOL_NADE then
if (not this.t_newnade) and this.grenades > 0 then
if (not this.t_nadeboom) then
if this.mode == PLM_NORMAL then
this.grenades = this.grenades - 1
end
this.t_nadeboom = sec_current + MODE_NADE_FUSE
end
end
else
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
local ct,cr,cg,cb
ct,cr,cg,cb = map_block_pick(this.blx3, this.bly3, this.blz3)
@ -874,6 +890,7 @@ function new_player(settings)
mvx = mvx - 1.0
end
if this.mode == PLM_NORMAL then
if this.ev_crouch then
if this.grounded and not this.crouching then
if MODE_SOFTCROUCH then this.jerkoffs = this.jerkoffs - 1 end
@ -888,14 +905,23 @@ function new_player(settings)
client.wav_play_global(wav_jump_up, this.x, this.y, this.z)
end
end
else
if this.ev_crouch then
mvy = mvy + 1.0
end
if this.ev_jump then
mvy = mvy - 1.0
end
end
-- normalise mvx,mvz
local mvd = math.max(0.00001,math.sqrt(mvx*mvx + mvz*mvz))
-- normalise mvx,mvy,mvz
local mvd = math.max(0.00001,math.sqrt(mvx*mvx + mvy*mvy + mvz*mvz))
mvx = mvx / mvd
mvy = mvy / mvd
mvz = mvz / mvd
-- 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
mvz = mvz * 1.25
end
@ -904,9 +930,11 @@ function new_player(settings)
local mvspd = 8.0
local mvchange = 10.0
mvx = mvx * mvspd
mvy = mvy * mvspd
mvz = mvz * mvspd
-- apply extra slowdowns
if this.mode == PLM_NORMAL then
if not this.grounded then
mvx = mvx * 0.6
mvz = mvz * 0.6
@ -924,13 +952,18 @@ function new_player(settings)
mvx = mvx * 0.5
mvz = mvz * 0.5
end
end
-- apply rotation
mvx, mvz = mvx*cya+mvz*sya, mvz*cya-mvx*sya
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))
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 nx, ny, nz
@ -1620,7 +1653,11 @@ function new_player(settings)
y = h-48}
local function health_update(options)
if this.mode == PLM_NORMAL then
this.health_text.text = ""..this.health
else
this.health_text.text = ""
end
end
this.ammo_text = scene.textfield{

View File

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