Jump to content

¿Es posible hacer éste script?


xSrTorino

Recommended Posts

Hola, Buenas tardes, tengo un problema al editar dos scripts (de la comunidad) lo cual es que un script de Drone, (lo cuál lo puedes manejar y por un panel al costado de la pantalla se ve dicho vehículo) lo que sí, el player no sube al vehículo, mi idea es que: Al usar ese Drone para poder espiar a players y a través de un bindKey lanze misiles , ahora el problema; el otro script que sólo si te subes a dicho vehículo puedes usar esas funciones, se podría hacer eso sin poder entrar al vehículo?

Desde ya, muchísimas gracias, espero sus respuestas!

Link to comment
5 minutes ago, xSrTorino said:

Hola, Buenas tardes, tengo un problema al editar dos scripts (de la comunidad) lo cual es que un script de Drone, (lo cuál lo puedes manejar y por un panel al costado de la pantalla se ve dicho vehículo) lo que sí, el player no sube al vehículo, mi idea es que: Al usar ese Drone para poder espiar a players y a través de un bindKey lanze misiles , ahora el problema; el otro script que sólo si te subes a dicho vehículo puedes usar esas funciones, se podría hacer eso sin poder entrar al vehículo?

Desde ya, muchísimas gracias, espero sus respuestas!

O sea, ¿ tú quieres que el dron lanze misiles ?

Link to comment

Pues es fácil, solo debes tomar la posición del dron ( dependiendo si es un vehiculo/moto/aeronave con una textura reemplazada ) y debes usar las siguientes funciones


function dronpro()
	local vehicle = getPedOccupiedVehicle(localPlayer) -- Detecta el modelo del vehiculo ( que vendria siendo el dron ).
	if(vehicle)then -- Detecta si el jugador está manejando el dron.
		local x, y, z = getElementPosition(vehicle) --Toma la posición del dron.
		createProjectile(vehicle, 19, x, y + 2, z) --Crea el proyectil en frente del dron.
	end
end

bindKey("tecla", "down", donpro) -- La bindKey ( debes reemplazar "tecla" por el boton que desees usar para disparar los proyectiles )

 

Link to comment

No me funcionó

Client

Quote

function moveDrone(key, por)
    if keys[key] then
        triggerServerEvent ("drone.ctrl", localPlayer, entity.ped, keys[key], por);
    end    
end

function stopDrone()
    triggerServerEvent ("drone.stop", localPlayer);
end

function toggleDroneCamera()
    camera = not camera;
end    

function startDrone(drone, ped)
    entity.drone = drone;
    entity.ped = ped;
    addEventHandler ("onClientPreRender", root, checkDrone);
    addEventHandler ("onClientKey", root, moveDrone);
    bindKey ("fire", "down", toggleDroneCamera);
end

addEvent ("drone.ctrl_c", true);
addEventHandler ("drone.ctrl_c", root, 
    function (ped, ctrl, state)
        if not isElement (ped) then return; end
        setPedControlState (ped, ctrl, state);
    end
);    

addEvent ("drone.start", true);
addEventHandler ("drone.start", root,
    function (drone, ped)
        startDrone(drone, ped);
        setPlayerHudComponentVisible ("radar", false)
    end
);    

function terminateDroneOptions()
    removeEventHandler ("onClientKey", root, moveDrone);
    removeEventHandler ("onClientPreRender", root, checkDrone);
    mfx = nil;
    setCameraTarget (localPlayer);
    setPlayerHudComponentVisible ("radar", true)
    toggleAllControls(true);
    unbindKey ("fire", "down", toggleDroneCamera);
    for i, v in ipairs (getElementsByType"player") do 
        setPlayerNametagShowing(v, true);
    end    
end    
addEventHandler ("onClientResourceStop", resourceRoot, terminateDroneOptions);
addEvent ("drone.stop", true)
addEventHandler ("drone.stop", root, terminateDroneOptions);

addEventHandler ("onClientResourceStart", resourceRoot, 
    function ()
        local txd = engineLoadTXD ("files/drone.txd");
        engineImportTXD(txd, 501);
        local dff = engineLoadDFF ("files/drone.dff");
        engineReplaceModel(dff, 501);
    end
);    

function dronpro()
    local vehicle = getPedOccupiedVehicle(localPlayer) -- Detecta el modelo del vehiculo ( que vendria siendo el dron ).
    if(vehicle)then -- Detecta si el jugador está manejando el dron.
        local x, y, z = getElementPosition(vehicle) --Toma la posición del dron.
        createProjectile(vehicle, 19, x, y + 2, z) --Crea el proyectil en frente del dron.
    end
