-Rex-

[APORTE] Sistema de duelos

Recommended Posts

Buenas, paso que hace tiempo un cliente me pidio que le haga un script de duelos lo cual luego me arrepenti por haber pedido demasiado poco por el script. Entonces decidí nunca entregarlo, logré desarrollarlo casi por completo pero después por temas de la Universidad no segui trabajando en nada que tenga que ver con MTA y deje muchos proyectos sin terminar.

Yendo al grano, el script posee estas caracteristicas

  • Interfaz en DX ( No multiresolucion, fue hecha en 1280x600 )
  • Puedes elegir entre 8 mapas diferentes
  • Cada duelo es creado en una dimension diferente junto con el mapa ( Es decir cada vez que crees un duelo automaticamente se buscara X dimension desocupada creando el mapa en dicha dimension y redireccionando a los jugadores a la misma ).
  • Se otorgaran armas al jugador en cada respawn
  • Para ganar el duelo debes matar a tu contrincante 5 veces.

En fin, el script esta casi por completo, faltaron agregar las Coordenadas de los spawns, los mapas y siertas cosillas en la interfaz. Espero lo puedan modificar a su gusto.

Imagenes: https://imgur.com/a/DKkHy

Código Cliente

Spoiler

---------------------------------------------------------------------
--  Desarrollador/Developer: -Rex-
--  Proyecto/Proyect:        N/A
--  Contacto/Contact:        https://www.facebook.com/rexscripting/
--	Invitaciones.lua
--  Libre uso y modificacion, No borrar los creditos, Gracias
---------------------------------------------------------------------
GUIEditor = {
    gridlist = {},
    button = {},
    label = {}
}

    inviteplayerduelgui = guiCreateWindow(520, 190, 267, 324, "Invitar rival", false)
    guiWindowSetSizable(inviteplayerduelgui, false)

    GUIEditor.gridlist[1] = guiCreateGridList(10, 61, 162, 254, false, inviteplayerduelgui)
    nickCol = guiGridListAddColumn(GUIEditor.gridlist[1], "Nick", 0.9)
    GUIEditor.label[1] = guiCreateLabel(10, 27, 209, 30, "Para empezar el duelo debes invitar a un jugador para empezar.", false, inviteplayerduelgui)
    guiSetFont(GUIEditor.label[1], "default-bold-small")
    guiLabelSetHorizontalAlign(GUIEditor.label[1], "left", true)
    GUIEditor.button[1] = guiCreateButton(191, 71, 64, 32, "Invitar", false, inviteplayerduelgui)
    guiSetFont(GUIEditor.button[1], "default-bold-small")
    GUIEditor.button[2] = guiCreateButton(191, 113, 64, 32, "Cancelar", false, inviteplayerduelgui)
    guiSetFont(GUIEditor.button[2], "default-bold-small")    
    guiSetVisible( inviteplayerduelgui, false ) 
    centerWindow ( inviteplayerduelgui )



function showingInv( visible )

    if isInDuel ( getLocalPlayer(  ) ) then return end
    
    local inDuel = getElementData( getLocalPlayer(  ), "inDuel" )

    if inDuel then
        guiSetVisible( inviteplayerduelgui, visible ) 
        showDuelos( not visible )
        addPlayerGrid( )
    end
end

function addPlayerGrid( )
    
    guiGridListClear( GUIEditor.gridlist[1] )

    for i, players in ipairs( getElementsByType( "player") ) do
        

        if players ~= getLocalPlayer(  ) then

            local nombre = getPlayerName ( players )
            local row = guiGridListAddRow( GUIEditor.gridlist[1] )
            guiGridListSetItemText( GUIEditor.gridlist[1], row, nickCol, nombre, false, false )

        end

    end

end

function buttons(  )
    
    if source == GUIEditor.button[1] then

        guiSetEnabled( source, false )
        setTimer( guiSetEnabled, 2000, 1, source, true )

        local row,col = guiGridListGetSelectedItem( GUIEditor.gridlist[1] )
        local name = guiGridListGetItemText( GUIEditor.gridlist[1], row, nickCol )
        if row == -1 or col == -1 then return false end

        triggerServerEvent( "invitePlayerToDuel", getLocalPlayer(  ), getPlayerFromName( name ) )

    elseif source == GUIEditor.button[2] then
        guiSetVisible( inviteplayerduelgui, false )  
        showDuelos( true )
        preCreateDuel( false, 0 )
    end

