DzMGZXL Posted December 21, 2014 Posted December 21, 2014 Hey guys so i make script if player doesn't wear seatbelt it warns he.But Idk why my code doesn't work. function seatbeltW() if (getElementData(thePlayer, "seatbelt") == false) then local x, y = guiGetScreenSize() image = guiCreateStaticImage(x - 180, y - 140.5, 64, 64, "seatbelt.png", false) setTimer(destroyImage, 500, 1, image) end end addEventHandler("onVehicleEnter", getRootElement(), seatbeltW)
Castillo Posted December 21, 2014 Posted December 21, 2014 Well, the first mistake is that 'thePlayer' is not defined, also, you are using a server side event with client side only functions.
xScatta Posted December 22, 2014 Posted December 22, 2014 function seatbeltW(thePlayer) if (getElementData(thePlayer, "seatbelt") == false) then local x, y = guiGetScreenSize() image = guiCreateStaticImage(x - 180, y - 140.5, 64, 64, "seatbelt.png", false) setTimer(destroyImage, 500, 1, image) end end addEventHandler("onClientVehicleEnter", getRootElement(), seatbeltW) Not tested but should work.
Anubhav Posted December 22, 2014 Posted December 22, 2014 Well, the first mistake is that 'thePlayer' is not defined, also, you are using a server side event with client side only functions. 2nd line. It should be localPlayer
Castillo Posted December 22, 2014 Posted December 22, 2014 function seatbeltW(thePlayer) if (getElementData(thePlayer, "seatbelt") == false) then local x, y = guiGetScreenSize() image = guiCreateStaticImage(x - 180, y - 140.5, 64, 64, "seatbelt.png", false) setTimer(destroyImage, 500, 1, image) end end addEventHandler("onClientVehicleEnter", getRootElement(), seatbeltW) Not tested but should work. This will trigger even when a remote player enters a vehicle, you need to check if 'thePlayer' is the local player.
Tete omar Posted December 22, 2014 Posted December 22, 2014 Hey guys so i make script if player doesn't wear seatbelt it warns he.But Idk why my code doesn't work. function seatbeltW() if (getElementData(thePlayer, "seatbelt") == false) then local x, y = guiGetScreenSize() image = guiCreateStaticImage(x - 180, y - 140.5, 64, 64, "seatbelt.png", false) setTimer(destroyImage, 500, 1, image) end end addEventHandler("onVehicleEnter", getRootElement(), seatbeltW) First: You don't need an element data since you can just place variables instead (unless you want to declare that the player is wearing a seatbelt to the whole server), generally because you wouldn't want a pointless consumption of the server's CPU and clients' network traffic. Using variables is recommended. Second: onVehicleEnter is a server-side event while both guiGetScreenSize and guiCreateStaticImage are client-sided, So don't confuse both sides with each other. Use onClientVehicleEnter instead. And don't forget to define thePlayer argument/parameter in the handler function.
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