Jump to content

Doesn't work (GUI Problem)


Recommended Posts

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.

Link to comment

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.

Link to comment

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) 

Link to comment

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) 

Link to comment

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) 

  • Thanks 1
Link to comment

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

Link to comment
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 .

Link to comment
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 .

Link to comment

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

Link to comment

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 

Link to comment
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 ) 

Link to comment
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 ) 

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