Jump to content

kill player when he hit the object


Thivenin

Recommended Posts

hai all, this is the third time I ask help in 3 day x) but as I always say I started lua only since thursday

platformKillerofNoobObject = createObject ( 8661, -15, 95, 100 ) 
setElementInterior ( platformKillerofNoobObject, 901 ) 
  
function platformKillerofNoob ( hitElement, matchingDimension ) 
    if ( getElementType ( hitElement ) == "Object" ) then 
    targetPlayer = getPlayerFromName 
            setElementHealth ( targetPlayer, - 100 )  
    end 
end 
addEventHandler ( "onPlayerHit", getRootElement(), platformKillerofNoob ) 

here is the script

I want that the platform kill the player when he hit the object (platform) there is not any error, idk what is wrong ^^ and it's not killing the player

Link to comment
platformKillerofNoobObject = createObject ( 8661, -15, 95, 100 ) 
setElementInterior ( platformKillerofNoobObject, 901 ) 
  
function platformKillerofNoob ( targetElem, matchingDimension ) 
    if getElementType ( targetElem ) == "object" and getElementModel ( targetElem ) == 8661 then 
    targetPlayer = getPlayerFromName 
            setElementHealth ( targetPlayer, - 100 )  
    end 
end 
addEventHandler ( "onPlayerContact", getRootElement(), platformKillerofNoob ) 

I tried it, it saying on console when I hit the element

Bad argument at 'getElementType' [Expected element at argument 1, got nil ]

Link to comment

Thats because targetElem isn't a element.

Parameters

element previousElement, element currentElement

previousElement: The element player was standing on before. nil if none.

currentElement: The new element that the player is standing on now. nil if none.

also:

Source

The source of this event is the player who hit an element.

So:

platformKillerofNoobObject = createObject ( 8661, -15, 95, 100 ) 
setElementInterior ( platformKillerofNoobObject, 901 ) 
  
function platformKillerofNoob (prev, current) 
    if current == platformKillerofNoobObject then 
 killPed (source) 
    end 
end 
addEventHandler ( "onPlayerContact", getRootElement(), platformKillerofNoob ) 

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