Jump to content

script help


Stylez

Recommended Posts

Posted

Good Evening everybody :)

i have this small script. You should understand what i am trying to do.. i know where i have problem. But i cant solve it :D

the problem is in local vehicle = getPedOccupiedVehicle(source) - source argument.. but as i said, i cant solve this problem :D

Here is the code

function bind() 
local vehicle = getPedOccupiedVehicle(source) 
    if vehicle then 
        local driver = getVehicleOccupant(vehicle) 
            if driver then 
                bindKey(source, "m", "down", bind) 
                triggerClientEvent(source, "bindKey", getRootElement(), "trigger") 
            end 
    else 
        outputChatBox("u need to be in a car",source) 
    end 
end 
addEventHandler("onPlayerVehicleEnter", getRootElement(), bind) 
  

Posted (edited)
o.O i tried to trigger bindKey function to client side. Maybe, u can fix my code so it triggers bindKey function to clientside? :) Edited by Guest
Posted

So, what you want to do is bind a key to trigger that event?

function bind ( ) 
    bindKey ( source, "m", "down", trigger ) 
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), bind ) 
  
function trigger ( thePlayer ) 
    if ( isPedInVehicle ( thePlayer ) ) then 
        triggerClientEvent ( thePlayer, "bindKey", getRootElement(), "trigger" ) 
    else 
        outputChatBox ( "u need to be in a car", thePlayer ) 
    end 
end 

Posted

Nonono. i want to trigger bindKey function to client side. i tried to bind M key with "onClientPlayerVehicleEnter" but it didint worked for me, so i tried another way.

Posted
addEventHandler ( "onClientVehicleEnter", root, 
    function ( thePlayer, seat ) 
        if ( thePlayer == localPlayer ) then 
            bindKey ( "M", "down", bind ) 
        end 
    end 
) 

That would work.

Posted

Here. i tried to bind m key when player enters vehicle, so i could show and hide mouse.

function cursor(button, state) 
    if showCursor == false then 
        showCursor(true) 
    else 
        showCursor(false) 
    end 
end 
function bind () 
    bindKey("m", "down", cursor) 
end 
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), bind) 

Posted
if showCursor == false then 

That is wrong, you should use:

if ( not isCursorShowing ( ) ) then 

Or just:

showCursor ( not isCursorShowing ( ) ) 

Would show the cursor if is not already showing, else hide it.

Posted

Hey, solidsnake. i have new problem with same script. Everything works, just when i click on vehicle it opens 99999999+ window.

function masiniukui() 
    mainWin = guiCreateWindow(0.80, 0.15, 0.20, 0.60,"WINDOW!!!!!!!!!", true) 
    local car = getPedOccupiedVehicle(getLocalPlayer()) 
        if car then 
            local driver = getVehicleOccupant(car) 
                if driver then 
                    if isPedInVehicle(driver) then 
                        local carClick  = getPedOccupiedVehicle(driver) 
                            if carClick then 
                                guiSetVisible(mainWin, true) 
                            end 
                    end 
                end 
        end 
end 
addEventHandler("onClientClick", getRootElement(), masiniukui) 
  
function cursor( ) 
    if not isCursorShowing() then 
        showCursor(true) 
    else 
        showCursor(false) 
        guiSetVisible(mainWin, false) 
    end 
end 
function bind (thePlayer, seat) 
    if source == localPlayer then 
        bindKey( "m", "down", cursor) 
    end 
end 
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), bind) 
  

Posted
mainWin = guiCreateWindow(0.80, 0.15, 0.20, 0.60,"WINDOW!!!!!!!!!", true) 
guiSetVisible ( mianWin, false ) 
  
function masiniukui() 
    local car = getPedOccupiedVehicle(getLocalPlayer()) 
        if car then 
            local driver = getVehicleOccupant(car) 
                if driver then 
                    if isPedInVehicle(driver) then 
                        local carClick  = getPedOccupiedVehicle(driver) 
                            if carClick then 
                                guiSetVisible(mainWin, true) 
                            end 
                    end 
                end 
        end 
end 
addEventHandler("onClientClick", getRootElement(), masiniukui) 
  
function cursor( ) 
    if not isCursorShowing() then 
        showCursor(true) 
    else 
        showCursor(false) 
        guiSetVisible(mainWin, false) 
    end 
end 
function bind (thePlayer, seat) 
    if source == localPlayer then 
        bindKey( "m", "down", cursor) 
    end 
end 
addEventHandler("onClientPlayerVehicleEnter", getRootElement(), bind) 

You was creating the window every time.

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