Jump to content

Event System Function


xeon17

Recommended Posts

Hello , i want to create a command for my event system but i have problems with client side of script.

So when a player enter the event he have the ElementData ''Evento'' and i wanted for every player in event to delete his fire with hands , so he can't attact with hands if he have elementdata ''soco''

but the client side dosen't work.

--Server

function AntiSoco ( thePlayer ) 
    -- check player 
    if not (isAllownedPlayer(thePlayer)) then 
        return 
    end 
    local list9 = 0 
    for _, player in ipairs(getElementsByType("player")) do 
        local isPlayerInEvento = getElementData( player, "Evento" ) 
        if ( isPlayerInEvento) then 
         setElementData(player, "soco", true) 
            outputChatBox("#FFF000[EVENTO]#FFFFFF "..getPlayerName(thePlayer).." Deleted your hands",player, 255, 255, 255, true) 
             list9 = list9 + 1 
        end 
    end 
            outputChatBox("#FFF000[EVENTO]#FFFFFF You deleted soco of  "..list9.." players,", thePlayer, 255, 255, 255, true) 
 end 
addCommandHandler ("tirarsoco",AntiSoco) 

--Client

function onClientPlayerWeaponFireFunc(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement ) 
    if weapon == 0 and getElementType(hitElement)=="player" and getElementData( hitElement, "soco" ) then 
    cancelEvent () 
    end 
end 
addEventHandler ( "onClientPlayerWeaponFire", getLocalPlayer(), onClientPlayerWeaponFireFunc ) 

Link to comment

---Client

addEventHandler ( "onClientPlayerWeaponFire",root, 
function ( weapon ) 
    if ( weapon == 0 ) and ( getElementData ( localPlayer, 'soco' == true )) then 
    cancelEvent ( ) 
 end 
end 
) 

---server

addCommandHandler ("tirarsoco", 
function ( ) 
for _ , v in ipairs  ( getElementsByType ('player' )) do 
if not (isAllownedPlayer(v)) then return end 
local list9 = 0 
local isPlayerInEvento = getElementData( v, "Evento" ) 
        if ( isPlayerInEvento) then 
         setElementData(v, "soco", true) 
         outputChatBox("#FFF000[EVENTO]#FFFFFF "..getPlayerName(source).." Deleted your hands",source, 255, 255, 255, true) 
             list9 = list9 + 1 
        end 
    end 
     outputChatBox("#FFF000[EVENTO]#FFFFFF You deleted soco of  "..list9.." players,", source, 255, 255, 255, true) 
 end 
 ) 

if it didn't work then show me this side of script

if not (isAllownedPlayer(player)) then return end 
local list9 = 0 
local isPlayerInEvento = getElementData( v, "Evento" ) 
        if ( isPlayerInEvento) then 
Edited by Guest
Link to comment

Sorry for so much double posts ._. but i'll explain everything better now

When the player enter event he have the elementdata ''Evento'' and with this command i check have players elementdata ''Evento'' the players who have will get a new elementdata ''soco'' and when a player fire with hands ( fist ) weapon id : 0

then he can't because he have the elementdata ''soco''

my first code worked good ( server side ) but the problem is in client side i think..

Link to comment
---Client

addEventHandler ( "onClientPlayerWeaponFire",root, 
function ( weapon ) 
    if ( weapon == 0 ) and ( getElementData ( localPlayer, 'soco' == true )) then 
    cancelEvent ( ) 
 end 
end 
) 

---server

addCommandHandler ("tirarsoco", 
function ( ) 
for _ , v in ipairs  ( getElementsByType ('player' )) do 
if not (isAllownedPlayer(v)) then return end 
local list9 = 0 
local isPlayerInEvento = getElementData( v, "Evento" ) 
        if ( isPlayerInEvento) then 
         setElementData(v, "soco", true) 
         outputChatBox("#FFF000[EVENTO]#FFFFFF "..getPlayerName(source).." Deleted your hands",source, 255, 255, 255, true) 
             list9 = list9 + 1 
        end 
    end 
     outputChatBox("#FFF000[EVENTO]#FFFFFF You deleted soco of  "..list9.." players,", source, 255, 255, 255, true) 
 end 
 ) 

