Bilal135 Posted May 12, 2015 Posted May 12, 2015 CLIENT: function checkBox() if (guiCheckBoxGetSelected(GUIEditor.checkbox[1])) then setElementData(localPlayer, "invincible", true) else setElementData(localPlayer, "invincible", false) end end addEventHandler ( "onClientPlayerDamage",root, function () if getElementData(localPlayer,"invincible") then cancelEvent() end end) The player health still decreases. No errors in debug.
Walid Posted May 12, 2015 Posted May 12, 2015 it must be like this addEventHandler ( "onClientPlayerDamage",localPlayer, function () if getElementData(localPlayer,"invincible") then cancelEvent() end end)
John Smith Posted May 12, 2015 Posted May 12, 2015 checkBox function is never being triggered in the code you provided Also as walid said you should use localPlayer in damage event function
Bilal135 Posted May 12, 2015 Author Posted May 12, 2015 Well, I did something like this. Doesn't work. function checkBox() if ( getElementType(localPlayer) == "GUIEditor.checkbox[1]" ) then if (guiCheckBoxGetSelected(localPlayer)) then setElementData(localPlayer, "invincible", true) else setElementData(localPlayer, "invincible", false) end end end addEventHandler ( "onClientPlayerDamage",localPlayer, function () if getElementData(localPlayer,"invincible") then cancelEvent() end end) No errors in debug.
Walid Posted May 12, 2015 Posted May 12, 2015 it's Wrong. Try this function checkBox() if ( getElementType(source) == "gui-checkbox" ) then if ( guiCheckBoxGetSelected(GUIEditor.checkbox[1])) then setElementData(localPlayer, "invincible", true) else setElementData(localPlayer, "invincible", false) end end end addEventHandler("onClientGUIClick", root, checkBox, false) addEventHandler ( "onClientPlayerDamage",localPlayer, function () if getElementData(source,"invincible") then cancelEvent() end end)
Walid Posted May 12, 2015 Posted May 12, 2015 Doesn't work at all. Post full code here. i'm pretty sure that you have something wrong
Bilal135 Posted May 12, 2015 Author Posted May 12, 2015 CLIENT: GUIEditor = { checkbox = {}, staticimage = {}, label = {}, button = {}, window = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(542, 254, 348, 92, "No Deathmatch Mode", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.label[1] = guiCreateLabel(10, 25, 283, 15, "You can enable or disable 'No Deathmatch' mode.", false, GUIEditor.window[1]) GUIEditor.staticimage[1] = guiCreateStaticImage(10, 50, 34, 26, "icon.png", false, GUIEditor.window[1]) GUIEditor.checkbox[1] = guiCreateCheckBox(49, 52, 234, 24, "Enable / Disable No Deathmatch Mode", false, false, GUIEditor.window[1]) guiSetFont(GUIEditor.checkbox[1], "default-bold-small") GUIEditor.button[1] = guiCreateButton(303, 52, 31, 25, "X", false, GUIEditor.window[1]) guiSetVisible(GUIEditor.window[1], false) end ) addCommandHandler("nodm", function() guiSetVisible(GUIEditor.window[1], true) showCursor(true) end ) function onGuiClick() if (source == GUIEditor.button[1]) then guiSetVisible(GUIEditor.window[1], false) showCursor(false) end end addEventHandler("onClientGUIClick", root, onGuiClick) function checkBox() if ( getElementType(source) == "gui-checkbox" ) then if ( guiCheckBoxGetSelected(GUIEditor.checkbox[1])) then setElementData(localPlayer, "invincible", true) else setElementData(localPlayer, "invincible", false) end end end addEventHandler("onClientGUIClick", root, checkBox, false) addEventHandler ( "onClientPlayerDamage",localPlayer, function () if getElementData(source,"invincible") then cancelEvent() end end)
Walid Posted May 12, 2015 Posted May 12, 2015 As i told many things wrong try this one GUIEditor = { checkbox = {}, staticimage = {}, label = {}, button = {}, window = {} } addEventHandler("onClientResourceStart", resourceRoot, function() GUIEditor.window[1] = guiCreateWindow(542, 254, 348, 92, "No Deathmatch Mode", false) guiWindowSetSizable(GUIEditor.window[1], false) GUIEditor.label[1] = guiCreateLabel(10, 25, 283, 15, "You can enable or disable 'No Deathmatch' mode.", false, GUIEditor.window[1]) GUIEditor.staticimage[1] = guiCreateStaticImage(10, 50, 34, 26, "icon.png", false, GUIEditor.window[1]) GUIEditor.checkbox[1] = guiCreateCheckBox(49, 52, 234, 24, "Enable / Disable No Deathmatch Mode", false, false, GUIEditor.window[1]) guiSetFont(GUIEditor.checkbox[1], "default-bold-small") GUIEditor.button[1] = guiCreateButton(303, 52, 31, 25, "X", false, GUIEditor.window[1]) guiSetVisible(GUIEditor.window[1], false) addEventHandler("onClientGUIClick", GUIEditor.button[1], onGuiClick,false) addEventHandler("onClientGUIClick",GUIEditor.checkbox[1], checkBox, false) end ) addCommandHandler("nodm", function() guiSetVisible(GUIEditor.window[1], true) showCursor(true) end ) function onGuiClick() guiSetVisible(GUIEditor.window[1], false) showCursor(false) end function checkBox() if ( guiCheckBoxGetSelected(GUIEditor.checkbox[1])) then setElementData(localPlayer, "invincible", true) else setElementData(localPlayer, "invincible", false) end end addEventHandler ( "onClientPlayerDamage",localPlayer, function () if getElementData(source,"invincible") then cancelEvent() end end) 1
Bilal135 Posted May 12, 2015 Author Posted May 12, 2015 One more problem, how I do I prevent players from getting weapons if they have checked "GUIEditor.checkbox[1]"?
Walid Posted May 12, 2015 Posted May 12, 2015 One more problem, how I do I prevent players from getting weapons if they have checked "GUIEditor.checkbox[1]"? explain your problem better
Bilal135 Posted May 12, 2015 Author Posted May 12, 2015 The script I made was "No Deathmatch Mode", which gives godmode power to those who tick the checkbox. So I want, for example, if they have enabled "No Deathmatch Mode", and if they try to /wp or something to get weapons, it would give them an error that "Getting weapon in no dm mode isn't allowed".
Walid Posted May 12, 2015 Posted May 12, 2015 The script I made was "No Deathmatch Mode", which gives godmode power to those who tick the checkbox. So I want, for example, if they have enabled "No Deathmatch Mode", and if they try to /wp or something to get weapons, it would give them an error that "Getting weapon in no dm mode isn't allowed". Show me the part where you add the command .
Walid Posted May 12, 2015 Posted May 12, 2015 The script I made was "No Deathmatch Mode", which gives godmode power to those who tick the checkbox. So I want, for example, if they have enabled "No Deathmatch Mode", and if they try to /wp or something to get weapons, it would give them an error that "Getting weapon in no dm mode isn't allowed". Really i don't undrestand what you want exactly Show me the part where you add the command .
Donald Duck Posted May 12, 2015 Posted May 12, 2015 Try using root element in the onClientDamage event, for some reason it doesn't seem to work using localPlayer.
Bilal135 Posted May 13, 2015 Author Posted May 13, 2015 @Walid, LOL, you still don't understand me? Well I simply wanted to prevent players from getting weapons if they have getElementData(source, "invincible", true). So, I just found this in freeroam/fr_server.lua.. function giveMeWeapon(weapon, amount) if weapon > 50 then return end if table.find(getOption('weapons.disallowed'), weapon) then errMsg((getWeaponNameFromID(weapon) or tostring(weapon)) .. 's are not allowed', source) else giveWeapon(source, weapon, amount, true) end end I edited, and made it like this.. function giveMeWeapon(weapon, amount) if getElementData(source, "invincible", true) then toggleControl (source, "fire", false) toggleControl (source, "next_weapon", false) toggleControl (source, "previous_weapon", false) toggleControl (source, "aim_weapon", false) toggleControl (source, "vehicle_fire", false) end if getElementData(source, "invincible", false) then toggleControl (source, "fire", true) toggleControl (source, "next_weapon", true) toggleControl (source, "previous_weapon", true) toggleControl (source, "aim_weapon", true) toggleControl (source, "vehicle_fire", true) end if weapon and weapon > 50 then return end if table.find(getOption('weapons.disallowed'), weapon) then errMsg((getWeaponNameFromID(weapon) or tostring(weapon)) .. 's are not allowed', source) else giveWeapon(source, weapon, amount, true) end end It won't work.
Walid Posted May 13, 2015 Posted May 13, 2015 Try this function giveMeWeapon(weapon, amount) if getElementData(source, "invincible") then outputChatBox(" your message here ",source,255,0,0) return end if weapon > 50 then return end if table.find(getOption('weapons.disallowed'), weapon) then errMsg((getWeaponNameFromID(weapon) or tostring(weapon)) .. 's are not allowed', source) else giveWeapon(source, weapon, amount, true) end end
Bilal135 Posted May 13, 2015 Author Posted May 13, 2015 Works perfect but if I already have a weapon, then it should also get removed. How can I do that? I tried setPedWeaponSlot(source, 0) but it didn't work so....
Walid Posted May 13, 2015 Posted May 13, 2015 Works perfect but if I already have a weapon, then it should also get removed. How can I do that? I tried setPedWeaponSlot(source, 0) but it didn't work so.... Try this function disableWeaponOnGodMod (prev,new) if getElementData(localPlayer, "invincible") then if getPedWeapon(localPlayer,new) ~= 0 then setPedWeaponSlot(localPlayer, 0) end end end addEventHandler ( "onClientPlayerWeaponSwitch", getRootElement(), disableWeaponOnGodMod )
Walid Posted May 13, 2015 Posted May 13, 2015 Nope, it doesn't work. it dosent work because the player is already holding the gun try to switch you can use this function disableWeaponOnGodMod (prev,new) if getElementData(localPlayer, "invincible") then setPedWeaponSlot(localPlayer, 0) end end addEventHandler ( "onClientPlayerWeaponSwitch", localPlayer, disableWeaponOnGodMod ) or you can use onClientRender or a timer to check the player weapon slot every time addEventHandler ( "onClientRender", root, disableWeaponOnGodMod )
Bilal135 Posted May 13, 2015 Author Posted May 13, 2015 I used onClientRender method, it worked well. Thanks!
Walid Posted May 13, 2015 Posted May 13, 2015 I used onClientRender method, it worked well. Thanks! np.
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