mtasa-blue icon indicating copy to clipboard operation
mtasa-blue copied to clipboard

Serverside for SetPedControlState

Open sparrow-spw opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe.

In Client, you can make NPCs press or release certain buttons to do actions. You can't do it on server since its only client-sided.

Describe the solution you'd like

Making SetPedControlState a shared function.

Describe alternatives you've considered

No response

Additional context

https://wiki.multitheftauto.com/wiki/SetPedControlState

Security Policy

  • [x] I have read and understood the Security Policy and this issue is not about a cheat or security vulnerability.

sparrow-spw avatar Nov 26 '22 16:11 sparrow-spw

If someone wants to add this I don't see an issue, but this can be achieved easily in Lua without (m)any tradeoffs compared to a 'native' shared function.

Server code

triggerClientEvent(players, "onPlayerRPC", resourceRoot, "setPedControlState", ped, "fire", true)

Client code

function handleRPC(proc, ...)
    local func = _G[proc]

    if (type(func) ~= "function") then
        return
    end

    func(unpack({...}))
end
addEvent("onPlayerRPC", true)
addEventHandler("onPlayerRPC", resourceRoot, handleRPC)

You can now also use this for any other function which is available on client, but not server. If you needed the return value it could be achieved with a secondary event back to the server and the use of a callback function. Of course, this is where a native shared function serves a better purpose.

Lpsd avatar Nov 26 '22 17:11 Lpsd

If someone wants to add this I don't see an issue, but this can be achieved easily in Lua without (m)any tradeoffs compared to a 'native' shared function.

Server code

triggerClientEvent(players, "onPlayerRPC", resourceRoot, "setPedControlState", ped, "fire", true)

Client code

function handleRPC(proc, ...)
    local func = _G[proc]

    if (type(func) ~= "function") then
        return
    end

    func(unpack({...}))
end
addEvent("onPlayerRPC", true)
addEventHandler("onPlayerRPC", resourceRoot, handleRPC)

You can now also use this for any other function which is available on client, but not server. If you needed the return value it could be achieved with a secondary event back to the server and the use of a callback function. Of course, this is where a native shared function serves a better purpose.

You only have to send it to whichever player is being returned by getElementSyncer even. Very easy to implement yourself but I do agree that it's nice to have on the server nevertheless.

MegadreamsBE avatar Nov 26 '22 23:11 MegadreamsBE