end
addEventHandler("onClientGUIClick", root, buttons )

function dsa()
    local x,y,z = getElementPosition( getLocalPlayer(  ) )
    outputChatBox("{ ".. x ..", ".. y ..", ".. z .." },")
end
--addCommandHandler("gp2", dsa)

function ADS()
    setElementHealth( getLocalPlayer(  ), -10 )
end
addCommandHandler("kill", ADS  )

if fileExists( "invitations.lua" ) then
    fileDelete( "invitations.lua" )
end

---------------------------------------------------------------------
--  Desarrollador/Developer: -Rex-
--  Proyecto/Proyect:        N/A
--  Contacto/Contact:        https://www.facebook.com/rexscripting/
--	Utiles.lua
--  Libre uso y modificacion, No borrar los creditos, Gracias
---------------------------------------------------------------------

function dxDrawOutlinedRectangle( posX, posY, WidX, WidY, cLine, cRectangle, postGui )
    local AX1 = posX - 1
    local AY1 = posY - 1
    local WX1 = posX + WidX
    local HY1 = posY + WidY
    dxDrawLine(AX1, AY1, AX1, HY1, ( cLine or tocolor(0, 0, 0, 255) ), 1, ( postGui or false ) )
    dxDrawLine(WX1, AY1, AX1, AY1, ( cLine or tocolor(0, 0, 0, 255) ), 1, ( postGui or false ) )
    dxDrawLine(AX1, HY1, WX1, HY1, ( cLine or tocolor(0, 0, 0, 255) ), 1, ( postGui or false ) )
    dxDrawLine(WX1, HY1, WX1, AY1, ( cLine or tocolor(0, 0, 0, 255) ), 1, ( postGui or false ) )
    dxDrawRectangle(posX, posY, WidX, WidY, ( cRectangle or tocolor(0, 0, 0, 255) ), ( postGui or false ) )
end

function isCursorOnElement(x,y,w,h)
    local mx,my = getCursorPosition ()
    local fullx,fully = guiGetScreenSize()
    cursorx,cursory = mx*fullx,my*fully
    if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then
        return true
    else
        return false
    end
end

function math.round(number, decimals, method)
    decimals = decimals or 0
    local factor = 10 ^ decimals
    if (method == "ceil" or method == "floor") then return math[method](number * factor) / factor
    else return tonumber(("%."..decimals.."f"):format(number)) end
end

function isEventHandlerAdded( sEventName, pElementAttachedTo, func )
    if 
        type( sEventName ) == 'string' and 
        isElement( pElementAttachedTo ) and 
        type( func ) == 'function' 
    then
        local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo )
        if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then
            for i, v in ipairs( aAttachedFunctions ) do
                if v == func then
                    return true
                end
            end
        end
    end
 
    return false
end

function centerWindow (center_window)
    local screenW, screenH = guiGetScreenSize()
    local windowW, windowH = guiGetSize(center_window, false)
    local x, y = (screenW - windowW) /2,(screenH - windowH) /2
    guiSetPosition(center_window, x, y, false)
end

function isInDuel( player )
    
    local bool = getElementData( player, "playingDuel" )    

    return ( bool or false )
end

if fileExists( "utils.lua" ) then
    fileDelete( "utils.lua" )
end

 


---------------------------------------------------------------------
--  Desarrollador/Developer: -Rex-
--  Proyecto/Proyect:        N/A
--  Contacto/Contact:        https://www.facebook.com/rexscripting/
--	menuPrincipal.lua
--  Libre uso y modificacion, No borrar los creditos, Gracias
---------------------------------------------------------------------

local imagenes = {
    { "imagenes/1.png", 499, 269 },
    { "imagenes/1.png", 573, 269 },
    { "imagenes/1.png", 647, 269 },
    { "imagenes/1.png", 721, 269 },
    { "imagenes/1.png", 499, 374 },
    { "imagenes/1.png", 573, 374 },
    { "imagenes/1.png", 647, 374 },
    { "imagenes/1.png", 721, 374 },
}

local NombresMapa = {
    { "Map 1", 503, 332 },
    { "Map 2", 577, 332 },
    { "Map 3", 651, 332 },
    { "Map 4", 725, 332 },
    { "Map 5", 503, 437 },
    { "Map 6", 577, 437 },
    { "Map 7", 651, 437 },
    { "Map 8", 725, 437 },
}

