Jump to content

Usefull code, advanced onClientPlayerWeaponSwitch event.


IIYAMA

Recommended Posts

  • Moderators

This is not a request!!!

Custom onClientPlayerWeaponSwitch event which will now trigger for all players, instead only for the localPlayer.

Use it like you want...

So:

[b]Source[/b] 
The source of this event is the player who changed his weapon. [strike](Local player only)[/strike]  

Example:

addEventHandler ( "onClientPlayerWeaponSwitch",root, 
function ( prevSlot, newSlot, custom) 
    outputDebugString (prevSlot .. ", " .. newSlot .. " " .. tostring(custom)) 
end) 

Source code.

local playerDataBase = {} 
  
addEventHandler("onClientResourceStart",resourceRoot, 
function () 
    local allPlayers = getElementsByType("player") 
    for i=1,#allPlayers do 
        local player = allPlayers[i] 
        if player ~= localPlayer then 
            local slot = getPedWeaponSlot ( player ) 
            playerDataBase[player] = slot 
        end 
    end 
end) 
  
addEventHandler("onClientPlayerJoin",root, 
function () 
    playerDataBase[source] = getPedWeaponSlot (source) 
end) 
  
  
addEventHandler("onClientRender",root, 
function () 
    for player,oldSlot in pairs(playerDataBase) do 
        if isElement(player) then 
            local newSlot = getPedWeaponSlot ( player )  
            if oldSlot ~= newSlot then 
                triggerEvent("onClientPlayerWeaponSwitch",player,oldSlot,newSlot,true) 
                playerDataBase[player] = newSlot 
            end 
        else 
            playerDataBase[player] = nil 
        end 
    end 
end) 
  

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