Jump to content

Bad Argument debug


DynamicBan

Recommended Posts

I'm trying to add a few trucker skins into a gridlist for a job.

But I'm getting some bad arguments, here a ss.

agziZrp.png

Here the script

Skins = { 
{"Native Rancher", 128}, 
{"Furys Trucker", 133}, 
{"Beer Trucker", 202}, 
{"Money Trucker", 206} 
} 
  
function createWindow ( ) 
    local sWidth, sHeight, X, Y = guiGetScreenSize ( ) 
    local Width, Height = 500, 350 
    local X = (sWidth/2) - (Width/2) 
    local Y = (sHeight/2) - (Height/2) 
    takeJobWindow = guiCreateWindow ( X, Y, Width, Height, "Trucker Job", false ) 
    takeSkinGrid = guiCreateGridList ( 340, 30, 150, 310, false, takeJobWindow ) 
    guiGridListAddColumn ( takeSkinGrid, "Skin Name" , 0.6 ) 
    guiGridListAddColumn ( takeSkinGrid, "ID", 0.28 ) 
    jobButton = guiCreateButton ( 0, 310, 150, 50, "Take Job", false, takeJobWindow ) 
    cancelButton = guiCreateButton ( 175, 310, 150, 50, "Cancel", false, takeJobWindow ) 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement (), createWindow ) 
  
for i,v in ipairs (Skins) do 
  local row = guiGridListAddRow ( takeSkinGrid ) 
  guiGridListSetItemText ( takeSkinGrid, row, 1, v[1], false, true ) 
  guiGridListSetItemText ( takeSkinGrid, row, 2, v[2], false, true ) 
end 

Link to comment

You have to put it inside a function like this:

Skins = { 
{"Native Rancher", 128}, 
{"Furys Trucker", 133}, 
{"Beer Trucker", 202}, 
{"Money Trucker", 206} 
} 
      
function createWindow ( ) 
    local sWidth, sHeight, X, Y = guiGetScreenSize ( ) 
    local Width, Height = 500, 350 
    local X = (sWidth/2) - (Width/2) 
    local Y = (sHeight/2) - (Height/2) 
    takeJobWindow = guiCreateWindow ( X, Y, Width, Height, "Trucker Job", false ) 
    takeSkinGrid = guiCreateGridList ( 340, 30, 150, 310, false, takeJobWindow ) 
    guiGridListAddColumn ( takeSkinGrid, "Skin Name" , 0.6 ) 
    guiGridListAddColumn ( takeSkinGrid, "ID", 0.28 ) 
    jobButton = guiCreateButton ( 0, 310, 150, 50, "Take Job", false, takeJobWindow ) 
    cancelButton = guiCreateButton ( 175, 310, 150, 50, "Cancel", false, takeJobWindow ) 
    fillTheGrid() 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement (), createWindow ) 
     
function fillTheGrid() 
    for i,v in ipairs (Skins) do 
        local row = guiGridListAddRow ( takeSkinGrid ) 
        guiGridListSetItemText ( takeSkinGrid, row, 1, v[1], false, true ) 
        guiGridListSetItemText ( takeSkinGrid, row, 2, v[2], false, true ) 
    end 
end 

Link to comment

When I try to add markers for the destination the markers nor the blip show up when I spawn the truck

destinationCoords = { 
{-2524.92871, -618.60449, 132.56250}, 
{-1048.03088, -657.40356, 32.01260}, 
{259.51086, 1384.65955, 10.58594}, 
{-2254.77466, 2359.49536, 4.97963}, 
{2753.75195, -2473.34351, 13.64844} 
} 
  
function startBlips ( button ) 
    if ( button == spawnCar ) then 
        local marker = math.random ( destinationCoords ) 
        startMarker = createMarker ( destinationCoords, x, y, z, "cylinder", 3, 255, 255, 51 ) 
        startBlip = createBlipAttachedTo ( startMarker, 51 ) 
    end 
end 
addEventHandler ("onClientGUIClick", root, startBlips ) 

Link to comment
  • Moderators
