Jump to content

Event System Function


xeon17

Recommended Posts

Posted

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 ) 

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

Posted (edited)

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

- New , Kill System

- New, GameMode Intro

- Leve / Exp System

- New nametag showing style

- New , Hud For Players

- Skin Selection from SA-MP

- Money System / Buy Weapons

- Drop Weapons

- New, Flood System

- New , Group Assign

- Gun license For Weapons

- Random Rule System For Money

Posted
Still dosen't work , nothing in debug..

i have edited my post copy it again ,

- New , Kill System

- New, GameMode Intro

- Leve / Exp System

- New nametag showing style

- New , Hud For Players

- Skin Selection from SA-MP

- Money System / Buy Weapons

- Drop Weapons

- New, Flood System

- New , Group Assign

- Gun license For Weapons

- Random Rule System For Money

Posted

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

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

Posted
---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) 

Please do not PM me with scripting related question nor support, use the forums instead.

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

- New , Kill System

- New, GameMode Intro

- Leve / Exp System

- New nametag showing style

- New , Hud For Players

- Skin Selection from SA-MP

- Money System / Buy Weapons

- Drop Weapons

- New, Flood System

- New , Group Assign

- Gun license For Weapons

- Random Rule System For Money

Posted

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) 

State: Inactive

Posted

Nope, you can't cancel that event.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Nope, you can't cancel that event.

You'r Right , he could use

toggleControl 

- New , Kill System

- New, GameMode Intro

- Leve / Exp System

- New nametag showing style

- New , Hud For Players

- Skin Selection from SA-MP

- Money System / Buy Weapons

- Drop Weapons

- New, Flood System

- New , Group Assign

- Gun license For Weapons

- Random Rule System For Money

Posted

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) 

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

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

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

Posted

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

- New , Kill System

- New, GameMode Intro

- Leve / Exp System

- New nametag showing style

- New , Hud For Players

- Skin Selection from SA-MP

- Money System / Buy Weapons

- Drop Weapons

- New, Flood System

- New , Group Assign

- Gun license For Weapons

- Random Rule System For Money

Posted (edited)

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

State: Inactive

Posted

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

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

Posted

i have a error with your code , line : 17 addEventHandler onClientPlayerWeaponSwitch with this function is already handled

wtf?

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

Posted

Oh sorry. Put triggerClientEvent function outside the loop or copy the code again.

State: Inactive

Posted

I did what Et-win said and the code worked ( finally )

Thank you Sasu :) and thank to everyone who tried to help me.

A unique GangWar gamemode waiting for you!
Click here for more information.

560x95_FFFFFF_FF9900_000000_000000.png

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