It's missing ')' after 'soco' in getElementData function, you've used parentheses after comparing it with true.

Also, source is not defined in addCommandHandler function.

XeoN-, Try this:

Client

addEventHandler("onClientPlayerWeaponFire",root, 
function ( weapon ) 
    if ( weapon == 0 ) and (getElementData(localPlayer, 'soco') == true) then 
        cancelEvent ( ) 
    end 
end) 

Server

addCommandHandler("tirarsoco", 
function (sourcePlayer) 
    local list9 = 0 
    for _ , v in ipairs  ( getElementsByType ('player' )) do 
        if not (isAllownedPlayer(v)) then return end 
        local isPlayerInEvento = getElementData( v, "Evento" ) 
        if (isPlayerInEvento) then 
            setElementData(v, "soco", true) 
            outputChatBox("#FFF000[EVENTO]#FFFFFF "..getPlayerName(sourcePlayer).." Deleted your hands",root, 255, 255, 255, true) 
            list9 = list9 + 1 
            outputChatBox("#FFF000[EVENTO]#FFFFFF You deleted soco of  "..list9.." players", sourcePlayer, 255, 255, 255, true) 
        end 
    end 
end) 

Link to comment
---Client

addEventHandler ( "onClientPlayerWeaponFire",root, 
function ( weapon ) 
    if ( weapon == 0 ) and ( getElementData ( localPlayer, 'soco' == true )) then 
    cancelEvent ( ) 
 end 
end 
) 

---server

addCommandHandler ("tirarsoco", 
function ( ) 
for _ , v in ipairs  ( getElementsByType ('player' )) do 
if not (isAllownedPlayer(v)) then return end 
local list9 = 0 
local isPlayerInEvento = getElementData( v, "Evento" ) 
        if ( isPlayerInEvento) then 
         setElementData(v, "soco", true) 
         outputChatBox("#FFF000[EVENTO]#FFFFFF "..getPlayerName(source).." Deleted your hands",source, 255, 255, 255, true) 
             list9 = list9 + 1 
        end 
    end 
     outputChatBox("#FFF000[EVENTO]#FFFFFF You deleted soco of  "..list9.." players,", source, 255, 255, 255, true) 
 end 
 ) 

It's missing ')' after 'soco' in getElementData function, you've used parentheses after comparing it with true.

Also, source is not defined in addCommandHandler function.

XeoN-, Try this:

Client

addEventHandler("onClientPlayerWeaponFire",root, 
function ( weapon ) 
    if ( weapon == 0 ) and (getElementData(localPlayer, 'soco') == true) then 
        cancelEvent ( ) 
    end 
end) 

Server

addCommandHandler("tirarsoco", 
function (sourcePlayer) 
    local list9 = 0 
    for _ , v in ipairs  ( getElementsByType ('player' )) do 
        if not (isAllownedPlayer(v)) then return end 
        local isPlayerInEvento = getElementData( v, "Evento" ) 
        if (isPlayerInEvento) then 
            setElementData(v, "soco", true) 
            outputChatBox("#FFF000[EVENTO]#FFFFFF "..getPlayerName(sourcePlayer).." Deleted your hands",root, 255, 255, 255, true) 
            list9 = list9 + 1 
            outputChatBox("#FFF000[EVENTO]#FFFFFF You deleted soco of  "..list9.." players", sourcePlayer, 255, 255, 255, true) 
        end 
    end 
end) 

Ops, Thank's For telling me that .

Link to comment

I don't know if we can cancel 'onClientPlayerWeaponFire' event but in case it can't you can try this:

function dontFight(_, slot) 
    if slot == 0 and getElementData(localPlayer, "soco") then 
        toggleControl ( "fire", false ) 
    elseif slot ~= 0 and getElementData(localPlayer, "soco") then 
        toggleControl ( "fire", true) 
    else 
        toggleControl ( "fire", true) 
        removeEventHandler("onClientPlayerWeaponSwitch", root, dontFight) 
    end 