local pRectangles = {
    { 499, 269 },
    { 573, 269 },
    { 647, 269 },
    { 721, 269 },
    { 499, 374 },
    { 573, 374 },
    { 647, 374 },
    { 721, 374 },
}

local recIn           = 0
local recSelected     = 0
local recBSelected    = false
local buttonBoolSelec = false
local buttonSelect    = 0
local textoBienvenido = "Bienvenido a los duelos, Elige un mapa para empezar"
function mainDuelos()
    dxDrawRectangle(468, 127, 341, 379, tocolor(1, 1, 1, 213), false)
    dxDrawText("Duelos", 523 + 1, 142 + 1, 758 + 1, 195 + 1, tocolor(0, 0, 0, 255), 2.00, "bankgothic", "left", "top", false, false, false, false, false)
    dxDrawText("Duelos", 523, 142, 758, 195, tocolor(243, 255, 226, 213), 2.00, "bankgothic", "left", "top", false, false, false, false, false)
    dxDrawLine(478, 209, 802, 209, tocolor(138, 9, 23, 255), 1, false)
    
    if recSelected ~= 0 then
        textoBienvenido   = "Da click en Jugar para empezar la partida. "
    end
    dxDrawText(textoBienvenido, 488, 219, 723, 249, tocolor(243, 255, 226, 213), 1.00, "default-bold", "left", "top", false, true, false, false, false)  
    dxDrawOutlinedRectangle( 489, 259, 305, 202, tocolor(63, 63, 63, 135), tocolor(1, 1, 1, 135) )

    for i,v in ipairs( NombresMapa ) do
        local texto = v[1]
        local posX  = v[2]
        local posY  = v[3]
        dxDrawText(texto, posX, posY, 548, 350, tocolor(243, 255, 226, 213), 1.00, "default-bold", "left", "top", false, false, false, false, false)
    end

    local count = 0
    for i,v in ipairs( pRectangles ) do
        count = count + 1
        local posX  = v[1]
        local posY  = v[2]
        local cLine = tocolor(63, 63, 63, 11)
        if ( count == recIn ) then
            cLine = tocolor(138, 9, 23, 255)
        end
        dxDrawOutlinedRectangle( posX, posY, 64, 63, cLine, tocolor(100, 100, 100, 0) )
    end

    if recBSelected then
        local posX  = pRectangles[recSelected][1]
        local posY  = pRectangles[recSelected][2]
        dxDrawOutlinedRectangle( posX, posY, 64, 63, tocolor(138, 9, 23, 255), tocolor(100, 100, 100, 0) )
    end

    for i,v in ipairs( imagenes ) do
        local posX = v[2]
        local posY = v[3]
        dxDrawImage(posX, posY, 63, 62, v[1], 0, 0, 0, tocolor(255, 255, 255, 255), false)
    end

    local recC1  = tocolor(243, 255, 226, 0)
    local textC1 = tocolor(243, 255, 226, 213)
    local recC2  = tocolor(243, 255, 226, 0)
    local textC2 = tocolor(243, 255, 226, 213)
    if buttonBoolSelec then
        if buttonSelect == 1 then
            recC1  = tocolor(243, 255, 226, 213)
            textC1 = tocolor(1, 1, 1, 213)
        elseif buttonSelect == 2 then
            recC2  = tocolor(243, 255, 226, 213)
            textC2 = tocolor(1, 1, 1, 213)
        end
    end

    dxDrawOutlinedRectangle( 651, 471, 69, 29, recC1, tocolor(138, 9, 23, 255) )
    dxDrawText("Jugar", 668, 478, 701, 492, textC1, 1.00, "default-bold", "left", "top", false, false, false, false, false)
    
    dxDrawOutlinedRectangle( 730, 471, 69, 29, recC2, tocolor(138, 9, 23, 255) )
    dxDrawText("Cerrar", 746, 478, 779, 492, textC2, 1.00, "default-bold", "left", "top", false, false, false, false, false)
end

function moveCursor( )
    
    if isCursorShowing( getLocalPlayer(  ) ) then

        recIn = 0
        for i,v in ipairs( imagenes ) do

            local posX = v[2]
            local posY = v[3]

            if isCursorOnElement( posX, posY, 63, 62 ) then

                recIn = i
            end

        end

        buttonSelect    = 0
        buttonBoolSelec = false

        if isCursorOnElement( 651, 471, 69, 29 ) then
            buttonSelect    = 1
            buttonBoolSelec = true
        elseif isCursorOnElement( 730, 471, 69, 29 ) then
            buttonSelect    = 2
            buttonBoolSelec = true
        end

    end