end

bindKey("x", "down", donpro) -- La bindKey ( debes reemplazar "tecla" por el boton que desees usar para disparar los proyectiles )


 

 

Server:

Quote

function loadSettingsRecursively(node, cache)
    local cache = cache or {};
    
    for i, child in ipairs (xmlNodeGetChildren (node)) do 
        local nodeName = xmlNodeGetName (child);
        local prefix = xmlNodeGetAttribute (child, "prefix");
        if nodeName ~= "group" then             
            local value = xmlNodeGetAttribute (child, "value");
            if prefix then 
                cache[prefix] = value;
            else
                cache = value;
            end    
        else
            cache[prefix] = {};
            loadSettingsRecursively(child, cache[prefix]);
        end
    end
    return cache;
end

local config = xmlLoadFile("config/settings.xml");
local settings = loadSettingsRecursively(config);
xmlUnloadFile(config)

local msg = settings.msg;
local gm = settings.main.gm == "Cnr" and "Freeroam" or "RolePlay";

local players = {};
local valid_models = {
    [501] = "Drone",
    [465] = "Oyuncak Helikopter 2",
    [464] = "Drone",
};

function startDrone(player, id)
    if players[player] then 
        errMsg (msg.ALREADY_HAS_DRONE:format("droned"), player);
        return;
    end    
    players[player] = {};
    local x,y,z = getElementPosition(player)
    local drone = createVehicle(id, x+1.5, y+1.5, z)
    local ped = createPed(180, x+1.5, y+1.5, z)
    players[player].drone = drone;
    players[player].ped = ped
    setElementAlpha(ped, 0)
    warpPedIntoVehicle(ped, drone)
    giveWeapon(player, 40, 1, true)
    triggerClientEvent(player, "drone.start", resourceRoot, drone, ped)
    setPedAnimation(player, "CAMERA", "camstnd_lkabt",-1, false, false, false, true)
    toggleAllControls (player, false, true, false);
    addEventHandler ("onVehicleExplode", drone, function () stopDrone(player) end);    
    addEventHandler ("onElementDestroy", drone, function () stopDrone(player) end);
end

function stopDrone(player)
    if not players[player] then return false; end
    local ped = players[player].ped;
    local drone = players[player].drone;
    
    if isElement (drone) and isElement (ped) and eventName ~= "onElementDestroy" then 
        drone:destroy();
        ped:destroy();    
    end    
    takeWeapon(player, 40);
    player:setAnimation();
    if eventName ~= "onResourceStop" then 
        triggerClientEvent (player, "drone.stop", player);
    end    
    players[player] = nil;
end

function droneHelp(player)
    if gm == "CnR" then 
        output (msg.HELP_CMD_START, player);
        output (msg.HELP_CMD_STOP, player);
        output (msg.HELP_VALID_MODEL_TEXT, player);
        for i, v in pairs (valid_models) do 
            output (msg.HELP_VALID_MODELS:format(i, v), player);
        end
    else
        --gui
    end    
end

addCommandHandler ("droneke", 
    function (player)
        droneHelp(player);
    end
);    

addCommandHandler ("drone",
    function (player, cmd, ...)
        local id = arg[1] or 501;
        if tonumber (id) then 
            id=tonumber(id);
            if valid_models[id] then 
                startDrone (player, id);
            else
                errMsg (msg.INVALID_ID, player);
            end
        else
            errMsg (msg.INVALID_ID, player);
        end
    end
);    

addCommandHandler ("nodrone",
    function (player)
        if players[player] then 
            stopDrone(player);
        end
    end
);    

addEvent ("drone.stop", true);
addEvent ("drone.ctrl", true);

addEventHandler ("drone.ctrl", root, 
    function (ped, ctrl, state)
        triggerClientEvent (root, "drone.ctrl_c", resourceRoot, ped, ctrl, state);
    end
);

addEventHandler ("drone.stop", root, 
    function ()
        stopDrone(client);
    end
);    

addEventHandler ("onResourceStop", resourceRoot,
    function ()
        for i in pairs (players) do 
            stopDrone(i);
        end
    end
);    

addEventHandler ("onPlayerQuit", root, 
    function ()
        stopDrone(source);
    end
);    

addEventHandler ("onPlayerWasted", root, 
    function ()
        stopDrone(source);
    end
);

function errMsg(msg_, player)
    return outputChatBox(msg_, player, 255, 0, 0, true);
