Jump to content

OnMarkerleave


isa_Khamdan

Recommended Posts

How can I make this code works for vehicles too , this code works for the players only when they leave the marker but I want it for vehicles too so when the vehicle leave the marker ( destroyed or warped to another place ) it will do the functions so can anyone help me?

addEventHandler( "onMarkerLeave", getRootElement( ), 
    function( ) 
        local veh = getPlayerOccupiedVehicle( source ) 
        if veh then 
            local driver = getVehicleController( veh ) 
            if driver == source then 
                if getVehicleModShop( veh ) then 
                    unfreezeVehicleInModShop( veh ) 
                    setModShopBusy( shop, 0, false ) 
                triggerClientEvent( source, "modShop_moddingConfirmed", source ) 
                end 
            end 
        end 
    end 
) 

Link to comment

You want to do what? its only working for vehicle's right now.

local veh = getPlayerOccupiedVehicle( source ) 
        if veh then 

or do you want it like; when the vehicle explodes, it stops. When the player gets out of the car, it stops? This function might be the one thats bugging you;

onVehicleStartExit -- source: [url=https://wiki.multitheftauto.com/wiki/OnVehicleStartExit]https://wiki.multitheftauto.com/wiki/OnVehicleStartExit[/url] 

Link to comment
You want to do what? its only working for vehicle's right now.
local veh = getPlayerOccupiedVehicle( source ) 
        if veh then 

or do you want it like; when the vehicle explodes, it stops. When the player gets out of the car, it stops? This function might be the one thats bugging you;

onVehicleStartExit -- source: [url=https://wiki.multitheftauto.com/wiki/OnVehicleStartExit]https://wiki.multitheftauto.com/wiki/OnVehicleStartExit[/url] 

No I want it that if the vehicle leave the marker in any way ( destroyed , warped or anythings )

Edit : the code works only if the player leaves the marker

Link to comment

okee well you got a few ways to get it out of the marker;

onVehicleExplode() -- if it gets blown up 
onVehicleStartExit() -- if the player gets out of the car 

You dont got one for warped or destroyed. 'Cause the vehicle can only be destroyed if an admin destroys it. not in another way (oke, spawning millions of new vehicle's...).

Link to comment
okee well you got a few ways to get it out of the marker;
onVehicleExplode() -- if it gets blown up 
onVehicleStartExit() -- if the player gets out of the car 

You dont got one for warped or destroyed. 'Cause the vehicle can only be destroyed if an admin destroys it. not in another way (oke, spawning millions of new vehicle's...).

ok I made it work but what if the player created another car and the old one gone or what if he just used the map and teleported to another place?

Link to comment
Disable the menu to create new vehicle's, also the command plus the way to teleport away! You can do that with this function;
isElement 

You can see if the element is an actual element on that time, for example; the GUI thats openend.

People can use freeroam to do these things ( warp , Create ) is it possible to disable it in the modshop area?

Link to comment

Yes it is, open the freeroam source and search for the bindkey of F1, then look for the function that shows the GUI. Under the Function add this;

if ( getPedOccupiedVehicle ( source ) ) then if ( getVehicleModShop( getPedOccupiedVehicle( source ) ) ) then return; end end 

also for the command; cv. Do the same, find the command with the linked function, add the line under the function and restart freeroam.

Link to comment
Yes it is, open the freeroam source and search for the bindkey of F1, then look for the function that shows the GUI. Under the Function add this;
if ( getPedOccupiedVehicle ( source ) ) then if ( getVehicleModShop( getPedOccupiedVehicle( source ) ) ) then return; end end 

also for the command; cv. Do the same, find the command with the linked function, add the line under the function and restart freeroam.

I found another way to do that but I am having a problem how can I cancel the event that open the modshop gui?

I made this code but it didn't work

addEventHandler( "onMarkerLeave", getRootElement( ), 
    function( ) 
        local veh = getPlayerOccupiedVehicle( source ) 
        if veh then 
            local driver = getVehicleController( veh ) 
            if driver == source then 
                if getVehicleModShop( veh ) then 
                    unfreezeVehicleInModShop( veh ) 
                triggerClientEvent( source, "modShop_moddingConfirmed", source ) 
                else 
                cancelEvent () 
                triggerClientEvent( driver, "onClientPlayerEnterModShop", player, vehicle, getPlayerMoney( player ), modShops[ k ].name ) 
                end 
            end 
        end 
    end 
) 

Link to comment
You can't cancel a triggerClientEvent nor triggerServerEvent. You can only cancel eventHandlers.

So there is no way to cancel client events?

Edit what about your way ( the mod shop isn't part of the freeroam resource ) will it work?

if ( getPedOccupiedVehicle ( source ) ) then if ( getVehicleModShop( getPedOccupiedVehicle( source ) ) ) then return; end end 

Link to comment
If you add it to the right functions on the right places, it will. 100% sure. :)

Like this?

addEventHandler('onClientResourceStart', g_ResRoot, 
    function() 
     
    if ( getPedOccupiedVehicle ( source ) ) then if ( getVehicleModShop( getPedOccupiedVehicle( source ) ) ) then return; end end 
        fadeCamera(true) 
        setTimer(getPlayers, 1000, 1) 
         
        bindKey('f1', 'down', toggleFRWindow) 
        createWindow(wndMain) 
        hideAllWindows() 
        guiCheckBoxSetSelected(getControl(wndMain, 'Jetpack'), doesPedHaveJetPack(g_Me)) 
        guiCheckBoxSetSelected(getControl(wndMain, 'Falloff'), canPedBeKnockedOffBike(g_Me)) 
        setJetpackMaxHeight ( 9001 ) 
         
        triggerServerEvent('onLoadedAtClient', g_ResRoot, g_Me) 
    end 
) 

Link to comment
Nope, find this function:
toggleFRWindow 

There will be something like;

function toggleFRWindow()  

Under that line, add my code.

Like this xD

function toggleFRWindow() 
    if ( getPedOccupiedVehicle ( source ) ) then if ( getVehicleModShop( getPedOccupiedVehicle( source ) ) ) then return; end end 
    if isWindowOpen(wndMain) then 
        showCursor(false) 
        hideAllWindows() 
        colorPicker.closeSelect() 
    else 
        showCursor(true) 
        showAllWindows() 
    end 
end 
  
addCommandHandler('fr', toggleFRWindow) 

Edit : I tested it but it didn't work?

Link to comment
function toggleFRWindow() 
    if ( getPedOccupiedVehicle ( getLocalPlayer() ) ) then if ( getVehicleModShop( getPedOccupiedVehicle( getLocalPlayer() ) ) ) then return; end end 
    if isWindowOpen(wndMain) then 
        showCursor(false) 
        hideAllWindows() 
        colorPicker.closeSelect() 
    else 
        showCursor(true) 
        showAllWindows() 
    end 
end 
  
addCommandHandler('fr', toggleFRWindow) 

try that.

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