Jump to content

addeventhandler problem with godmode


Lucario

Recommended Posts

Hello, i need a help, when i created a new function for the godmode, with dxdrawtext in client side, it give me a error, addeventhandler expected argument and argument 3 got nil, line 27, the code with the problem.

addEventHandler( 'onClientRender', root, 
    function (targetPlayer) 
        for _, player in ipairs( getElementsByType( 'player')) do 
                local x, y, z = getElementPosition( player ); 
                local cx, cy, cz = getCameraMatrix( ); 
                if getDistanceBetweenPoints3D( cx, cy, cz, x, y, z ) <= 15 then 
                    local px, py = getScreenFromWorldPosition( x, y, z + 1.3, 0.06 ); 
                    if px then 
                        dxDrawText( 'Dont  attack me again, or i will punish you', px, py, px, py, tocolor( 255, 255, 255, 255 ), 1, "arial-bold", "center", "center", false, false, false , true  ) 
                        getElementHealth (player, -8) 
                        addEventHandler("onClientPlayerStealthKill", player, targetPlayer) 
                    end 
                end 
        end 
    end) 

Link to comment

Sure, here is the full code of the server side.

    addEventHandler ( "onClientPlayerDamage",root, 
    function () 
        if getElementData(source,"invincible") then 
            cancelEvent() 
        end 
    end) 
      
    addEventHandler("onClientPlayerStealthKill",localPlayer, 
    function (targetPlayer) 
        if getElementData(targetPlayer,"invincible") then 
            cancelEvent() 
        end 
    end) 
  
addEventHandler( 'onClientRender', root, 
    function (targetPlayer) 
        for _, player in ipairs( getElementsByType( 'player')) do 
                local x, y, z = getElementPosition( player ); 
                local cx, cy, cz = getCameraMatrix( ); 
                if getDistanceBetweenPoints3D( cx, cy, cz, x, y, z ) <= 15 then 
                    local px, py = getScreenFromWorldPosition( x, y, z + 1.3, 0.06 ); 
                    if px then 
                        dxDrawText( 'Pegame Otra Vez y Te Pateare el Culo', px, py, px, py, tocolor( 255, 255, 255, 255 ), 1, "arial-bold", "center", "center", false, false, false , true  ) 
                        getElementHealth (player, -8) 
                        addEventHandler("onClientPlayerStealthKill", player, targetPlayer) 
                    end 
                end 
        end 
    end) 

I think i was wrong in the targetPlayer, i use setelementhealth -8 for if the attacker attack me with a weapon or without, he rest -8 of health, and show him the message up of the staff head

Link to comment
Sure, here is the full code of the server side.
    addEventHandler ( "onClientPlayerDamage",root, 
    function () 
        if getElementData(source,"invincible") then 
            cancelEvent() 
        end 
    end) 
      
    addEventHandler("onClientPlayerStealthKill",localPlayer, 
    function (targetPlayer) 
        if getElementData(targetPlayer,"invincible") then 
            cancelEvent() 
        end 
    end) 
  
addEventHandler( 'onClientRender', root, 
    function (targetPlayer) 
        for _, player in ipairs( getElementsByType( 'player')) do 
                local x, y, z = getElementPosition( player ); 
                local cx, cy, cz = getCameraMatrix( ); 
                if getDistanceBetweenPoints3D( cx, cy, cz, x, y, z ) <= 15 then 
                    local px, py = getScreenFromWorldPosition( x, y, z + 1.3, 0.06 ); 
                    if px then 
                        dxDrawText( 'Pegame Otra Vez y Te Pateare el Culo', px, py, px, py, tocolor( 255, 255, 255, 255 ), 1, "arial-bold", "center", "center", false, false, false , true  ) 
                        getElementHealth (player, -8) 
                        addEventHandler("onClientPlayerStealthKill", player, targetPlayer) 
                    end 
                end 
        end 
    end) 

I think i was wrong in the targetPlayer, i use setelementhealth -8 for if the attacker attack me with a weapon or without, he rest -8 of health, and show him the message up of the staff head

It's client-side code then why do you use it server-side? What does the line with getElementHealth do? You don't even assign its return value to a variable and you pass another argument even though that function only need the element whose health you want to get. What is targetPlayer at line 25?

Link to comment

What line and what error are you getting?

addeventhandler expected argument and argument 3 got nil, line 27

There is nothing at line 27 that would make any sense. You're not helping us to help you. You just make it difficult for us to find the problem. The code looks fine to me except for that targetPlayer. onClientRender does not pass any arguments to the handled function so targetPlayer will always be nil.

Link to comment

You only need to set the data of the player "invincible" to "true".

addEventHandler ( "onClientPlayerDamage",root,function () 
    if (getElementData(getLocalPlayer(),"invincible") == "true") then 
        cancelEvent() 
    end 
end) 
      
  
  
addEventHandler("onClientPlayerStealthKill", getLocalPlayer(),  
function () 
    if (getElementData(getLocalPlayer(),"invincible") == "true") then 
        cancelEvent() 
    end 
end) 
  
  
  