end    

function output(msg_, player)
    return outputChatBox(msg_, player, 255, 255, 255, true);
end    

 

Por si necesitas el GUI, me avisas.xD
Link to comment
--CLIENT
function loadSettingsRecursively(node, cache)
    local cache = cache or {};
    
    for i, child in ipairs (xmlNodeGetChildren (node)) do 
        local nodeName = xmlNodeGetName (child);
        local prefix = xmlNodeGetAttribute (child, "prefix");
        if nodeName ~= "group" then             
            local value = xmlNodeGetAttribute (child, "value");
            if prefix then 
                cache[prefix] = value;
            else
                cache = value;
            end    
        else
            cache[prefix] = {};
            loadSettingsRecursively(child, cache[prefix]);
        end
    end
    return cache;
end

local config = xmlLoadFile("config/settings.xml");
local settings = loadSettingsRecursively(config);
xmlUnloadFile(config)

local msg = settings.msg;
local gm = settings.main.gm == "Cnr" and "Freeroam" or "RolePlay";

local players = {};
local valid_models = {
    [501] = "Drone",
    [465] = "Oyuncak Helikopter 2",
    [464] = "Drone",
};

function startDrone(player, id)
    if players[player] then 
        errMsg (msg.ALREADY_HAS_DRONE:format("droned"), player);
        return;
    end    
    players[player] = {};
    local x,y,z = getElementPosition(player)
    local drone = createVehicle(id, x+1.5, y+1.5, z)
    local ped = createPed(180, x+1.5, y+1.5, z)
    players[player].drone = drone;
    players[player].ped = ped
    setElementAlpha(ped, 0)
    warpPedIntoVehicle(ped, drone)
    giveWeapon(player, 40, 1, true)
	bindKey ( player, "x", "down", dronpro )
    triggerClientEvent(player, "drone.start", resourceRoot, drone, ped)
    setPedAnimation(player, "CAMERA", "camstnd_lkabt",-1, false, false, false, true)
    toggleAllControls (player, false, true, false);
    addEventHandler ("onVehicleExplode", drone, function () stopDrone(player) end);    
    addEventHandler ("onElementDestroy", drone, function () stopDrone(player) end);
end

function dronpro(player)
triggerClientEvent(player, "onDronProject", player)
end



function stopDrone(player)
    if not players[player] then return false; end
    local ped = players[player].ped;
    local drone = players[player].drone;
    
    if isElement (drone) and isElement (ped) and eventName ~= "onElementDestroy" then 
        drone:destroy();
        ped:destroy();    
    end    
    takeWeapon(player, 40);
    player:setAnimation();
    if eventName ~= "onResourceStop" then 
        triggerClientEvent (player, "drone.stop", player);
    end    
    players[player] = nil;
end

function droneHelp(player)
    if gm == "CnR" then 
        output (msg.HELP_CMD_START, player);
        output (msg.HELP_CMD_STOP, player);
        output (msg.HELP_VALID_MODEL_TEXT, player);
        for i, v in pairs (valid_models) do 
            output (msg.HELP_VALID_MODELS:format(i, v), player);
        end
    else
        --gui
    end    
end

addCommandHandler ("droneke", 
    function (player)
        droneHelp(player);
    end
);    

addCommandHandler ("drone",
    function (player, cmd, ...)
        local id = arg[1] or 501;
        if tonumber (id) then 
            id=tonumber(id);
            if valid_models[id] then 
                startDrone (player, id);
            else
                errMsg (msg.INVALID_ID, player);
            end
        else
            errMsg (msg.INVALID_ID, player);
        end
    end
);    

addCommandHandler ("nodrone",
    function (player)
        if players[player] then 
            stopDrone(player);
        end
    end
);    

addEvent ("drone.stop", true);
addEvent ("drone.ctrl", true);

addEventHandler ("drone.ctrl", root, 
    function (ped, ctrl, state)
        triggerClientEvent (root, "drone.ctrl_c", resourceRoot, ped, ctrl, state);
    end
);

addEventHandler ("drone.stop", root, 
    function ()
        stopDrone(client);
    end
);    

addEventHandler ("onResourceStop", resourceRoot,
    function ()
        for i in pairs (players) do 
            stopDrone(i);
        end
    end
);    

addEventHandler ("onPlayerQuit", root, 
    function ()
        stopDrone(source);
    end
);    

addEventHandler ("onPlayerWasted", root, 
    function ()
        stopDrone(source);
    end
);

