Jump to content

GetElementData


Recommended Posts

function schaden ( attacker, weapon, bodypart, loss ) 
    if attacker then 
        if getElementType ( attacker ) == "vehicle" then 
            cancelEvent() 
        else 
            local player1 = getPlayerName(attacker) 
            local player = getPlayerName(source) 
            local spielzeit = getElementData(thePlayer, "PlayedH") 
            local mindestzeit = 3 
            if tostring(spielzeit) < tostring(mindestzeit) then 
            outputChatBox("Du kannst ihn nicht verletzen!", 255, 0, 0, attacker) 
            outputChatBox("Du kannst nicht verletzt werden!", 255, 0, 0, player) 
            setElementHealth(player, 100) 
            setElementHealth(player, getElementHealth(player)-5) 
            end 
        end 
    end 
end 
addEventHandler ( "onPlayerDamage", getRootElement(), schaden) 
  

What this script should do. It checks if the attacker or victim has played more than 3 hours and if not, the victim will get 100% health and the attacker -5.

But it doesn't do.

WARNING : BAD ARGUMENT @ GETELEMENTDATA

The PlayedH is defined.

Link to comment

You're mixing both player variables and sometimes even use their names (strings) where a player element is needed.

function schaden ( attacker, weapon, bodypart, loss ) 
    if attacker then 
       if getElementType ( attacker ) == "vehicle" then 
            cancelEvent() 
       else 
            local victim = source 
            local spielzeit = getElementData(victim, "PlayedH") 
            local mindestzeit = 3 
            if tostring(spielzeit) < tostring(mindestzeit) then 
                     outputChatBox("Du kannst ihn nicht verletzen!", 255, 0, 0, attacker) 
                     outputChatBox("Du kannst nicht verletzt werden!", 255, 0, 0, victim) 
                     setElementHealth(victim, 100) 
                     setElementHealth(attacker, getElementHealth(attacker)-5) 
            end 
       end 
    end 
end 
addEventHandler ( "onPlayerDamage", getRootElement(), schaden) 

Link to comment
  
addEventHandler ( "onPlayerDamage", root,  
    function( attacker, weapon, bodypart, loss ) 
        if attacker then 
            if getElementType ( attacker ) == "vehicle" then 
                cancelEvent() 
          else 
                local victim = source 
                local spielzeit = getElementData(victim, "PlayedH") 
                local mindestzeit = 3 
                if tonumber(spielzeit) < tonumber(mindestzeit) then 
                     outputChatBox("Du kannst ihn nicht verletzen!", 255, 0, 0, attacker) 
                     outputChatBox("Du kannst nicht verletzt werden!", 255, 0, 0, victim) 
                     setElementHealth(victim, 100) 
                     local health = getElementHealth(attacker) 
                     setElementHealth(attacker, health - 5) 
                end 
            end 
        end 
    end 
)    
  

Link to comment
  • Moderators

As far I know we can compare 2 strings. I mean for exemple this:

if "a" < "b" then 
    outputChatBox( "Yeah a it's lower than b !!" ) 
end 

And I think that you can make it for numbers, because it's compare the ASCII code.

(If I'm wrong, tell me :mrgreen: )

But yeah tonumber it's better.

It checks if the attacker or victim has played more than 3 hours and if not, the victim will get 100% health and the attacker -5.

:?: If I understand correctly, the player have to play more than 3 hours before than he can killed by someone :?: It's a spawn protect for 3 hours :mrgreen:

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