DynamicBan Posted September 7, 2014 Share Posted September 7, 2014 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. 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
koeno100 Posted September 7, 2014 Share Posted September 7, 2014 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
DynamicBan Posted September 7, 2014 Author Share Posted September 7, 2014 Ah thats why, it works now, thnx Link to comment
DynamicBan Posted September 8, 2014 Author Share Posted September 8, 2014 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 IIYAMA Posted September 8, 2014 Moderators Share Posted September 8, 2014 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
DynamicBan Posted September 8, 2014 Author Share Posted September 8, 2014 What about the addEventHandler, when I click on a truck on the gui it shows the blip instead of showing it when I spawn one. Link to comment
Moderators IIYAMA Posted September 8, 2014 Moderators Share Posted September 8, 2014 https://wiki.multitheftauto.com/wiki/On ... layerSpawn Link to comment
DynamicBan Posted September 8, 2014 Author Share Posted September 8, 2014 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
Anubhav Posted September 8, 2014 Share Posted September 8, 2014 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
DynamicBan Posted September 8, 2014 Author Share Posted September 8, 2014 Once I remove this line it works, but every car I enter does create a blip. if ( button == spawnCar ) then If I add that line back it doesn't work anymore. Link to comment
Moderators IIYAMA Posted September 8, 2014 Moderators Share Posted September 8, 2014 debug your code if it doesn't work -_-" outputDebugString(tostring(button) .. " " .. tostring(spawnCar)) anyway where is spawnCar defined? Link to comment
DynamicBan Posted September 8, 2014 Author Share Posted September 8, 2014 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
Moderators IIYAMA Posted September 8, 2014 Moderators Share Posted September 8, 2014 You need to send the spawned car(element) back to clientside(after you spawn a vehicle), so you can define the spawnCar variable. and setElementVisibleTo is a server side function. https://wiki.multitheftauto.com/wiki/Se ... tVisibleTo orange = server red = client blue = shared Link to comment
Chris!i! Posted September 8, 2014 Share Posted September 8, 2014 Well, mitch your script is good but when a guy enter the marker job the GUI be shown to all players you must trigger it from Client to Server so you must create server side too. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now