Jump to content

Idk why dont work :/


TheIceman

Recommended Posts

Idk what is problem.When i spawn vehicle then i dont spawn in vehicle :/

function marker() 
        myMarker = createMarker(1539.3,-1686.8,13,"cylinder", 2, 225, 225, 0, 150 ) 
end 
addEventHandler ("onResourceStart",getResourceRootElement(getThisResource()),marker) 
  
function vehicle (thePlayer) 
        x,y,z = getElementPosition(thePlayer) 
        veh = createVehicle(470, 1539.3,-1686.8,13) 
        warpPedIntoVehicle(thePlayer, veh) 
end 
addEvent ("vehicle",true) 
addEventHandler ("vehicle",getRootElement(),vehicle) 
  
function openGUI(hitElement) 
        if source == myMarker then 
                triggerClientEvent(hitElement,"openGUI",getRootElement())          
        end 
end 
addEventHandler ("onMarkerHit",getRootElement(),openGUI) 

Link to comment

First - Tabulate your code correctly:

  
local myMarker = createMarker ( 1539.3, -1686.8, 13, 'cylinder', 2, 255, 225, 0, 150 ); 
  
addEvent ( 'vehicle', true ); 
  
addEventHandler ( 'vehicle', root, 
    function ( uPlayer ) 
        local nX, nY, nZ     = getElementPosition ( uPlayer ); 
        local uVehicle       = createVehicle ( 470, 1539.3, -1686.8, 13 ); 
        warpPedIntoVehicle ( uPlayer, uVehicle ); 
    end 
) 
  
addEventHandler ( 'onMarkerHit', root, 
    function ( uPlayer ) 
        if ( source == myMarker ) then 
            triggerClientEvent ( uPlayer, 'openGUI', root ); 
        end 
    end 
) 

Second - warpPedIntoVehicle is bugged.

where is "vehicle" event is triggered?

also i'd suggest using more explanatory names for events and functions rather than generic "vehicle" or "marker".

When i spawn vehicle then i dont spawn in vehicle :/

The problem isn't that, the script creates the vehicle, but he don't get spawned into vehicle.

Edited by Guest
Link to comment
local uMyMarker = createMarker ( 1539.3, -1686.8, 13, 'cylinder', 2, 255, 225, 0, 150 ) 
  
addEvent ( 'vehicle', true ) 
  
addEventHandler ( 'vehicle', root, 
    function ( uPlayer ) 
        local uVehicle       = createVehicle ( 470, 1539.3, -1686.8, 13 ) 
        setTimer( warpPedIntoVehicle, 1000, 1, uPlayer, uVehicle ) 
    end 
) 
  
addEventHandler ( 'onMarkerHit', root, 
    function ( uPlayer ) 
        if ( source == uMyMarker ) then 
            triggerClientEvent ( uPlayer, 'openGUI', uPlayer ) 
        end 
    end 
) 

You should use timer for warp player into vehicle.

Also use in next time /debugscript 3

And show your client side code if this didn't working.

Link to comment

CLIENT side:

local vehicles = 
    { 
        "Patriot" 
    } 
  
function openGUI ( ) 
    window = guiCreateWindow (0.3,0.2,0.3,0.6,"SACR Car spawn",true) 
    gridlist = guiCreateGridList (0.1,0.1,0.8,0.7,true,window) 
    column = guiGridListAddColumn( gridlist, "Vehicles:", 0.85 ) 
    for index, vehicle in ipairs ( vehicles ) do 
        local row = guiGridListAddRow ( gridlist ) 
        guiGridListSetItemText ( gridlist, row, column, tostring ( vehicle ), false, false ) 
    end 
    button = guiCreateButton (0.6,0.85,0.4,0.1,"Spawn",true,window) 
    close = guiCreateButton(0,0.85,0.4,0.1,"Close",true,window) 
    showCursor ( true ) 
end 
addEvent ( "openGUI", true ) 
addEventHandler ( "openGUI", root, openGUI ) 
  
function destroyGUI() 
    destroyElement(window) 
    showCursor (false) 
    window = nil 
end 
  
function buttonClick ( ) 
   if ( source == button ) then -- "row" is not a GUI element. 
        local row, col = guiGridListGetSelectedItem ( gridlist ) -- Get the selected item from the grid list. 
        if ( row and col and row ~= -1 and col ~= -1 ) then -- If he has a selected item. 
            local vehicleName = guiGridListGetItemText ( gridlist, row, col ) -- Get the text of it. 
            triggerServerEvent ( "vehicle", localPlayer, getVehicleModelFromName ( vehicleName ) ) -- Trigger the "vehicle" event with a vehicle model argument. 
            destroyGUI () 
        end 
   elseif ( source == close ) then 
        destroyGUI () 
    end 
