Jump to content

isElement function is not working!


Xwad

Recommended Posts

Hi i used "isElement" function but its not working and theres no debugscript:/

So the script is that if i enter the col then an image will be showed. And i want to make that players can only teleport (setPlayerPosition) if the "icon"(mg42.png) is visible or the player is inside the col..

CLIENT

  
col = createColCuboid ( -2424.2, -610, 132.5, 5, 5, 5 ) 
  
function main() 
icon = guiCreateStaticImage(0.6, 0.3, 0.1, 0.08, "files/mg42.png", true) 
setTimer ( function() 
        guiSetVisible(icon, false) 
    end, 50, 1 ) 
end 
addEventHandler( "onClientResourceStart", root, main ) 
  
function onHit() 
guiSetVisible(icon, true) 
end 
addEventHandler( "onClientColShapeHit", col, onHit ) 
  
function onLeave() 
guiSetVisible(icon, false) 
end 
addEventHandler( "onClientColShapeLeave", col, onLeave ) 
  
  
  
  
  
  
  
  
function binds() 
bindKey ( "e", "down", onEnter ) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), binds) 
  
  
function onEnter(posX, posY, posZ) 
if isElement(icon) then 
local x, y, z = getElementPosition(localPlayer) 
setElementPosition(localPlayer, -2422.1469,  -607.8954, 132.56) 
end 
end 
  

Link to comment

isElement will always return true (because the image is an element, even when invisible), Use isElementWithinColShape, also using root in the second parameter of addEventHandler (line 10) will execute the main function when ANY resource starts, you must use resourceRoot.

 col = createColCuboid ( -2424.2, -610, 132.5, 5, 5, 5 ) 
  
function main() 
    icon = guiCreateStaticImage(0.6, 0.3, 0.1, 0.08, "files/mg42.jpg", true) 
     
    -- I assume that timer is just for testing, otherwise there's no need of this. 
    setTimer ( function() 
        guiSetVisible(icon, false) 
    end, 50, 1 ) 
     
    bindKey ( "e", "down", onEnter ) 
end 
addEventHandler( "onClientResourceStart", resourceRoot, main ) 
  
function onHit() 
    guiSetVisible(icon, true) 
end 
addEventHandler( "onClientColShapeHit", col, onHit ) 
  
function onLeave() 
    guiSetVisible(icon, false) 
end 
addEventHandler( "onClientColShapeLeave", col, onLeave ) 
  
  
function onEnter(posX, posY, posZ) 
    if isElementWithinColShape ( localPlayer, col ) then 
        local x, y, z = getElementPosition(localPlayer) 
        setElementPosition(localPlayer, -2422.1469,  -607.8954, 132.56) 
    end 
end 

@EDIT

Al3grab's solution will work also, but if you REALLY want to check if the player is in the colshape isElementWithinColShape is the function for this.

Edited by Guest
Link to comment
col = createColCuboid ( -2424.2, -610, 132.5, 5, 5, 5 ) 
  
function main() 
icon = guiCreateStaticImage(0.6, 0.3, 0.1, 0.08, "files/mg42.png", true) 
setTimer ( function() 
        guiSetVisible(icon, false) 
    end, 50, 1 ) 
end 
addEventHandler( "onClientResourceStart", root, main ) 
  
function onHit() 
guiSetVisible(icon, true) 
end 
addEventHandler( "onClientColShapeHit", col, onHit ) 
  
function onLeave() 
guiSetVisible(icon, false) 
end 
addEventHandler( "onClientColShapeLeave", col, onLeave ) 
  
  
  
  
  
  
  
  
function binds() 
bindKey ( "e", "down", onEnter ) 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), binds) 
  
  
function onEnter(posX, posY, posZ) 
if guiGetVisible(icon) then 
local x, y, z = getElementPosition(localPlayer) 
setElementPosition(localPlayer, -2422.1469,  -607.8954, 132.56) 
end 
end 
  

This should work. You just have to use guiGetVisible to check if the GUI element is visible.

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