end

function clickRec( _, state )

    if ( state == "down" ) then

        if buttonSelect == 0 then
            recSelected  = 0
            recBSelected = false
            textoBienvenido = "Bienvenido a los duelos, Elige un mapa para empezar"
        end

        for i,v in ipairs( imagenes ) do

            local posX = v[2]
            local posY = v[3]

            if isCursorOnElement( posX, posY, 63, 62 ) then
                recSelected  = i
                recBSelected = true
            end

        end

        if isCursorOnElement( 651, 471, 69, 29 ) then
            buttonSelect    = 0
            buttonBoolSelec = false
        elseif isCursorOnElement( 730, 471, 69, 29 ) then
            buttonSelect    = 0
            buttonBoolSelec = false
        end

    elseif ( state == "up" ) then

        if isCursorOnElement( 651, 471, 69, 29 ) then

            buttonSelect    = 1
            buttonBoolSelec = true

            if recSelected ~= 0 then
                preCreateDuel( true, recSelected )
                showingInv( true )
            else
                textoBienvenido = "Selecciona un mapa para iniciar el duelo!"
            end

        elseif isCursorOnElement( 730, 471, 69, 29 ) then
            buttonSelect    = 2
            buttonBoolSelec = true
            key(  )
        end



    end

end

function preCreateDuel( bool, id )

    if id ~= 0 then
        setElementData( getLocalPlayer(  ), "inDuel", { ( bool or false ), id } )
    else
        setElementData( getLocalPlayer(  ), "inDuel", nil )
    end
end

function showDuelos( bool )
    removeEventHandler("onClientRender", root, mainDuelos )
    removeEventHandler("onClientCursorMove", root, moveCursor )
    removeEventHandler("onClientClick", root, clickRec )
    if bool then
        addEventHandler("onClientRender", root, mainDuelos )
        addEventHandler("onClientCursorMove", root, moveCursor )
        addEventHandler("onClientClick", root, clickRec )
    end
end

local showing = false
function key(  )
    if isInDuel ( getLocalPlayer(  ) ) then return end
    showDuelos( not showing )
    showCursor( not showing )
    showing = not showing

    if not showing then
        guiSetVisible( inviteplayerduelgui, false ) 
    end

end
addCommandHandler( "duelos", key )


function disableGUIS( )
    showDuelos( false )
    guiSetVisible( inviteplayerduelgui, false ) 
    showCursor( false )
end
addEvent("disableGUIS", true)
addEventHandler("disableGUIS", getLocalPlayer(), disableGUIS)


local counterEnabled = false
local counterText    = ""
local enabledInici   = false
function playSoundss( name )
    playSound( "sonidos/"..name..".mp3" )
    counterText = string.gsub( name, "count_", "" )
    if name ~= "count_go" then
        counterEnabled = true
    else

        setTimer( function( )
        enabledInici   = false
        counterEnabled = false
        counterText    = ""  end, 1000, 1 )
    end

end
addEvent("playtheSound", true)
addEventHandler("playtheSound", getLocalPlayer(), playSoundss)


function enableIni( bool )
    enabledInici = bool
end
addEvent("sad", true)
addEventHandler("sad", getLocalPlayer(), enableIni)

function speed(  )
    setGameSpeed( 0 )

    setTimer( setGameSpeed, 5000, 1, 1)
end
addEvent("speeds", true)
addEventHandler("speeds", getLocalPlayer(), speed )

local x, y = guiGetScreenSize(  )
function drawins()

    if enabledInici then
        dxDrawText("Duelo aceptado! Iniciando el juego...", 0 + 1, 0 + 1, x + 1, ( y - 20 ) + 1, tocolor(0, 0, 0, 255), 2.50, "sans", "center", "center", false, false, false, false, false)
        dxDrawText("Duelo aceptado! Iniciando el juego...", 0, 0, x, ( y - 20 ), tocolor(255, 255, 255, 255), 2.50, "sans", "center", "center", false, false, false, false, false)
    end 

    if counterEnabled then

        dxDrawText(counterText, 0 + 1, 0 + 1, x + 1, ( y - 20 ) + 1, tocolor(0, 0, 0, 255), 4.00, "pricedown", "center", "center", false, false, false, false, false)
        dxDrawText(counterText, 0, 0, x, ( y - 20 ), tocolor(0, 225, 0, 255), 4.00, "pricedown", "center", "center", false, false, false, false, false)
    end