end 
addEventHandler ( "onClientGUIClick", getRootElement(), buttonClick ) 
  

Link to comment
local uMyMarker = createMarker ( 1539.3, -1686.8, 13, 'cylinder', 2, 255, 225, 0, 150 ) 
  
addEvent ( 'vehicle', true ) 
  
addEventHandler ( 'vehicle', root, 
    function ( model ) 
        local uVehicle       = createVehicle ( model, 1539.3, -1686.8, 13 ) 
        setTimer( warpPedIntoVehicle, 1000, 1, source, uVehicle ) 
    end 
) 
  
addEventHandler ( 'onMarkerHit', root, 
    function ( uPlayer ) 
        if ( source == uMyMarker ) then 
            triggerClientEvent ( uPlayer, 'openGUI', uPlayer ) 
        end 
    end 
) 

Link to comment

Corrected code

addEvent ( 'openGUI', true ) 
  
local vehicles = 
{ 
    'Patriot'; 
} 
  
function openGUI ( ) 
    window = guiCreateWindow ( 0.3,0.2,0.3,0.6,'SACR Car spawn',true ) 
    gridlist = guiCreateGridList ( 0.1,0.1,0.8,0.7,true,window ) 
    column = guiGridListAddColumn( gridlist, 'Vehicles:', 0.85 ) 
    for index, vehicle in ipairs ( vehicles ) do 
        local row = guiGridListAddRow ( gridlist ) 
        guiGridListSetItemText ( gridlist, row, column, tostring ( vehicle ), false, false ) 
    end 
    button = guiCreateButton ( 0.6,0.85,0.4,0.1,'Spawn',true,window ) 
    close = guiCreateButton( 0,0.85,0.4,0.1,'Close',true,window ) 
    showCursor ( true ) 
end 
  
function destroyGUI( ) 
    destroyElement( window ) 
    showCursor ( false ) 
    window = nil 
end 
  
function buttonClick ( ) 
   if ( source == button ) then -- 'row' is not a GUI element. 
        local nRow, nCol = guiGridListGetSelectedItem ( gridlist ) 
        if ( nRow and nCol and nRow ~= -1 and nCol ~= -1 ) then 
            local sVehicleName = guiGridListGetItemText ( gridlist, nRow, nCol ) 
            triggerServerEvent ( 'vehicle', localPlayer, getVehicleModelFromName ( sVehicleName ) ) 
            destroyGUI ( ) 
        end 
   elseif source == close then 
        destroyGUI ( ) 
    end 
end 
  
  
addEventHandler ( 'onClientGUIClick', root, buttonClick ) 
addEventHandler ( 'openGUI', root, openGUI ) 

local uMyMarker = createMarker ( 1539.3, -1686.8, 13, 'cylinder', 2, 255, 225, 0, 150 ) 
  
addEvent ( 'vehicle', true ) 
  
addEventHandler ( 'vehicle', root, 
    function ( nModel ) 
        local uVehicle = createVehicle ( nModel, 1539.3, -1686.8, 13 ) 
        setTimer( warpPedIntoVehicle, 1000, 1, source, uVehicle ) 
    end 
) 
  
addEventHandler ( 'onMarkerHit', root, 
    function ( uPlayer ) 
        if ( source == uMyMarker ) then 
            triggerClientEvent ( uPlayer, 'openGUI', uPlayer ) 
        end 
    end 
) 

Your problem here:

addEventHandler ( 'vehicle', root, 
    function ( uPlayer ) 
        local uVehicle       = createVehicle ( 470, 1539.3, -1686.8, 13 ) 
        setTimer( warpPedIntoVehicle, 1000, 1, uPlayer, uVehicle ) 
    end 
) 

Variable uPlayer is not element, it's number of model vehicle ..

You should use source here.

viewtopic.php?f=91&t=39678

addEventHandler ( 'vehicle', root, 
    function ( nModel ) 
        local uVehicle = createVehicle ( nModel, 1539.3, -1686.8, 13 ) 
        setTimer( warpPedIntoVehicle, 1000, 1, source, uVehicle ) 
    end 
) 

P.S Solidsnake14, ... You just fix it and not explain him ...

Good job :/

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