Jump to content

Player Control


Try

Recommended Posts

Posted

Heyo Guys! Im back,

Im trying to make a script for control other peoples like /control then the camera fade at people and u can control, and he cant move,

I tryed to make:

I used this functions

- setPedControlState ( ped thePed, string control, bool state )

- setCameraTarget ( player thePlayer, [ element target ] )

Thanks for the Help,

Maria.

Posted
function control(player, commandName, name) 
setPedControlState ( name, WHAT I PUT HERE, AND HERE? ) 
setCameraTarget ( MY NAME, name ) 
end 
addCommandHandler("control",control) 

but i need know then how i can back

Posted (edited)

you need to bind one player's key serverside, then send the keystate to the client of 2nd player, to setPedControlState for the player clientside.

Edited by Guest
Posted

I asking for help not for enter at a server

_______

Someone can help me please

I don't understant what u sais karlis

Posted
I asking for help not for enter at a server

_______

Someone can help me please

I don't understant what u sais karlis

he just want to show/explain in the server

and i already described it pretty plain, its too long for me to write it for you.

Posted

karlis don't need bind with setPedControlState u can control the guy with the normal keys

but im trying to make the code but its not workkiiingg

Posted
karlis don't need bind with setPedControlState u can control the guy with the normal keys

but im trying to make the code but its not workkiiingg

facepalm.jpg

Posted (edited)

Haha, yeah.

Here is some code I made for you which apparently does not fully work in MTA 1.1 (trololo).

Stuff it into a resource and do

/control *playername*

/cancelcontrol

Try_client.lua

local controlSessions = {}; 
local forwardControls = { 
    "fire", 
    "next_weapon", 
    "previous_weapon", 
    "forwards", 
    "backwards", 
    "left", 
    "right", 
    "zoom_in", 
    "zoom_out", 
    "change_camera", 
    "jump", 
    "sprint", 
    "look_behind", 
    "crouch", 
    "action", 
    "walk", 
    "aim_weapon", 
    "conversation_yes", 
    "conversation_no", 
    "group_control_forwards", 
    "group_control_back", 
    "enter_exit", 
    "vehicle_fire", 
    "vehicle_secondary_fire", 
    "vehicle_left", 
    "vehicle_right", 
    "steer_forward", 
    "steer_back", 
    "accelerate", 
    "brake_reverse", 
    "radio_next", 
    "radio_previous", 
    "radio_user_track_skip", 
    "horn", 
    "sub_mission", 
    "handbrake", 
    "vehicle_look_left", 
    "vehicle_look_right", 
    "vehicle_look_behind", 
    "vehicle_mouse_look", 
    "special_control_left", 
    "special_control_right", 
    "special_control_down", 
    "special_control_up" 
}; 
local remoteControlStates = {}; 
local remoteMatrix = {}; 
local controlling = false; 
  
function clearControlStates() 
     for m,n in ipairs(forwardControls) do 
        remoteControlStates[n] = false; 
     end 
  
    triggerServerEvent("onControlReset", controlling); 
    return true; 
end 
  
addEvent("onClientControlAttach", true); 
addEventHandler("onClientControlAttach", getRootElement(), function(controller) 
        outputDebugString(getPlayerName(source) .. " is being controlled by " .. getPlayerName(controller)); 
  
        if (controller == getLocalPlayer()) then 
            controlling = source; 
  
            setCameraTarget(source); 
  
            clearControlStates(); 
  
            remoteMatrix = {}; 
            return true; 
        end 
  
        if not (source == getLocalPlayer()) then return true; end; 
  
        for m,n in ipairs(forwardControls) do 
            --toggleControl(n, false); 
        end 
    end 
); 
  
addEvent("onClientControlDetach", true); 
addEventHandler("onClientControlDetach", getRootElement(), function() 
        outputDebugString(getPlayerName(source) .. " has been given back control"); 
  
        if (source == controlling) then 
            controlling = false; 
            return true; 
        end 
  
        if not (source == getLocalPlayer()) then return true; end; 
  
        for m,n in ipairs(forwardControls) do 
            --toggleControl(n, true); 
        end 
  
        setCameraTarget(getLocalPlayer()); 
    end 
); 
  
addEvent("onClientControlReset", true); 
addEventHandler("onClientControlReset", getRootElement(), function() 
        local m,n; 
  
        for m,n in ipairs(forwardControls) do 
            setControlState(n, false); 
        end 
    end 
); 
  
addEvent("onClientControlStateUpdate", true); 
addEventHandler("onClientControlStateUpdate", getRootElement(), function(state, active) 
        setControlState(state, active); 
    end 
); 
  
addEvent("onClientControlMatrixUpdate", true); 
addEventHandler("onClientControlMatrixUpdate", getRootElement(), function(matrix) 
         setCameraMatrix(unpack(matrix)); 
    end 
); 
  
