Jump to content

help over here.


Sparrow

Recommended Posts

Posted

well, I'll trying to do a marker for spawning vehicles only for Police team, and this is my first time I add grid list, I used wiki, but can't get help from there,

this is the error:

spawn/client.lua:33: attempt to call global 'warpPedIntoVehicle' (a nil value)

and on the grid list, there are no vehicles

script:

local marker = createMarker (1605.600, -1625.300, 12.5, "cylinder", 2, 25, 50, 255, 255 ) 
local cars = {[596] = true, [597] = true, [598] = true, [599] = true} 
  
window = guiCreateWindow(561,187,260,388,"Spawn Vehicle",false) 
guiWindowSetSizable(window,false) 
spawnButton = guiCreateButton(26,317,96,37,"Spawn",false,window) 
closeButton = guiCreateButton(142,318,96,37,"Close",false,window) 
carGrid = guiCreateGridList(23,34,210,249,false,window) 
guiGridListSetSelectionMode(carGrid,2) 
guiGridListAddColumn(carGrid,"Vehicle name",0.85) 
for key,vehName in ipairs(cars) do 
    local row = guiGridListAddRow ( carGrid ) 
    guiGridListSetItemText ( carGrid, row, column, vehName, false, false ) 
end 
  
lp = getLocalPlayer ( ) 
function showWindow() 
    local playerTeam = getPlayerTeam ( lp ) 
    local teamName = getTeamName ( playerTeam )  
    if teamName == "Police" then 
        if not guiGetVisible( window ) then 
            guiSetVisible( window, true ) 
            showCursor( true ) 
        end 
    end 
end 
addEventHandler ("onClientMarkerHit", marker, showWindow) 
  
function spawnVeh( ) 
local uTeam = getPlayerTeam( lp ) 
    if not uTeam or uTeam and getTeamName ( uTeam ) ~= 'Police' then 
        local theVehicle = createVehicle (cars, x, y, z, 0, 0, rotZ) 
        warpPedIntoVehicle(source, theVehicle) 
        guiSetVisible( window, false ) 
        showCursor( false ) 
    end 
end 
addEventHandler( "onClientGUIClick", spawnButton , spawnVeh, false ) 

Posted

warpPedIntoVehicle is an server-side function.

local marker = createMarker (1605.600, -1625.300, 12.5, "cylinder", 2, 25, 50, 255, 255 ) 
local cars = {[596] = true, [597] = true, [598] = true, [599] = true} 
      
window = guiCreateWindow(561,187,260,388,"Spawn Vehicle",false) 
guiWindowSetSizable(window,false) 
spawnButton = guiCreateButton(26,317,96,37,"Spawn",false,window) 
closeButton = guiCreateButton(142,318,96,37,"Close",false,window) 
carGrid = guiCreateGridList(23,34,210,249,false,window) 
guiGridListSetSelectionMode(carGrid,2) 
guiGridListAddColumn(carGrid,"Vehicle name",0.85) 
  
for key,vehName in ipairs(cars) do 
   local row = guiGridListAddRow ( carGrid ) 
      guiGridListSetItemText ( carGrid, row, column, vehName, false, false ) 
end 
         
function showWindow() 
        local playerTeam = getPlayerTeam (localPlayer()) 
        local teamName = getTeamName ( playerTeam ) 
        if teamName == "Police" then 
                guiSetVisible( window, true ) 
                showCursor(true) 
         end 
end 
addEventHandler ("onClientMarkerHit", marker, showWindow) 
      
function spawnVeh( ) 
    local uTeam = getPlayerTeam( localPlayer() ) 
       if not uTeam or uTeam and getTeamName ( uTeam ) ~= 'Police' then 
            local theVehicle = createVehicle (cars, x, y, z, 0, 0, rotZ) 
            triggerServerEvent('warpPedIntoVehicle',localPlayer(),theVehicle) 
            guiSetVisible( window, false) 
            showCursor( false ) 
       end 
end 
addEventHandler( "onClientGUIClick", spawnButton , spawnVeh, false ) 