end
addEventHandler("onClientRender", root, drawins )

if fileExists( "main.lua" ) then
    fileDelete( "main.lua" )
end

 

Código server

Spoiler

---------------------------------------------------------------------
--  Desarrollador/Developer: -Rex-
--  Proyecto/Proyect:        N/A
--  Contacto/Contact:        https://www.facebook.com/rexscripting/
--	server.lua
--  Libre uso y modificacion, No borrar los creditos, Gracias
---------------------------------------------------------------------
local duels = { }

local mapsSpawns = {

	[1] = {
		{ 2490.4135742188, -1656.00390625, 13.371081352234 },
	},

	[2] = {
		{ 2490.4135742188, -1656.00390625, 13.371081352234 },
	},

	[3] = {
		{ 2490.4135742188, -1656.00390625, 13.371081352234 },
	},

	[4] = {
		{ 2490.4135742188, -1656.00390625, 13.371081352234 },
	},

	[5] = {
		{ 2490.4135742188, -1656.00390625, 13.371081352234 },
	},

	[6] = {
		{ 2490.4135742188, -1656.00390625, 13.371081352234 },
	},

	[7] = {
		{ 2490.4135742188, -1656.00390625, 13.371081352234 },
	},

	[8] = {
		{ 2490.4135742188, -1656.00390625, 13.371081352234 },
	},

}

local mapsObjects = {

	[1] = {
		{ 3243, 2504.8955078125, -1665.8275146484, 13.381624221802, 0, 0, 180 },
	},

	[2] = {
		{ 3243, 2504.8955078125, -1665.8275146484, 13.381624221802, 0, 0, 180 },
	},

	[3] = {
		{ 3243, 2504.8955078125, -1665.8275146484, 13.381624221802, 0, 0, 180 },
	},

	[4] = {
		{ 3243, 2504.8955078125, -1665.8275146484, 13.381624221802, 0, 0, 180 },
	},

	[5] = {
		{ 3243, 2504.8955078125, -1665.8275146484, 13.381624221802, 0, 0, 180 },
	},

	[6] = {
		{ 3243, 2504.8955078125, -1665.8275146484, 13.381624221802, 0, 0, 180 },
	},

	[7] = {
		{ 3243, 2504.8955078125, -1665.8275146484, 13.381624221802, 0, 0, 180 },	
	},

	[8] = {
		{ 3243, 2504.8955078125, -1665.8275146484, 13.381624221802, 0, 0, 180 },
	},

}

function startResource(  )
	
	for i, player in ipairs( getElementsByType( "player") ) do
		setElementData( player, "playingDuel", nil )
		setElementData( player, "inDuel", nil )
		setElementData( player, "murdersInDuel", nil )
	end

end
addEventHandler("onResourceStart",getResourceRootElement( getThisResource() ),startResource )


function inviteDuel( player )
	
	if isElement( player ) then

		duels[player] = { getElementData( source, "inDuel" )[2], source }

		outputChatBox( getPlayerName( source ).."#FFFFFF Te reto a un duelo! Usa /aceptarduelo", player, 255, 255, 255, true )

		outputChatBox( "Invitacion enviada! Espera a que la acepte para iniciar el juego.", source, 255, 255, 255, true )
	end

end
addEvent("invitePlayerToDuel", true)
addEventHandler("invitePlayerToDuel", getRootElement(), inviteDuel)