addEventHandler("onClientPreRender", getRootElement(), function() 
        if not (controlling) then return true; end; 
  
        -- Emulate vehicle controls 
        if (isPedInVehicle(controlling)) and not (isPedInVehicle(getLocalPlayer())) then 
            if not (remoteControlStates["accelerate"] == getControlState("forwards")) then 
                remoteControlStates["accelerate"] = getControlState("forwards"); 
  
                triggerServerEvent("onControlStateUpdate", controlling, "accelerate", getControlState("forwards")); 
            end 
        end 
  
        local m,n; 
  
        for m,n in ipairs(forwardControls) do 
            if not (getControlState(n) == remoteControlStates[n]) then 
                remoteControlStates[n] = getControlState(n); 
  
                triggerServerEvent("onControlStateUpdate", controlling, n, getControlState(n)); 
            end 
        end 
  
        local newMatrix = { getCameraMatrix() }; 
  
        if not (remoteMatrix == newMatrix) then 
            remoteMatrix = newMatrix; 
  
            triggerServerEvent("onControlMatrixUpdate", controlling, remoteMatrix); 
        end 
    end 
); 
  
addCommandHandler("control", function(command, name) 
        if not (name) then return false; end; 
  
        local player = getPlayerFromName(name); 
  
        if not (player) then 
            outputChatBox(name .. " player not found"); 
            return false; 
        end 
  
        if (player == getLocalPlayer()) then 
            outputChatBox("You cannot remote control yourself!"); 
            return false; 
        end 
  
        triggerServerEvent("onControlRequest", player); 
    end 
); 
  
addCommandHandler("cancelcontrol", function(command) 
        if not (controlling) then return false; end; 
  
        triggerServerEvent("onControlCancel", controlling); 
  
        setCameraTarget(getLocalPlayer()); 
    end 
); 

Try_server.lua

local playerData = {}; 
  
function initPlayer(player) 
    local data = { 
        controlledBy = false 
    }; 
  
    playerData[player] = data; 
    return true; 
end 
  
local m,n; 
local ap = getElementsByType("player"); 
  
for m,n in ipairs(ap) do 
    initPlayer(n); 
end 
  
addEventHandler("onPlayerJoin", getRootElement(), function() 
        initPlayer(source); 
    end 
); 
  
function attachControl(control, controller) 
    local pData = playerData[controller]; 
    local controlData = playerData[control]; 
  
    if (control == controller) then return false; end; 
  
    if (controlData.controlledBy == controller) then 
        return true; 
    elseif (controlData.controlledBy) then 
        return false; 
    end 
  
    if (pData.control) then 
        detachControl(pData.control); 
    end 
  
    pData.control = control; 
    controlData.controlledBy = controller; 
  
    triggerClientEvent("onClientControlAttach", control, controller); 
    return true; 
end 
  
function detachControl(control) 
    local pData = playerData[control]; 
  
    if not (pData.controlledBy) then return true; end; 
  
    local controllerData = playerData[pData.controlledBy]; 
  
    controllerData.control = false; 
    pData.controlledBy = false; 
  
    triggerClientEvent("onClientControlDetach", control); 
    return true; 
end 
  
addEvent("onControlRequest", true); 
addEventHandler("onControlRequest", getRootElement(), function() 
        local pData = playerData[client]; 
  
        attachControl(source, client); 
    end 
); 
  
addEvent("onControlCancel", true); 
addEventHandler("onControlCancel", getRootElement(), function() 
        local pData = playerData[client]; 
  
        if not (pData.control == source) then return false; end; 
  
        detachControl(pData.control); 
   end 
); 
  
addEvent("onControlStateReset", true); 
addEventHandler("onControlStateReset", getRootElement(), function() 
        local pData = playerData[client]; 
  
        if not (pData.control == source) then 
            -- HAX 
            kickPlayer(client); 
            return false; 
        end 
  
        triggerClientEvent(source, "onClientControlStateReset", getRootElement()); 
    end 
); 
  
addEvent("onControlStateUpdate", true); 
addEventHandler("onControlStateUpdate", getRootElement(), function(state, active) 
        local pData = playerData[client]; 
  
        if not (pData.control == source) then 
            -- HAX 
            kickPlayer(client); 
            return false; 
        end 
  
        triggerClientEvent(source, "onClientControlStateUpdate", getRootElement(), state, active); 
    end 
); 
  
addEvent("onControlMatrixUpdate", true); 
addEventHandler("onControlMatrixUpdate", getRootElement(), function(matrix) 
        local pData = playerData[client]; 
  
        if not (pData.control == source) then 
            -- HAX 
            kickPlayer(client); 
            return false; 
        end 
  
        triggerClientEvent(source, "onClientControlMatrixUpdate", getRootElement(), matrix); 
    end 
); 
  
addEventHandler("onPlayerQuit", getRootElement(), function() 
        local pData = playerData[source]; 
  
        if (pData.control) then 
            detachControl(pData.control); 
        end 
  
        if (pData.controlledBy) then 
            detachControl(source); 
        end 
    end 
); 

Feel free to expand it.

I did not add a camera control for the controlled player, maybe you can do that.

Edited by Guest
Posted

The_GTA

Thanks

but when im controling the people get frezed?

and where i add the setCameraTarget and how i add

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...