Use default MTA team system

This commit is contained in:
ChronosX88 2020-01-07 14:52:56 +04:00
parent b0301c0f54
commit 6ed4a58ebd
5 changed files with 55 additions and 21 deletions

12
.vscode/settings.json vendored
View File

@ -30,7 +30,17 @@
"setElementModel", "setElementModel",
"localPlayer", "localPlayer",
"bindKey", "bindKey",
"setCameraTarget" "setCameraTarget",
"createTeam",
"setElementData",
"setPlayerTeam",
"setTimer",
"getTeamFromName",
"respawnVehicle",
"getPlayerTeam",
"getTeamName",
"getElementData",
"triggerServerEvent"
], ],
"Lua.diagnostics.disable": [ "Lua.diagnostics.disable": [
"lowercase-global" "lowercase-global"

View File

@ -1,5 +1,5 @@
Teams = { Teams = {
SECRET_SERVICE = "secret_service", SECRET_SERVICE = "Secret Service",
POLICE = "police", POLICE = "Police",
TERRORISTS = "terrorists" TERRORISTS = "Terrorists"
} }

View File

@ -3,9 +3,9 @@
<script src="util\class.lua" type="shared"/> <script src="util\class.lua" type="shared"/>
<script src="util\color.lua" type="shared"/> <script src="util\color.lua" type="shared"/>
<script src="enums.lua" type="shared"/> <script src="enums.lua" type="shared"/>
<script src="team.lua" type="shared"/>
<script src="server.lua" type="server"/> <script src="server.lua" type="server"/>
<script src="client.lua" type="client"/> <script src="client.lua" type="client"/>
<script src="gui\dxbutton.lua" type="client"/> <script src="gui\dxbutton.lua" type="client"/>
<map src="ptp-map.map" dimension="0" />
<oop>true</oop> <oop>true</oop>
</meta> </meta>

View File

@ -1,4 +1,4 @@
local teams = {} local teamSpawns = {}
local function mainOnPlayerJoin() local function mainOnPlayerJoin()
setCameraMatrix(source, 1654.3691, -1643.5967, 85.176224, 1658.8364, -1545.6569, 65.482597) setCameraMatrix(source, 1654.3691, -1643.5967, 85.176224, 1658.8364, -1545.6569, 65.482597)
@ -14,7 +14,7 @@ local function spawnPlayerOnTeamBase(player, x, y, z, rotation, skinID)
showCursor(player, false) showCursor(player, false)
spawnPlayer(player, x, y, z, rotation, skinID) spawnPlayer(player, x, y, z, rotation, skinID)
setCameraTarget(player) setCameraTarget(player)
fadeCamera(source, true) --fadeCamera(player, true)
setPlayerHudComponentVisible(player, "all", true) setPlayerHudComponentVisible(player, "all", true)
toggleAllControls(player, true, true, true) toggleAllControls(player, true, true, true)
end end
@ -24,11 +24,20 @@ local function mainOnPlayerTeamSelected(team, skinID)
outputDebugString("OnPlayerTeamSelected: Invalid argument type") outputDebugString("OnPlayerTeamSelected: Invalid argument type")
end end
if team == Teams.SECRET_SERVICE then if team == Teams.SECRET_SERVICE then
spawnPlayerOnTeamBase(source, 2795.0, -1825.0, 9.9, 90, skinID) local team = getTeamFromName(Teams.SECRET_SERVICE)
setPlayerTeam(source, team)
setElementData(source, "team."..Teams.SECRET_SERVICE..".skinID", skinID)
spawnPlayerOnTeamBase(source, teamSpawns[Teams.SECRET_SERVICE][1], teamSpawns[Teams.SECRET_SERVICE][2], teamSpawns[Teams.SECRET_SERVICE][3], teamSpawns[Teams.SECRET_SERVICE][4], skinID)
elseif team == Teams.POLICE then elseif team == Teams.POLICE then
spawnPlayerOnTeamBase(source, 1532.6, -1677.3, 5.9, 90, skinID) local team = getTeamFromName(Teams.POLICE)
setPlayerTeam(source, team)
setElementData(source, "team."..Teams.POLICE..".skinID", skinID)
spawnPlayerOnTeamBase(source, teamSpawns[Teams.POLICE][1], teamSpawns[Teams.POLICE][2], teamSpawns[Teams.POLICE][3], teamSpawns[Teams.POLICE][4], skinID)
elseif team == Teams.TERRORISTS then elseif team == Teams.TERRORISTS then
spawnPlayerOnTeamBase(source, 1774.0, -1926.5, 13.5, 90, skinID) local team = getTeamFromName(Teams.TERRORISTS)
setPlayerTeam(source, team)
setElementData(source, "team."..Teams.TERRORISTS..".skinID", skinID)
spawnPlayerOnTeamBase(source, teamSpawns[Teams.TERRORISTS][1], teamSpawns[Teams.TERRORISTS][2], teamSpawns[Teams.TERRORISTS][3], teamSpawns[Teams.TERRORISTS][4], skinID)
end end
triggerClientEvent(source, "onPlayerTeamSelectedSuccessful", resourceRoot) triggerClientEvent(source, "onPlayerTeamSelectedSuccessful", resourceRoot)
end end
@ -36,8 +45,29 @@ end
addEvent("onPlayerTeamSelected", true) addEvent("onPlayerTeamSelected", true)
addEventHandler("onPlayerTeamSelected", root, mainOnPlayerTeamSelected) addEventHandler("onPlayerTeamSelected", root, mainOnPlayerTeamSelected)
addEventHandler("onPlayerJoin", root, mainOnPlayerJoin) addEventHandler("onPlayerJoin", root, mainOnPlayerJoin)
addEventHandler("onResourceStart", root, function()
teams[Teams.SECRET_SERVICE] = Team(Teams.SECRET_SERVICE, "Secret Service", tocolor(29, 253, 0, 255)) function respawnExplodedVehicle()
teams[Teams.POLICE] = Team(Teams.POLICE, "Police", tocolor(0, 23, 252, 55)) setTimer(respawnVehicle, 9000, 1, source)
teams[Teams.TERRORISTS] = Team(Teams.TERRORISTS, "Terrorists", tocolor(251, 0, 0, 200)) end
end) addEventHandler("onVehicleExplode", root, respawnExplodedVehicle)
addEventHandler("onPlayerWasted", root,
function()
local team = getPlayerTeam(source)
if team then
local teamName = getTeamName(team)
setTimer( spawnPlayerOnTeamBase, 3000, 1, source, teamSpawns[teamName][1], teamSpawns[teamName][2], teamSpawns[teamName][3], teamSpawns[teamName][4], getElementData(source, "team."..teamName..".skinID"))
end
end
)
addEventHandler("onResourceStart", root,
function ()
createTeam(Teams.SECRET_SERVICE, 29, 253, 0)
createTeam(Teams.POLICE, 0, 23, 252)
createTeam(Teams.TERRORISTS, 251, 0, 0)
teamSpawns[Teams.SECRET_SERVICE] = { 2795.0, -1825.0, 9.9, 90 }
teamSpawns[Teams.POLICE] = { 1532.6, -1677.3, 5.9, 270 }
teamSpawns[Teams.TERRORISTS] = { 1774.0, -1926.5, 13.5, 270 }
end
)

View File

@ -1,6 +0,0 @@
Team = class(function(team, teamID, teamName, teamColor)
team.teamID = teamID
team.teamName = teamName
team.teamColor = teamColor
team.playersCount = 0
end)