function acceptDuel( player )
	
	if duels[player] then

		local isOnlyDuel = getElementData( duels[player][2], "inDuel" )

		local idMap      = duels[player][1]
		if isOnlyDuel then

			if not isInDuel ( player ) then

				if isInDuel ( duels[player][2] ) then
					--outputChatBox( "El Jugador ya esta en un duelo!", player, 255, 255, 255, true )
					duels[player] = nil
					return
				end

				local thePlay = duels[player][2]
				takeAllWeapons( player )
				takeAllWeapons( thePlay )

				triggerClientEvent( player, "sad", player, true )
				triggerClientEvent( thePlay, "sad", thePlay, true )

				triggerClientEvent( player, "disableGUIS", player )
				triggerClientEvent( thePlay, "disableGUIS", thePlay )

				controlsPlayers( player, thePlay, false )

				setElementData( player, "inDuel", { true, idMap } )
				setElementData( player, "playingDuel", idMap )
				setElementData( thePlay, "playingDuel", idMap )
				setElementHealth( player, 1000 )
				setElementHealth( thePlay, 1000 )

				removePlayersFromVehicle( player, thePlay )

				setTimer( function( idMap, player ) 

					triggerClientEvent( player, "sad", player, false )
					triggerClientEvent( duels[player][2], "sad", duels[player][2], false )

				local dimensionLibre = findDimensionForMap( idMap )

				if dimensionLibre then

					if not isElement( duels[player][2] ) then
						outputChatBox( "Error desconocido!", player, 255, 255, 255, true )
						setElementData( player, "playingDuel", nil )
						setElementData( player, "inDuel", nil )
						setElementDimension( player, 0 )
						killPed ( player )
						return
					end

					createMapForDimension( idMap, dimensionLibre )

					respawnInDuelMap( player, idMap, dimensionLibre )
					respawnInDuelMap( duels[player][2], idMap, dimensionLibre )
					setElementData( player, "murdersInDuel", 0 )
					setElementData( duels[player][2], "murdersInDuel", 0 )

					local contador = 3

					setTimer( function( player, player2 ) 


						if contador > 0 then
							playPlayerSound( player, player2, "count_"..tostring( contador ) )
							contador = contador - 1
						else
							playPlayerSound( player, player2, "count_go" )
							controlsPlayers( player, player2, true )
						end

					end, 1000, contador+1, player, duels[player][2] )

					duels[player] = nil
				
				end
				end, 5000, 1, idMap, player )

			else
				outputChatBox( "Ya estás en un duelo!", player, 255, 255, 255, true )
			end

		else
			outputChatBox( "El Retador cancelo el duelo!", player, 255, 255, 255, true )
			duels[player] = nil
		end

	else
		if not isInDuel ( player ) then
			outputChatBox( "No tienes invitaciones de duelo.", player, 255, 255, 255, true )
		end
	end

end
addCommandHandler( "aceptarduelo", acceptDuel )



function onDiePlayer( ammo, attacker, weapon, bodypart )

	if attacker and getElementType( attacker ) == "player" then
		
		if isInDuel( attacker ) and isInDuel( source ) then

			if isInDuel( source ) then

				setElementData( attacker, "murdersInDuel", ( getElementData( attacker, "murdersInDuel") or 0 ) + 1 )
				outputChatBox( "#00FF00"..getPlayerName ( attacker ).."#FFFFFF "..( getElementData( attacker, "murdersInDuel") or 0 ).." - "..( getElementData( source, "murdersInDuel") or 0 ).." ".."#00FF00"..getPlayerName ( source ), attacker, 255, 255, 255, true )
				outputChatBox( "#00FF00"..getPlayerName ( attacker ).."#FFFFFF "..( getElementData( attacker, "murdersInDuel") or 0 ).." - "..( getElementData( source, "murdersInDuel") or 0 ).." ".."#00FF00"..getPlayerName ( source ), source, 0, 225, 0, true )
				local attackerMurders = getElementData( attacker, "murdersInDuel") or 0

				if attackerMurders >= 5 then
					outputChatBox( "Ganaste el duelo!", attacker, 0, 225, 0, true )
					outputChatBox( "Perdiste el duelo", source, 0, 225, 0, true )
					givePlayerMoney( attacker, 5000 )
					triggerClientEvent( source, "speeds", source )
					destroyObjectsInDimension( getElementDimension( source ) )
					setElementData( source, "playingDuel", nil )
					setElementData( source, "inDuel", nil )
					setElementData( source, "murdersInDuel", nil )
					setElementDimension( source, 0 )


					setElementData( attacker, "playingDuel", nil )
					setElementData( attacker, "inDuel", nil )
					setElementData( attacker, "murdersInDuel", nil )
					setElementDimension( attacker, 0 )
					triggerClientEvent( attacker, "speeds", attacker )

					setElementHealth( attacker, -15 )
					setElementHealth( source, -15 )
				else
					triggerClientEvent( source, "speeds", source )
				end
			end
		end
	end
end
addEventHandler ( "onPlayerWasted", getRootElement(), onDiePlayer )

function onSpawn(  )
	local data      = getElementData( source, "inDuel" )
	local idMap     = data[2]
	local dimension = getElementDimension( source )
	local skinID    = getElementModel( source )
	respawnInDuelMap ( source, idMap, dimension, skinID )
