Xwad Posted October 30, 2015 Share Posted October 30, 2015 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
Al3grab Posted October 30, 2015 Share Posted October 30, 2015 You can try using guiGetVisible Link to comment
t3wz Posted October 30, 2015 Share Posted October 30, 2015 (edited) 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 October 30, 2015 by Guest Link to comment
SpecT Posted October 30, 2015 Share Posted October 30, 2015 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
Xwad Posted October 30, 2015 Author Share Posted October 30, 2015 Thanks for all answers.t3wz: isElementWithinColShape is also a way to fix it but guiGetVisible was faster and easyer for me. toni012899: Thanks! i used guiGetVisible and its working with that function:D Link to comment
SpecT Posted October 31, 2015 Share Posted October 31, 2015 Thanks for all answers.t3wz: isElementWithinColShape is also a way to fix it but guiGetVisible was faster and easyer for me. toni012899: Thanks! i used guiGetVisible and its working with that function:D You are welcome! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now