Jump to content

Seatbelt warning


DzMGZXL

Recommended Posts

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) 

Link to comment
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. ;)

Link to comment
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.

Link to comment
  • Other Languages Moderators
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.

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