end
addEventHandler ( "onPlayerSpawn", getRootElement(), onSpawn )
function controlsPlayers( player, thePlayer, bool )
	toggleAllControls( player, bool )
	toggleAllControls( thePlayer, bool )
end

function playPlayerSound( player, thePlayer, sound )
	triggerClientEvent( player, "playtheSound", player, sound )
	triggerClientEvent( thePlayer, "playtheSound", thePlayer, sound )
end

function removePlayersFromVehicle( player, thePlayer )
	local isInVeh1 = getPedOccupiedVehicle( player )
	if isInVeh1 then
		removePedFromVehicle( player )
	end

	local isInVeh2 = getPedOccupiedVehicle( thePlayer )
	if isInVeh2 then
		removePedFromVehicle( thePlayer )
	end
end


local objectMaps = { }
function createMapForDimension( idMap, dimension )
	
	if objectMaps["dimension_"..tostring( dimension )] then
		destroyObjectsInDimension( dimension )
	else
		objectMaps["dimension_"..tostring( dimension )] = { }
	end

	for i,v in ipairs(mapsObjects[idMap]) do
		
		local model = v[1]
		local x     = v[2]
		local y     = v[3]
		local z     = v[4]
		local rotx  = v[5]
		local roty  = v[6]
		local rotz  = v[7]
		local objet = createObject( model, x, y, z-1, rotx, roty, rotz )
		setElementDimension( objet, dimension )
		table.insert( objectMaps["dimension_"..tostring( dimension )], objet )
	end

end

function destroyObjectsInDimension( dimension )
	
	for i,ob in ipairs( ( objectMaps["dimension_"..tostring( dimension )] or { }  ) ) do
			
		if isElement( ob ) then
			destroyElement( ob )
		end

	end

	objectMaps["dimension_"..tostring( dimension )] = nil

end

function respawnInDuelMap( player, idMap, dimension, skinID )
	
	local coords = mapsSpawns[idMap][math.random( 1, #mapsSpawns[idMap] )]
	local x      = coords[1]
	local y      = coords[2]
	local z      = coords[3]
	setElementPosition ( player, x, y, z)
	setElementDimension( player, dimension )
	giveDefaultWeapons( player )
	if isPedDead( player ) then
		respawnInDuelMap2( player, idMap, dimension, skinID )
	end
end

function respawnInDuelMap2( player, idMap, dimension, skinID )
	
	local coords = mapsSpawns[idMap][math.random( 1, #mapsSpawns[idMap] )]
	local x      = coords[1]
	local y      = coords[2]
	local z      = coords[3]

	spawnPlayer( player, x, y, z, 0, skinID, 0, dimension )
	giveDefaultWeapons( player )
end

function giveDefaultWeapons( player )
	takeAllWeapons( player )
	giveWeapon( player, 31, 99999, true )
	giveWeapon( player, 26, 99999 )
end


function findDimensionForMap( idMap )
	if idMap == 1 then
		local dimension = finD ( 100 )
		return dimension
	elseif idMap == 2 then
		local dimension = finD ( 200 )
		return dimension
	elseif idMap == 3 then
		local dimension = finD ( 300 )
		return dimension		
	elseif idMap == 4 then
		local dimension = finD ( 400 )
		return dimension
	elseif idMap == 5 then
		local dimension = finD ( 500 )
		return dimension
	elseif idMap == 6 then
		local dimension = finD ( 600 )
		return dimension
	elseif idMap == 7 then
		local dimension = finD ( 700 )
		return dimension
	elseif idMap == 8 then
		local dimension = finD ( 800 )
		return dimension
	end
end

function finD( start )
	local count = 0
	local bool = false
	while bool == false do
		if count < 100 then
			count = count + 1
		else
			bool = true
		end
		local b = false
		for i, player in ipairs( getElementsByType( "player") ) do
			if getElementDimension( player ) == ( count + start ) then
				b = true
				break
			end
		end
		if not b then
			bool = true
		end
	end
	return count + start

end

function isInDuel( player )
	
	local bool = getElementData( player, "playingDuel" )	

	if bool then
		return true
	end
	return false
end

 

link de descarga: https://mega.nz/#!JuY3UKiI!IeYNbel4Ll0pUS5jCx6t0D_ixdZH3NWzNl6KcQL89IE

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.