All pastes #2052797 Raw Edit

Miscellany

public lua v1 · immutable
#2052797 ·published 2011-05-02 10:08 UTC
rendered paste body
--Сначала у меня узнаются положения точекfor pointID,pointElement in ipairs(getElementsByType("caputecheckpoint")) do    local x,y,z = getElementData(pointElement, "posX"),getElementData(pointElement, "posY"),getElementData(pointElement, "posZ")    createObject(3279,x,y,z)    setElementData(pointElement, "blip", createBlip(x,y,z,37,0,0,0,0,0,0,180))    setElementData(pointElement, "colshape", createColCuboid(x-5,y-5,z, 10,10,20))end--после, их получает клиент, добавляя каждый colshape точки в pointsByShapefor pointID,pointElement in ipairs(getElementsByType("caputecheckpoint")) do    local x,y,z = getElementData(pointElement, "posX"),getElementData(pointElement, "posY"),getElementData(pointElement, "posZ")    pointsByShape[getElementData(pointElement, "colshape")] = pointElementend--дальше, на клиенте у меня имеются события hit & leave colshape:addEventHandler("onClientElementColShapeHit", localPlayer,function(colShape)    currentShape = {shape=colShape,timer=setTimer(sendInfoToServer, 1000, 0, pointsByShape[colShape])}end)addEventHandler("onClientElementColShapeLeave", localPlayer,	function(colShape)		if(currentShape.shape == colShape) then			killTimer(currentShape.timer)			currentShape = nil		end	end)--Клиентский таймер. Вот тут начинается бред - отправляем каждую секунду серверу о захватывании точки, и если точка захвачена, то игроку генерируется +5хп\сек.function sendInfoToServer(point)	if(currentPlayerState == "play") then		local team = getPlayerTeam(localPlayer)		local spawn = getElementData(team, "spawn")		local send = getElementData(point, spawn)+5		if(getElementData(point, "owner") ~= team) then triggerServerEvent("getInfoFromClient", point, spawn, send, localPlayer)		else			local hp = getElementHealth(localPlayer)			if(hp < 100) then setElementHealth(localPlayer,hp + 5)			elseif(hp ~= 100) then setElementHealth(localPlayer, 100) end		end	else		killTimer(currentShape.timer)		currentShape = nil	endend--На сервере обрабатываем присланную сервером инфуaddEvent("getInfoFromClient", true)addEventHandler("getInfoFromClient", getRootElement(),	function(spawn, howmach, player)		--outputChatBox(spawn.." - "..howmach)		setElementData(source, spawn, howmach)		addToStatistic(player, "score", 5)				if(howmach >= 100) then			local owner = getElementData(source, "owner")			if(owner) then outputChatBox(getTeamName(spawnAndTeams[spawn]).." ("..getPlayerName(player)..") перехватили вышку у "..getTeamName(owner).."!")			else outputChatBox(getTeamName(spawnAndTeams[spawn]).." ("..getPlayerName(player)..") захватили вышку!") end			addToStatistic(player, "captured", 1)			setBlipIcon(getElementData(source, "blip"), spawnAndIcons[spawn])			setElementData(source, "owner", spawnAndTeams[spawn])			addToStatistic(player, "score", 100*getTeamTowers(spawnAndTeams[spawn]))			setElementData(source, "Team1", 0)			setElementData(source, "Team2", 0)			setElementData(source, "Team3", 0)			setElementData(source, "Team4", 0)		end	end)--Вот такой бред. Как лучше и проще сделать захват точки?