function errMsg(msg_, player)
    return outputChatBox(msg_, player, 255, 0, 0, true);
end    

function output(msg_, player)
    return outputChatBox(msg_, player, 255, 255, 255, true);
end    


--SERVER

function moveDrone(key, por)
    if keys[key] then
        triggerServerEvent ("drone.ctrl", localPlayer, entity.ped, keys[key], por);
    end    
end

function stopDrone()
    triggerServerEvent ("drone.stop", localPlayer);
end

function toggleDroneCamera()
    camera = not camera;
end    

function startDrone(drone, ped)
    entity.drone = drone;
    entity.ped = ped;
    addEventHandler ("onClientPreRender", root, checkDrone);
    addEventHandler ("onClientKey", root, moveDrone);
    bindKey ("fire", "down", toggleDroneCamera);
end

addEvent ("drone.ctrl_c", true);
addEventHandler ("drone.ctrl_c", root, 
    function (ped, ctrl, state)
        if not isElement (ped) then return; end
        setPedControlState (ped, ctrl, state);
    end
);    

addEvent ("drone.start", true);
addEventHandler ("drone.start", root,
    function (drone, ped)
        startDrone(drone, ped);
        setPlayerHudComponentVisible ("radar", false)
    end
);    

function terminateDroneOptions()
    removeEventHandler ("onClientKey", root, moveDrone);
    removeEventHandler ("onClientPreRender", root, checkDrone);
    mfx = nil;
    setCameraTarget (localPlayer);
    setPlayerHudComponentVisible ("radar", true)
    toggleAllControls(true);
    unbindKey ("fire", "down", toggleDroneCamera);
    for i, v in ipairs (getElementsByType"player") do 
        setPlayerNametagShowing(v, true);
    end    
end    
addEventHandler ("onClientResourceStop", resourceRoot, terminateDroneOptions);
addEvent ("drone.stop", true)
addEventHandler ("drone.stop", root, terminateDroneOptions);

addEventHandler ("onClientResourceStart", resourceRoot, 
    function ()
        local txd = engineLoadTXD ("files/drone.txd");
        engineImportTXD(txd, 501);
        local dff = engineLoadDFF ("files/drone.dff");
        engineReplaceModel(dff, 501);
    end
);    

function dronpro()
local vehicle = getPedOccupiedVehicle(localPlayer)
local x, y, z = getElementPosition(vehicle) --Toma la posición del dron.
createProjectile(vehicle, 19, x, y + 2, z) --Crea el proyectil en frente del dron.
end
addEvent("onDronProject", true)
addEventHandler("onDronProject", root, dronpro)

 

Link to comment

Agregá esto en client-side:

addEvent("fireDrone", true)
addEventHandler("fireDrone", root,
	function(vehicle)
		if entity.drone then
			local x, y, z = getElementPosition(vehicle)
			--local rx, ry, rz = getElementRotation(vehicle)
			if (not createProjectile(localPlayer, 20, x, y, z-2)) then
				outputChatBox("Fire drone!")
			end
		end
	end
)

Y esto en server-side:

function fireDrone(player)
	if players[player] then
		triggerClientEvent(player, "fireDrone", player, players[player].drone)
	end
end

Y reemplazá la función 'startDrone' en 'server.lua' por esta:

function startDrone(player, id)
	if players[player] then 
		errMsg (msg.ALREADY_HAS_DRONE:format("droned"), player);
		return;
	end	
	players[player] = {};
	local x,y,z = getElementPosition(player)
	local drone = createVehicle(id, x+1.5, y+1.5, z)
	local ped = createPed(180, x+1.5, y+1.5, z)
	players[player].drone = drone;
	players[player].ped = ped
	setElementAlpha(ped, 0)
	warpPedIntoVehicle(ped, drone)
	giveWeapon(player, 40, 1, true)
	triggerClientEvent(player, "drone.start", resourceRoot, drone, ped)
	setPedAnimation(player, "CAMERA", "camstnd_lkabt",-1, false, false, false, true)
	toggleAllControls (player, false, true, false);
	addEventHandler ("onVehicleExplode", drone, function () stopDrone(player) end);	
	addEventHandler ("onElementDestroy", drone, function () stopDrone(player) end);
	bindKey(player, "X", "down", fireDrone)
end


Con la tecla "x" disparas :b

(Y la próxima vez postea tus dudas en esta sección: https://forum.multitheftauto.com/forum/166-spanish-español/)

Edited by #Dv^
Link to comment

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.
×
×
  • Create New...