addEventHandler( 'onClientRender', root, 
    function () 
        for _, player in ipairs( getElementsByType( 'player')) do 
if (getElementData(player,"invincible") == "true") then 
                local x, y, z = getElementPosition( player ) 
                local cx, cy, cz = getCameraMatrix( ) 
                if getDistanceBetweenPoints3D( cx, cy, cz, x, y, z ) <= 15 then 
                    local px, py = getScreenFromWorldPosition( x, y, z + 1.3, 0.06 ) 
                    if px then 
                        dxDrawText( "I have godmode....", px, py, px, py, tocolor( 255, 255, 255, 255 ), 1, "arial-bold", "center", "center", false, false, false , true  ) 
  
                end 
            end 
        end 
    end 
end) 

Not tested.

Link to comment
addEventHandler ( "onClientPlayerDamage",root,function () 
    if (getElementData(getLocalPlayer(),"invincible") == "true") then 
        cancelEvent() 
    end 
end) 
      
  
  
addEventHandler("onClientPlayerStealthKill", getLocalPlayer(), 
function () 
    if (getElementData(getLocalPlayer(),"invincible") == "true") then 
        cancelEvent() 
    end 
end) 
  
addEventHandler( 'onClientRender', root, 
    function () 
        for _, player in ipairs( getElementsByType( 'player')) do 
        if getElementData(source,"invincible") then 
                local x, y, z = getElementPosition( player ); 
                local cx, cy, cz = getCameraMatrix( ); 
                if getDistanceBetweenPoints3D( cx, cy, cz, x, y, z ) <= 15 then 
                    local px, py = getScreenFromWorldPosition( x, y, z + 1.3, 0.06 ); 
                    if px then 
                        dxDrawText( 'Pegame Otra Vez y Te Pateare el Culo', px, py, px, py, tocolor( 255, 255, 255, 255 ), 1, "arial-bold", "center", "center", false, false, false , true  ) 
                        setElementHealth (player, -8) 
                    end 
                end 
                end 
                end 
        end) 

Now it not give errors, but the message dont shows in the head of the staff and not display when a player shoot me, and i changed getelementhealth to setelementhealth (my error :D) but the health not be get

Link to comment
    addEventHandler ( "onClientPlayerDamage",root, 
    function () 
        if getElementData(source,"invincible") then 
            cancelEvent() 
        end 
    end) 
      
    addEventHandler("onClientPlayerStealthKill",localPlayer, 
    function (targetPlayer) 
        if getElementData(targetPlayer,"invincible") then 
            cancelEvent() 
        end 
    end) 
  
addEventHandler( 'onClientRender', root, 
    function () 
        for _, player in ipairs( getElementsByType( 'player')) do 
        if getElementData(player,"invincible") then 
                local x, y, z = getElementPosition( player ); 
                local cx, cy, cz = getCameraMatrix( ); 
                if getDistanceBetweenPoints3D( cx, cy, cz, x, y, z ) <= 15 then 
                    local px, py = getScreenFromWorldPosition( x, y, z + 1.3, 0.06 ); 
                    if px then 
                        dxDrawText( 'Pegame Otra Vez y Te Pateare el Culo', px, py, px, py, tocolor( 255, 255, 255, 255 ), 1, "arial-bold", "center", "center", false, false, false , true  ) 
                        setElementHealth (player, -8) 
                    end 
                end 
                end 
                end 
        end) 

I changed source to player? now?

Link to comment

Try this one:

local playerToDraw 
local lastTick 
  
addEventHandler ( "onClientPlayerDamage", root, 
    function ( attacker ) 
        if getElementData ( source, "invincible" ) then 
            if isElement ( attacker ) then 
                removeEventHandler ( "onClientRender", root, renderText ) 
                setElementHealth ( attacker, getElementHealth ( attacker ) - 8 ) 
                playerToDraw = source 
                lastTick = getTickCount ( ) 
                addEventHandler ( "onClientRender", root, renderText ) 
            end 
            cancelEvent ( ) 
        end 
    end 
) 
  
addEventHandler ( "onClientPlayerStealthKill", localPlayer, 
    function ( targetPlayer ) 
        if getElementData ( targetPlayer, "invincible" ) then 
            removeEventHandler ( "onClientRender", root, renderText ) 
            setElementHealth ( localPlayer, getElementHealth ( localPlayer ) - 8 ) 
            playerToDraw = targetPlayer 
            lastTick = getTickCount ( ) 
            addEventHandler ( "onClientRender", root, renderText ) 
            cancelEvent ( ) 
        end 
    end 
) 
  
function renderText ( ) 
    if ( playerToDraw and lastTick ) then 
        if ( getTickCount ( ) - lastTick >= 5000 ) then 
            playerToDraw = nil 
            lastTick = nil 
  
            return removeEventHandler ( "onClientRender", root, renderText ) 
        end 
  
        if getElementData ( playerToDraw, "invincible" ) then 
            local x, y, z = getElementPosition ( playerToDraw ) 
            local cx, cy, cz = getCameraMatrix ( ) 
            if ( getDistanceBetweenPoints3D ( cx, cy, cz, x, y, z ) <= 15 ) then 
                local px, py = getScreenFromWorldPosition ( x, y, z + 1.3, 0.06 ) 
                if ( px ) then 
                    dxDrawText ( 'Pegame Otra Vez y Te Pateare el Culo', px, py, px, py, tocolor ( 255, 255, 255, 255 ), 1, "arial-bold", "center", "center", false, false, false, true ) 
                end 
            end 
        end 
    end 
end 

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