Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions script.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ g_timer=0
g_remind_interval=3600
g_ui_reset_requested=false
g_flag_radius=300
--WebMapAddon
g_has_webmap=false
g_webMapBindings={}

g_ammo_supply_buttons={
MG_K={42,50,'mg'},
Expand Down Expand Up @@ -614,6 +617,19 @@ function onCreate(is_world_create)
registerPopup('game_time', -0.9, -0.9)

setSettingsToStandby()

--WebMapAddonDetectCheck
count = server.getAddonCount()
for addon_index=0,count-1 do
local ADDON_DATA =server.getAddonData(addon_index)
local addon_name = string.lower(ADDON_DATA.name)
if addon_name == 'webmap' then
g_has_webmap=true
announce('Webmap addon detected!',0)
break
end
end

end

function onDestroy()
Expand Down Expand Up @@ -792,6 +808,10 @@ function onPlayerSit_(peer_id, vehicle_id, seat_name)
local vehicle=registerVehicle(vehicle_id)
if vehicle and vehicle.alive then
player.vehicle_id=vehicle_id
--WebMapAddon
if g_has_webmap then
bindVehicleTeamToWebMap(vehicle_id, player.team)
end
end
g_player_status_dirty=true
end
Expand Down Expand Up @@ -881,6 +901,21 @@ function join(peer_id, team, force)
local vehicle=registerVehicle(vehicle_id)
if vehicle and vehicle.alive then
player.vehicle_id=vehicle_id
--WebMapAddon
if g_has_webmap then
bindVehicleTeamToWebMap(vehicle_id, team)
end
end
else
--WebMapAddon
--not sit
--Currently, it does not work because player.vehicle_id = -1 is set.
local vehicle=registerVehicle(player.vehicle_id)
if vehicle and vehicle.alive then
player.vehicle_id=vehicle_id
if g_has_webmap then
bindVehicleTeamToWebMap(vehicle_id, team)
end
end
end

Expand Down Expand Up @@ -931,6 +966,13 @@ function shuffle(team_count, exec_peer_id)
local team=g_default_teams[1+(i-1)%team_count]
g_players[peer_id].team=team
announce('You joined to '..team..'.', peer_id)
--WebMapAddon
if g_has_webmap then
local vehicle=findVehicle(g_players[peer_id].vehicle_id)
if vehicle and vehicle.alive then
bindVehicleTeamToWebMap(g_players[peer_id].vehicle_id, team)
end
end
table.remove(peer_ids, pick)
end

Expand Down Expand Up @@ -1090,6 +1132,11 @@ function unregisterVehicle(vehicle_id)
if not vehicle then return end
table.remove(g_vehicles,index)

--WebMapAddon
if g_has_webmap then
g_webMapBindings[vehicle_id]=nil
end

for peer_id,player in pairs(g_players) do
if player.vehicle_id==vehicle_id then
player.vehicle_id=-1
Expand Down Expand Up @@ -1189,6 +1236,34 @@ function updateVehicle(vehicle)
g_player_status_dirty=true
end

--WebMapAddon(Called from the Join/Shuffle/Sit event.)
function bindVehicleTeamToWebMap(vehicle_id, team)

if g_has_webmap==false then
return
end

if not vehicle_id or vehicle_id<0 then
return
end

local TEAM_COLOR_MAP = {
red = "RED",
blue = "BLUE",
pink = "PINK",
ylw = "YELLOW",
standby = "YELLOW"
}
team = string.lower(team)
local color = TEAM_COLOR_MAP[team]
if not color then return end

if g_webMapBindings[vehicle_id]==color then return end
g_webMapBindings[vehicle_id]=color
--?wm ct(WebMap_ChangeTeam)command
local cmd = '?wm ct ' .. vehicle_id .. ' ' .. color
server.command(cmd)
end
-- System Functions --

function updateTeamStatus()
Expand Down