xeon17 Posted August 11, 2014 Share Posted August 11, 2014 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
Max+ Posted August 11, 2014 Share Posted August 11, 2014 (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 August 12, 2014 by Guest Link to comment
xeon17 Posted August 12, 2014 Author Share Posted August 12, 2014 Still dosen't work , nothing in debug.. Link to comment
Max+ Posted August 12, 2014 Share Posted August 12, 2014 Still dosen't work , nothing in debug.. i have edited my post copy it again , Link to comment
xeon17 Posted August 12, 2014 Author Share Posted August 12, 2014 No work , bad argument at getPlayerName got nill. nothing wrong at my other functions.. Link to comment
xeon17 Posted August 12, 2014 Author Share Posted August 12, 2014 Problem is clientside.. Link to comment
xeon17 Posted August 12, 2014 Author Share Posted August 12, 2014 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
DNL291 Posted August 12, 2014 Share Posted August 12, 2014 ---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
Max+ Posted August 12, 2014 Share Posted August 12, 2014 ---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
Sasu Posted August 12, 2014 Share Posted August 12, 2014 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
Castillo Posted August 12, 2014 Share Posted August 12, 2014 Nope, you can't cancel that event. Link to comment
Max+ Posted August 13, 2014 Share Posted August 13, 2014 Nope, you can't cancel that event. You'r Right , he could use toggleControl Link to comment
xeon17 Posted August 13, 2014 Author Share Posted August 13, 2014 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
xeon17 Posted August 13, 2014 Author Share Posted August 13, 2014 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
Max+ Posted August 13, 2014 Share Posted August 13, 2014 --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
xeon17 Posted August 13, 2014 Author Share Posted August 13, 2014 Tried dosen't work i write /tirarsoco and get the outputchatbox , but i still can fire with hands... Link to comment
Sasu Posted August 13, 2014 Share Posted August 13, 2014 (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 August 13, 2014 by Guest Link to comment
xeon17 Posted August 13, 2014 Author Share Posted August 13, 2014 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
xeon17 Posted August 13, 2014 Author Share Posted August 13, 2014 i have a error with your code , line : 17 addEventHandler onClientPlayerWeaponSwitch with this function is already handled wtf? Link to comment
Et-win Posted August 13, 2014 Share Posted August 13, 2014 It means there already is an event handler for that function with the same event. Link to comment
xeon17 Posted August 13, 2014 Author Share Posted August 13, 2014 Can anyone fix it ._. Link to comment
Et-win Posted August 13, 2014 Share Posted August 13, 2014 triggerClientEvent("onDeleteHands", root, playerTable) Probably to: triggerClientEvent(v, "onDeleteHands", root, playerTable) Link to comment
Sasu Posted August 13, 2014 Share Posted August 13, 2014 Oh sorry. Put triggerClientEvent function outside the loop or copy the code again. Link to comment
xeon17 Posted August 13, 2014 Author Share Posted August 13, 2014 I did what Et-win said and the code worked ( finally ) Thank you Sasu and thank to everyone who tried to help me. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now