end) 
addEventHandler("onClientPlayerWeaponSwitch", root, dontFight) 

Link to comment

I tried this , but dosen't work..

addEventHandler("onClientPlayerWeaponFire",root, 
function ( weapon ) 
    if ( weapon == 0 ) and (getElementData(localPlayer, 'soco') == true) then 
     toggleControl ( "fire", false) 
     else 
     toggleControl ( "fire", true) 
    end 
end) 

Link to comment
I don't know if we can cancel 'onClientPlayerWeaponFire' event but in case it can't you can try this:
function dontFight(_, slot) 
    if slot == 0 and getElementData(localPlayer, "soco") then 
        toggleControl ( "fire", false ) 
    elseif slot ~= 0 and getElementData(localPlayer, "soco") then 
        toggleControl ( "fire", true) 
    else 
        toggleControl ( "fire", true) 
        removeEventHandler("onClientPlayerWeaponSwitch", root, dontFight) 
    end 
end) 
addEventHandler("onClientPlayerWeaponSwitch", root, dontFight) 

Dosen't work too.

Link to comment

--ClientSide

if didn't work then make it

'onClientPlayerDamage' 
and change 
 toggleControl  
to cancelEvent ( ) 

addEventHandler ( "onClientPlayerWeaponFire", root, 
function ( weapon ) 
    if ( isElement( localPlayer) ) and ( getElementType( localPlayer ) == "player" )  and ( weapon == 0 ) then 
    if (getElementData(localPlayer, 'soco') == true) then 
    toggleControl ( "fire", false ) 
    else 
    toggleControl ( "fire", true ) 
     end 
   end 
end 
) 
Link to comment

Maybe the problem is with 'isAllownedPlayer' function, what does it do?

EDIT:

Try it:

Server:

addCommandHandler("tirarsoco", 
function (sourcePlayer) 
    local list9 = 0 
    local playerTable = {} 
    for _ , v in ipairs  ( getElementsByType ('player' )) do 
        -- if not (isAllownedPlayer(v)) then return end 
        local isPlayerInEvento = getElementData( v, "Evento" ) 
        if (isPlayerInEvento) then 
            setElementData(v, "soco", true) 
            outputChatBox("#FFF000[EVENTO]#FFFFFF "..getPlayerName(sourcePlayer).." Deleted your hands", v, 255, 255, 255, true) 
            list9 = list9 + 1 
            playerTable[v] = true 
     end 
triggerClientEvent("onDeleteHands", root, playerTable) 
        outputChatBox("#FFF000[EVENTO]#FFFFFF You deleted soco of  "..list9.." players", sourcePlayer, 255, 255, 255, true) 
    end 
end) 
  

Client:

function dontFight(_, slot) 
    if slot == 0 and getElementData(localPlayer, "soco") then 
        toggleControl ( "fire", false ) 
    elseif slot ~= 0 and getElementData(localPlayer, "soco") then 
        toggleControl ( "fire", true) 
    else 
        toggleControl ( "fire", true) 
        removeEventHandler("onClientPlayerWeaponSwitch", root, dontFight) 
    end 
end 
  
addEvent("onDeleteHands", true) 
addEventHandler("onDeleteHands", root, 
function(playerTable) 
    if playerTable[localPlayer] then 
        dontFight(_, getPedWeaponSlot(localPlayer)) 
        addEventHandler("onClientPlayerWeaponSwitch", root, dontFight) 
    end 
end) 
  

Edited by Guest
Link to comment

The problem isn't in my function, because the function work without problems in all my other commands..

Here is the function

function isAllownedPlayer(player) 
    local account = getPlayerAccount(player) 
    if (not account or isGuestAccount(account)) then return false end 
    local accountName = getAccountName(account) 
    for i, v in pairs ( acls ) do 
        if ( isObjectInACLGroup ( "user.".. accountName, aclGetGroup ( v ) ) ) then 
            return true 
        end 
    end 
  
    outputChatBox("#FFF000[sERVER]#FFFFFF You aren't an admin.", player, 255,255,255, true) 
    return false 
end 

I'll check your code and answer soon

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