local markerTableData = destinationCoords[math.random ( #destinationCoords )] 
local x = markerTableData[1] 
local y = markerTableData[2] 
local z = markerTableData[3] 
  

startMarker = createMarker ( [strike]destinationCoords,[/strike] x, y, z, "cylinder", 3, 255, 255, 51 ) 

Link to comment

Tried it out, but didn't work, so I used onClientPlayerVehicleEnter which didn't work either, so I removed

if ( button == spawnCar ) then 

to test out if it would work. It did work without that line.

But everyone who would enter a car would create a blip. How can I make it work so only the player who spawned the truck would create a destination blip.

function startBlips ( button ) 
    if ( button == spawnCar ) then 
        local markerTableData = destinationCoords[math.random ( #destinationCoords )] 
        local x = markerTableData[1] 
        local y = markerTableData[2] 
        local z = markerTableData[3] 
        startMarker = createMarker ( x, y, z, "cylinder", 3, 255, 255, 51 ) 
        startBlip = createBlipAttachedTo ( startMarker, 51 ) 
    end 
end 
addEventHandler ("onClientPlayerVehicleEnter", getRootElement (), startBlips ) 

It looks like this atm, right now it doesn't work because if ( button == spawnCar ) then

Link to comment
  
function startBlips ( button ) 
    if ( button == spawnCar ) then 
        local markerTableData = destinationCoords[math.random ( #destinationCoords )] 
        local x = markerTableData[1] 
        local y = markerTableData[2] 
        local z = markerTableData[3] 
        startMarker = createMarker ( x, y, z, "cylinder", 3, 255, 255, 51 ) 
        startBlip = createBlipAttachedTo ( startMarker, 51 ) 
        setElementVisibleTo( startBlip, root, false ) 
        setElementVisibleTo( startBlip, source, true ) 
    end 
end 
addEventHandler ("onClientPlayerVehicleEnter", getRootElement (), startBlips ) 
  

Link to comment
vehicles = { 
{515}, 
{514}, 
{403} 
} 
  
function createVehicleGUI ( ) 
    local sWidth, sHeight, X, Y = guiGetScreenSize ( ) 
    local Width, Height = 250, 350 
    local X = (sWidth/2) - (Width/2) 
    local Y = (sHeight/2) - (Height/2) 
    vehicleWindow = guiCreateWindow ( X, Y, Width, Height, "Trucker Vehicle Spawner", false ) 
    takeVehicleGrid = guiCreateGridList ( 0, 20, 250, 275, false, vehicleWindow ) 
    guiGridListAddColumn (takeVehicleGrid, "Vehicle", 0.9 ) 
    spawnCar = guiCreateButton ( 0, 300, 230, 40, "Spawn Truck", false, vehicleWindow ) 
     
    for i,v in ipairs ( vehicles ) do 
        local carName = getVehicleNameFromModel ( v[1] ) 
        local row = guiGridListAddRow ( takeVehicleGrid ) 
        guiGridListSetItemText ( takeVehicleGrid, row, 1, carName, false, true ) 
        guiGridListSetItemText ( takeVehicleGrid, row, 2, tostring ( v[2] ), false, true ) 
        guiSetVisible ( vehicleWindow, false ) 
    end 
end 
addEventHandler ( "onClientResourceStart", getResourceRootElement (), createVehicleGUI ) 
  
function loadSkinsintoGrid ( ) 
    for i,v in ipairs ( Skins ) do 
        local row = guiGridListAddRow ( takeSkinGrid ) 
        guiGridListSetItemText ( takeSkinGrid, row, 1, v[1], false, true ) 
        guiGridListSetItemText ( takeSkinGrid, row, 2, v[2], false, true ) 
    end 
end 
addEventHandler ("onClientResourceStart", root, loadSkinsintoGrid ) 
  
  
addEventHandler ("onClientGUIClick", root, 
    function ( ) 
        if ( source == jobButton ) then 
            local row, Column = guiGridListGetSelectedItem ( takeSkinGrid ) 
            local id = tostring ( guiGridListGetItemText ( takeSkinGrid, row, 2 ) ) 
            if ( row and Column and row ~= -1 and Column ~= -1 ) then 
                triggerServerEvent ("giveSkin", localPlayer, id ) 
            end 
        end 
    end 
) 
  
function closeGUI ( ) 
        if ( source == cancelButton ) then 
            guiSetVisible ( takeJobWindow, false ) 
            showCursor ( false,false ) 
        end 
end 
addEventHandler ("onClientGUIClick", root, closeGUI ) 
  
function MarkerGUIShoww ( hitPlayer, matchingDimension ) 
    if ( hitPlayer ) then 
        guiSetVisible ( vehicleWindow, true ) 
        showCursor ( true, true ) 
    end 
end 
addEventHandler ( "onClientMarkerHit", vehicleMarker, MarkerGUIShoww ) 
  
function spawnCar ( button, state, absoluteX, absoluteYe ) 
  if ( source == spawnCar ) then guiSetVisible ( vehicleWindow, false ) showCursor ( false ) 
    if (guiGridListGetSelectedItem ( takeVehicleGrid ) ) then 
      local carName = guiGridListGetItemText ( takeVehicleGrid, guiGridListGetSelectedItem ( takeVehicleGrid ), 1 ) 
      local carID = getVehicleModelFromName ( carName ) 
      triggerServerEvent ("spawnCar", getLocalPlayer ( ), carID, carName ) 
    end 
  end 
end 
addEventHandler ("onClientGUIClick", root, spawnCar ) 
  
destinationCoords = { 
{-2524.92871, -618.60449, 132.56250}, 
{-1048.03088, -657.40356, 32.01260}, 
{259.51086, 1384.65955, 10.58594}, 
{-2254.77466, 2359.49536, 4.97963}, 
{2753.75195, -2473.34351, 13.64844} 
} 
  
function startBlips ( button ) 
    if ( button == spawnCar ) then 
        local markerTableData = destinationCoords[math.random ( #destinationCoords )] 
        local x = markerTableData[1] 
        local y = markerTableData[2] 
        local z = markerTableData[3] 
        startMarker = createMarker ( x, y, z, "cylinder", 3, 255, 255, 51 ) 
        startBlip = createBlipAttachedTo ( startMarker, 51 ) 
        setElementVisibleTo( startBlip, root, false ) 
        setElementVisibleTo( startBlip, source, true ) 
    end 
end 
addEventHandler ("onClientPlayerVehicleEnter", getRootElement (), startBlips ) 

Full script, except the trucker job gui.

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