Counter Strike Online Wiki
Advertisement

Script Structure example to create a Team Deathmatch map

Codes used in each file to be imported by the destination map

game.lua[]

-- Team Deathmatch Example (game)

local TDM = Game.Rule
TDM.name = "Team Deathmatch"
TDM.desc = "Teamed mode scripted"

-- Map breakable
TDM.breakable = true

-- Target Score
local MaxKill = Game.SyncValue.Create("MaxKill")
MaxKill.value = 30

-- Team Score
local Score = {}
Score[Game.TEAM.CT] = Game.SyncValue.Create("ScoreCT")
Score[Game.TEAM.CT].value = 0
Score[Game.TEAM.TR] = Game.SyncValue.Create("ScoreTR")
Score[Game.TEAM.TR].value = 0

function TDM:OnPlayerSpawn(player)
    player:ShowBuymenu()
end

function TDM:OnPlayerKilled(victim, killer)
    -- Suicide or death
    if killer == nil then
        return
    end

    -- 1 point for the killer team
    local killer_team = killer.team
    local point = Score[killer_team]
    point.value = point.value + 1

    -- Win over the target!
    if (point.value >= MaxKill.value) then
        self:Win(killer_team)
    end
end


ui.lua[]

-- Team Death Match Example (ui)

-- Score variables to be synchronized on the server
ScoreCT = UI.SyncValue.Create("ScoreCT")
ScoreTR = UI.SyncValue.Create("ScoreTR")
MaxKill = UI.SyncValue.Create("MaxKill")

-- Create scoreboard
screen = UI.ScreenSize()
center = {x = screen.width / 2, y = screen.height / 2}

scoreBG = UI.Box.Create()
scoreBG:Set({x = center.x - 100, y = 0, width = 200, height = 50, r = 255, g = 255, b = 255, a = 150})

goalBG = UI.Box.Create()
goalBG:Set({x = center.x - 50, y = 0, width = 100, height = 50, r = 40, g = 40, b = 40, a = 150})

goalLabel = UI.Text.Create()
goalLabel:Set({text='00', font='large', align='center', x = center.x - 50, y = 10, width = 100, height = 50, r = 80, g = 255, b = 80})

ctLabel = UI.Text.Create()
ctLabel:Set({text='00', font='medium', align='left', x = center.x - 95, y = 20, width = 50, height = 50, r = 80, g = 80, b = 255})

trLabel = UI.Text.Create()
trLabel:Set({text='00', font='medium', align='right', x = center.x + 45, y = 20, width = 50, height = 50, r = 255, g = 80, b = 80})

-- Update the scoreboard whenever variables are synchronized
function ScoreCT:OnSync()
    local str = string.format("%02d", self.value)
    ctLabel:Set({text = str})
end

function ScoreTR:OnSync()
    local str = string.format("%02d", self.value)
    trLabel:Set({text = str})
end

function MaxKill:OnSync()
    local str = string.format("%02d", self.value)
    goalLabel:Set({text = str})
end

Advertisement