Posted (edited)

error:

line 30: bad argument @ 'createVehicle'

Client triggered serverside event warpPedIntoVehicle, but event is not added serverside

Edited by Guest
Posted
error:
line 30: bad argument @ 'createVehicle'

Client triggered serverside event warpPedIntoVehicle, but event is not added serverside

still same errors also no vehicles on gridlist :(

Posted (edited)

Not the same.

Try:

Client side:

    local marker = createMarker (1605.600, -1625.300, 12.5, "cylinder", 2, 25, 50, 255, 255 ) 
    local cars = {[596] = true, [597] = true, [598] = true, [599] = true} 
          
    window = guiCreateWindow(561,187,260,388,"Spawn Vehicle",false) 
    guiWindowSetSizable(window,false) 
    spawnButton = guiCreateButton(26,317,96,37,"Spawn",false,window) 
    closeButton = guiCreateButton(142,318,96,37,"Close",false,window) 
    carGrid = guiCreateGridList(23,34,210,249,false,window) 
    guiGridListSetSelectionMode(carGrid,2) 
    guiGridListAddColumn(carGrid,"Vehicle name",0.85) 
      
    for key,vehName in ipairs(cars) do 
       local row = guiGridListAddRow ( carGrid ) 
          guiGridListSetItemText ( carGrid, row, column, vehName, false, false ) 
    end 
            
    function showWindow() 
            local playerTeam = getPlayerTeam (localPlayer()) 
            local teamName = getTeamName ( playerTeam ) 
            if teamName == "Police" then 
                    guiSetVisible( window, true ) 
                    showCursor(true) 
             end 
    end 
    addEventHandler ("onClientMarkerHit", marker, showWindow) 
    
   function spawn() 
       triggerServerEvent('onGUIClick',localPlayer) 
   end 
   addEventHandler('onClientGUIClick',spawnButton, spawn, false) 
  
   function setVisible() 
       guiSetVisible(window,false) 
       showCursor(false) 
   end 
   addEvent('setGUIVisible',true) 
   addEventHandler('setGUIVisible',root,setVisible) 
  
  

Server:

function spawnVeh( ) 
        local uTeam = getPlayerTeam( source ) 
           if not uTeam or uTeam and getTeamName ( uTeam ) ~= 'Police' then 
                local theVehicle = createVehicle (cars, x, y, z, 0, 0, rotZ) -- you have to change cars to the return of the grid list selected vehicle 
                warpPedIntoVehicle(source,theVehicle) 
               triggerClientEvent('setGUIVisible',source) 
           end 
    end 
    addEvent('onGUIClick',true) 
    addEventHandler('onGUIClick',root,spawnVeh) 

Edited by Guest
Posted

the script didn't work with

localPlayer() 

so I change it to

localPlayer 

and now errors are:

spawn\server.lua:2: Bad argument @ 'getPlayerTeam'

spawn\server.lua:4: Bad argument @ 'createVehicle'

spawn\server.lua:5: Bad argument @ 'warpPedIntoVehicle'

spawn\server.lua:2: Bad argument @ 'getPlayerTeam'

spawn\server.lua:4: Bad argument @ 'createVehicle'

spawn\server.lua:5: Bad argument @ 'warpPedIntoVehicle'

Posted

no vehicles on gridlist :(

and erros when I walk to marker are:

spawn\server.lua:4: Bad argument @ 'createVehicle'

spawn\server.lua:5: Bad argument @ 'warpPedIntoVehicle'

Posted

Because your table is wrong e.e

Your table:

local cars = {[596] = true, [597] = true, [598] = true, [599] = true} 

Correct:

local cars = { 
    [596] = 'Vehicle name', 
    [597] = 'Vehicle name', 
    [598] = 'Vehicle name', 
    [599] = 'Vehicle name' 
} 

And in this change:

for id,vehName in ipairs(cars) do 
       local row = guiGridListAddRow ( carGrid ) 
          guiGridListSetItemText ( carGrid, row, column, tostring(vehName), false, false ) 
    end 

Posted
no vehicles on gridlist :(

and erros when I walk to marker are:

spawn\server.lua:4: Bad argument @ 'createVehicle'

spawn\server.lua:5: Bad argument @ 'warpPedIntoVehicle'

You get these errors because 'cars' is nil.

Posted

client:

local marker = createMarker (1605.600, -1625.300, 12.5, "cylinder", 2, 25, 50, 255, 255 ) 
local cars = { 
    [596] = 'Police LS', 
    [597] = 'Police SF', 
    [598] = 'Police LV', 
    [599] = 'Police Ranger' 
} 
  
window = guiCreateWindow(561,187,260,388,"Spawn Vehicle",false) 
guiWindowSetSizable(window,false) 
spawnButton = guiCreateButton(26,317,96,37,"Spawn",false,window) 
closeButton = guiCreateButton(142,318,96,37,"Close",false,window) 
carGrid = guiCreateGridList(23,34,210,249,false,window) 
guiGridListSetSelectionMode(carGrid,2) 
guiGridListAddColumn(carGrid,"Vehicle name",0.85) 
for id,vehName in ipairs(cars) do 
    local row = guiGridListAddRow ( carGrid ) 
    guiGridListSetItemText ( carGrid, row, column, tostring(vehName), false, false ) 
end 
  
function showWindow() 
    local playerTeam = getPlayerTeam (localPlayer) 
    local teamName = getTeamName ( playerTeam ) 
    if teamName == "Police" then 
        guiSetVisible( window, true ) 
        showCursor(true) 
    end 
end 
addEventHandler ("onClientMarkerHit", marker, showWindow) 
  
function spawn() 
    triggerServerEvent('onGUIClick',localPlayer) 
end 
addEventHandler('onClientGUIClick',spawnButton, spawn, false) 
    
function setVisible() 
    guiSetVisible(window,false) 
    showCursor(false) 
end 
addEvent('setGUIVisible',true) 
 addEventHandler('setGUIVisible',root,setVisible) 
  
function closeWindow() 
    guiSetVisible(window,false) 
    showCursor(false) 
end 
addEventHandler ("onClientGUIClick", closeButton, closeWindow, false) 

server:

function spawnVeh( ) 
    local uTeam = getPlayerTeam( source ) 
    if not uTeam or uTeam and getTeamName ( uTeam ) ~= 'Police' then 
        local theVehicle = createVehicle (cars, x, y, z, 0, 0, rotZ) -- you have to change cars to the return of the grid list selected vehicle 
        warpPedIntoVehicle(source,theVehicle) 
        triggerClientEvent('setGUIVisible',source) 
     end 
end 
addEvent('onGUIClick',true) 
addEventHandler('onGUIClick',root,spawnVeh) 

Posted

client:

local marker = createMarker (1605.600, -1625.300, 12.5, "cylinder", 2, 25, 50, 255, 255 ) 
local cars = { 
    [596] = 'Police LS', 
    [597] = 'Police SF', 
    [598] = 'Police LV', 
    [599] = 'Police Ranger' 
} 
  
window = guiCreateWindow(561,187,260,388,"Spawn Vehicle",false) 
guiWindowSetSizable(window,false) 
spawnButton = guiCreateButton(26,317,96,37,"Spawn",false,window) 
closeButton = guiCreateButton(142,318,96,37,"Close",false,window) 
carGrid = guiCreateGridList(23,34,210,249,false,window) 
guiGridListSetSelectionMode(carGrid,0) 
column = guiGridListAddColumn(carGrid,"Vehicle name",0.85) 
for id,vehName in ipairs(cars) do 
    local row = guiGridListAddRow ( carGrid ) 
    guiGridListSetItemText ( carGrid, row, column, tostring(vehName), false, false ) 
end 
  
function showWindow() 
    local playerTeam = getPlayerTeam (localPlayer) 
    local teamName = getTeamName ( playerTeam ) 
    if teamName == "Police" then 
        guiSetVisible( window, true ) 
        showCursor(true) 
    end 
end 
addEventHandler ("onClientMarkerHit", marker, showWindow) 
  
function spawn() 
    triggerServerEvent('onGUIClick',localPlayer) 
end 
addEventHandler('onClientGUIClick',spawnButton, spawn, false) 
    
function setVisible() 
    guiSetVisible(window,false) 
    showCursor(false) 
end 
addEvent('setGUIVisible',true) 
 addEventHandler('setGUIVisible',root,setVisible) 
  
function closeWindow() 
    guiSetVisible(window,false) 
    showCursor(false) 
end 
addEventHandler ("onClientGUIClick", closeButton, closeWindow, false) 

server:

function spawnVeh( ) 
    local uTeam = getPlayerTeam( source ) 
    if not uTeam or uTeam and getTeamName ( uTeam ) ~= 'Police' then 
        local theVehicle = createVehicle (cars, x, y, z, 0, 0, rotZ) -- you have to change cars to the return of the grid list selected vehicle 
        warpPedIntoVehicle(source,theVehicle) 
        triggerClientEvent('setGUIVisible',source) 
     end 
end 
addEvent('onGUIClick',true) 
addEventHandler('onGUIClick',root,spawnVeh) 

Posted

-- client side:

local marker = createMarker (1605.600, -1625.300, 12.5, "cylinder", 2, 25, 50, 255, 255 ) 
local cars = { 
    [596] = 'Police LS', 
    [597] = 'Police SF', 
    [598] = 'Police LV', 
    [599] = 'Police Ranger' 
} 
  
window = guiCreateWindow(561,187,260,388,"Spawn Vehicle",false) 
guiWindowSetSizable(window,false) 
spawnButton = guiCreateButton(26,317,96,37,"Spawn",false,window) 
closeButton = guiCreateButton(142,318,96,37,"Close",false,window) 
carGrid = guiCreateGridList(23,34,210,249,false,window) 
guiGridListSetSelectionMode(carGrid,0) 
column = guiGridListAddColumn(carGrid,"Vehicle name",0.85) 
for id,vehName in ipairs(cars) do 
    local row = guiGridListAddRow ( carGrid ) 
    guiGridListSetItemText ( carGrid, row, column, tostring(vehName), false, false ) 
    guiGridListSetItemData ( carGrid, row, column, tonumber(id), false, false ) 
end 
  
function showWindow() 
    local playerTeam = getPlayerTeam (localPlayer) 
    local teamName = getTeamName ( playerTeam ) 
    if (teamName == "Police") then 
        guiSetVisible( window, true ) 
        showCursor(true) 
    end 
end 
addEventHandler ("onClientMarkerHit", marker, showWindow) 
  
function spawn() 
    local row,col = guiGridListGetSelectedItem(carGrid) 
    if (row and col and row ~= -1 and col ~= -1) then 
        local model = guiGridListGetItemData(carGrid, row, 1) 
        triggerServerEvent('onGUIClick',localPlayer,tonumber(model)) 
    end 
end 
addEventHandler('onClientGUIClick',spawnButton, spawn, false) 
    
function setVisible() 
    guiSetVisible(window,false) 
    showCursor(false) 
end 
addEvent('setGUIVisible',true) 
 addEventHandler('setGUIVisible',root,setVisible) 
  
function closeWindow() 
    guiSetVisible(window,false) 
    showCursor(false) 
end 
addEventHandler ("onClientGUIClick", closeButton, closeWindow, false) 

-- server side:

function spawnVeh(model) 
    local uTeam = getPlayerTeam( source ) 
    if (uTeam and getTeamName ( uTeam ) == 'Police') then 
        local x, y, z = getElementPosition(source) 
        local rot = getPedRotation(source) 
        local theVehicle = createVehicle (model, x, y, z, 0, 0, rot) 
        warpPedIntoVehicle(source,theVehicle) 
        triggerClientEvent('setGUIVisible',source) 
    end 
end 
addEvent('onGUIClick',true) 
addEventHandler('onGUIClick',root,spawnVeh) 

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