LasHa Posted March 14, 2014 Posted March 14, 2014 (edited) guys hello i am new scripter and its my first script i ever made. you will laugh when you will see my script because of its bugs but i am new scripter. guys problem is that when player joins in server or when resource starts it shows features menu and car shop it self. also when i am buying car it doesn't adds in vehicle features. when i click f2 or write command /vehiclemenu it doesn't opens features menu. and some other bugs. i need your help to learn scripting please guys client.lua local vehicles = { { "Bullet", 1400000 }, { "Infernus", 1500000 }, { "Banshee", 250000 } } addEventHandler ( "onClientResourceStart", getResourceRootElement ( getThisResource() ), function() shopWindow = guiCreateWindow(30, 352, 333, 650, "Vehicle Sales", false) guiWindowSetSizable(shopWindow, false) shopGrid = guiCreateGridList(10, 62, 312, 542, false, shopWindow) vehicleGrid = guiGridListAddColumn(shopGrid, "Vehicle", 0.5) priceGrid = guiGridListAddColumn(shopGrid, "Price", 0.5) chooseLabel = guiCreateLabel(12, 24, 181, 15, "Choose one vehicle and click Buy", false, shopWindow) guiLabelSetColor(chooseLabel, 84, 238, 16) buyButton = guiCreateButton(12, 610, 98, 29, "Buy", false, shopWindow) colorButton = guiCreateButton(115, 610, 98, 29, "Choose Color", false, shopWindow) closeButton = guiCreateButton(218, 610, 98, 29, "Close", false, shopWindow) addEventHandler ( "onClientGUIClick", closeButton, hideShopWindow, false ) addEventHandler ( "onClientGUIClick", buyButton, buyVehicle, false ) for i, v in ipairs ( vehicles ) do local row = guiGridListAddRow ( shopGrid ) guiGridListSetItemText ( shopGrid, row, vehicleGrid, v[1], false, false ) guiGridListSetItemData ( shopGrid, row, vehicleGrid, v[2], false, false ) guiGridListSetItemText ( shopGrid, row, priceGrid, v[2], false, false ) end guiSetVisible (shopWndow, false) end ) function hideShopWindow () guiSetVisible (shopWindow, false) showCursor (false) end addEvent ( "showShopGui", true ) addEventHandler ( "showShopGui", root, function ( thePlayer ) if ( thePlayer == getLocalPlayer() ) then guiSetVisible ( shopWindow, true ) showCursor ( true ) end end ) function buyVehicle () local row = guiGridListGetSelectedItem ( shopGrid ) if ( row ~= -1 ) then local price = guiGridListGetItemData ( shopGrid, row, vehicleGrid ) local vehicleName = guiGridListGetItemText ( shopGrid, row, vehicleGrid ) triggerServerEvent ( "buyVehicle", getLocalPlayer(), getLocalPlayer(), price, vehicleName) else outputChatBox ( "Please make a selection first.", getLocalPlayer() ) end end server.lua local shopMarker = createMarker ( 2131.7788, -1149.8193, 23, "cylinder", 2, 255, 255, 0, 150 ) local shopBlip = createBlipAttachedTo ( shopMarker, 55 ) setBlipVisibleDistance ( shopBlip, 500 ); addEventHandler ( "onMarkerHit", shopMarker, function ( thePlayer ) if ( getElementType ( thePlayer ) == "player" ) then triggerClientEvent ( "showShopGui", thePlayer, thePlayer ) end end ) addEvent ( "buyVehicle", true ) addEventHandler ( "buyVehicle", root, function ( thePlayer, price, vehicle ) local playerMoney = getPlayerMoney ( thePlayer ) if ( playerMoney >= price ) then local model = getVehicleModelFromName ( vehicle ) local accName = getAccountName ( getPlayerAccount ( thePlayer )) local insertQry = ( "INSERT INTO `vehicles` ( VehicleModel, VehicleColor1, VehicleColor2, VehicleColor3, VehicleColor4, VehicleX, VehicleY, VehicleZ, VehicleRot, VehicleFuel, VehicleHealth, VehicleOwner, VehiclePlate ) VALUES ( '".. model .."', '".. tostring ( color1 ) .."', '".. tostring ( color2 ) .."', '".. tostring ( color3 ) .."', '".. tostring ( color4 ) .."', '2134', '-1135', '26', '100.85', '100', '1000', '".. ( accName ) .."', '".. tostring ( plate ) .."' )" ); if ( insertQry ) then triggerClientEvent ( "hideShopGui", thePlayer, thePlayer ) outputChatBox ( "Your purchase has been completed successfully, you can now spawn it using the vehicle menu. ( /vehiclemenu )", thePlayer ); takePlayerMoney ( thePlayer, price ) else outputChatBox ( "Something went wrong, please notify an administrator about this.", thePlayer ); end else outputChatBox ( "You can't afford this vehicle.", thePlayer ) end end ) features-c.lua local marked = false; local markedBlip = nil; local markedDbid = nil; local markedTimer = nil; addEventHandler ( "onClientResourceStart", getResourceRootElement ( getThisResource() ), function() featuresWindow = guiCreateWindow(976, 290, 294, 429, "Vehicle Features", false) guiWindowSetSizable(featuresWindow, false) guiSetAlpha(featuresWindow, 0.95) chosenLabel = guiCreateLabel(10, 32, 204, 15, "No Vehicles Selected", false, featuresWindow) guiLabelSetColor(chosenLabel, 76, 116, 228) featuresGrid = guiCreateGridList(10, 116, 273, 238, false, featuresWindow) vehicleColumnGrid = guiGridListAddColumn(featuresGrid, "Vehicle", 0.5) healthColumnGrid = guiGridListAddColumn(featuresGrid, "Health", 0.5) recoverButton = guiCreateButton(9, 78, 59, 32, "Recover", false, featuresWindow) lockButton = guiCreateButton(224, 78, 59, 32, "Un/Lock", false, featuresWindow) blipButton = guiCreateButton(159, 78, 59, 32, "Un/Blip", false, featuresWindow) pickButton = guiCreateButton(9, 364, 50, 34, "Pick", false, featuresWindow) sellButton = guiCreateButton(69, 364, 50, 34, "Sell", false, featuresWindow) hideButton = guiCreateButton(129, 364, 50, 34, "Hide", false, featuresWindow) closeButton = guiCreateButton(210, 364, 73, 38, "Close", false, featuresWindow) addEventHandler ( "onClientGUIClick", pickButton, spawnVehicle, false ); addEventHandler ( "onClientGUIClick", blipButton, markVehicle, false ); addEventHandler ( "onClientGUIClick", closeButton, closeMenu, false ); guiSetVisible ( featuresMain, false ); end ) function spawnVehicle () local row = guiGridListGetSelectedItem ( featuresGrid ); if ( row ~= -1 ) then local dbid = guiGridListGetItemData ( featuresGrid, row, vehicleColumnGrid ); triggerServerEvent ( "spawnVehicle", getLocalPlayer(), getLocalPlayer(), dbid ); else outputChatBox ( "Please select a vehicle first.", getLocalPlayer() ); end end function markVehicle () if ( marked ) then outputChatBox ( "Your vehicle is still marked.", getLocalPlayer() ); else local row = guiGridListGetSelectedItem ( featuresGrid ); if ( row ~= -1 ) then local dbid = guiGridListGetItemData ( featuresGrid, row, vehicleColumnGrid ); for i, v in ipairs ( getElementsByType ( "vehicle" ) ) do if ( getElementData ( v, "vehicle:dbid" ) == tonumber ( dbid ) ) then markedBlip = createBlipAttachedTo ( v, 41 ); marked = true; markedDbid = tonumber ( dbid ); markedTimer = setTimer ( function () destroyElement ( markedBlip ); marked = false; markedBlip = nil; markedDbid = nil; markedTimer = nil; end, 12000, 1 ); return; end end end end end addEventHandler ( "onClientVehicleEnter", root, function ( thePlayer ) if ( thePlayer == getLocalPlayer() ) then if ( getElementData ( source, "vehicle:dbid" ) ~= nil ) then if ( getElementData ( source, "vehicle:dbid" ) == markedDbid ) then destroyElement ( markedBlip ); marked = false; markedBlip = nil; markedDbid = nil; if ( isTimer ( markedTimer ) ) then killTimer ( markedTimer ); markedTimer = nil; end end end end end ); function closeMenu () triggerEvent ( "showVehicleMenu", getLocalPlayer(), getLocalPlayer() ); end features-s.lua addCommandHandler ( "vehiclemenu", function ( thePlayer ) local vehicles = getPlayerVehicles ( thePlayer ); triggerClientEvent ( "showVehicleMenu", thePlayer, thePlayer, vehicles ); end ); function getPlayerVehicles ( thePlayer ) if not ( thePlayer ) then return; end local accName = getAccountName ( getPlayerAccount ( thePlayer ) ); outputDebugString ( thePlayer ); local query = ( "SELECT * FROM `vehicles` WHERE `VehicleOwner` = '".. ( accName ) .."'" ); if ( query[1] ~= nil ) then return query; end return {}; end addEvent ( "getPlayerVehicles", true ); addEventHandler ( "getPlayerVehicles", getRootElement(), getPlayerVehicles ); addEvent ( "spawnVehicle", true ); addEventHandler ( "spawnVehicle", root, function ( plr, dbid ) for i, e in ipairs ( getElementsByType ( "vehicle" ) ) do if ( getElementData ( e, "vehicle:dbid" ) == tonumber ( dbid ) ) then local owner = getElementData ( e, "vehicle:owner" ); local dbid = getElementData ( e, "vehicle:dbid" ); local fuel = getElementData ( e, "vehicle:fuel" ); local model = getElementModel ( e ); local x, y, z = getElementPosition ( e ); local rotX, rotY, rotZ = getElementRotation ( e ); local health = getElementHealth ( e ); local update = ( "UPDATE `vehicles` SET `VehicleX` = '".. x .."', `VehicleY` = '".. y .."', `VehicleZ` = '".. z .."', `VehicleFuel` = '".. fuel .."', `VehicleRot` = '".. rotX .."', `VehicleHealth` = '".. health .."' WHERE `VehicleId` = '".. dbid .."'" ); destroyElement ( e ); local vehicle = ( "SELECT * FROM `vehicles` WHERE `VehicleId` = '".. dbid .."'" ); if ( vehicle[1] ~= nil ) then local v = nil; local x, y, z = getElementPosition ( plr ); v = createVehicle ( vehicle [ 1 ] [ "VehicleModel"], x, y, z ); warpPedIntoVehicle ( plr, v ); else v = createVehicle ( vehicle [ 1 ] [ "VehicleModel"], vehicle [ 1 ] [ "VehicleX" ], vehicle [ 1 ] [ "VehicleY" ], vehicle [ 1 ] [ "VehicleZ" ] ); end setElementRotation ( v, 0, 0, vehicle [ 1 ] [ "VehicleRot" ] ); setElementData ( v, "vehicle:engine", false ); setElementData ( v, "vehicle:fuel", tonumber ( vehicle [ 1 ] [ "VehicleFuel" ] ) ); setElementHealth ( v, vehicle [ 1 ] [ "VehicleHealth" ] ); setElementData ( v, "vehicle:dbid", tonumber ( vehicle [ 1 ] [ "VehicleId" ] ) ); setElementData ( v, "vehicle:owner", getAccountName ( getPlayerAccount ( plr ) ) ); end end end ) addEventHandler ( "onVehicleStartEnter", root, function ( plr ) local owner = getElementData ( source, "vehicle:owner" ); if ( owner == getAccountName ( getPlayerAccount ( plr ) ) ) then setVehicleLocked ( source, false ); end end ); addEventHandler ( "onPlayerSpawn", root, function () bindKey ( source, "F2", "down", "vehiclemenu" ); end ); meta.xml <meta> <script src="server.lua" type="server" /> <script src="client.lua" type="client" /> <script src="features-s.lua" type="server" /> <script src="features-c.lua" type="client" /> </meta> Edited March 14, 2014 by Guest
LasHa Posted March 14, 2014 Author Posted March 14, 2014 Guys Why noone helps? i thinked you were nice guys and you could help me
justn Posted March 14, 2014 Posted March 14, 2014 Guys Why noone helps? i thinked you were nice guys and you could help me Learn to wait patiently for others to help you. Features_c.lua addEventHandler ( "onClientResourceStart", getResourceRootElement ( getThisResource() ), function() featuresWindow = guiCreateWindow(976, 290, 294, 429, "Vehicle Features", false) guiWindowSetSizable(featuresWindow, false) guiSetAlpha(featuresWindow, 0.95) chosenLabel = guiCreateLabel(10, 32, 204, 15, "No Vehicles Selected", false, featuresWindow) guiLabelSetColor(chosenLabel, 76, 116, 228) featuresGrid = guiCreateGridList(10, 116, 273, 238, false, featuresWindow) vehicleColumnGrid = guiGridListAddColumn(featuresGrid, "Vehicle", 0.5) healthColumnGrid = guiGridListAddColumn(featuresGrid, "Health", 0.5) recoverButton = guiCreateButton(9, 78, 59, 32, "Recover", false, featuresWindow) lockButton = guiCreateButton(224, 78, 59, 32, "Un/Lock", false, featuresWindow) blipButton = guiCreateButton(159, 78, 59, 32, "Un/Blip", false, featuresWindow) pickButton = guiCreateButton(9, 364, 50, 34, "Pick", false, featuresWindow) sellButton = guiCreateButton(69, 364, 50, 34, "Sell", false, featuresWindow) hideButton = guiCreateButton(129, 364, 50, 34, "Hide", false, featuresWindow) closeButton = guiCreateButton(210, 364, 73, 38, "Close", false, featuresWindow) addEventHandler ( "onClientGUIClick", pickButton, spawnVehicle, false ); addEventHandler ( "onClientGUIClick", blipButton, markVehicle, false ); addEventHandler ( "onClientGUIClick", closeButton, closeMenu, false ); guiSetVisible ( featuresMain, false ) end ) Change guiSetVisible ( featuresMain, false ) to guiSetVisible ( featuresWindow, false ) and in client.lua change this: shopWindow = guiCreateWindow(30, 352, 333, 650, "Vehicle Sales", false) guiWindowSetSizable(shopWindow, false) shopGrid = guiCreateGridList(10, 62, 312, 542, false, shopWindow) vehicleGrid = guiGridListAddColumn(shopGrid, "Vehicle", 0.5) priceGrid = guiGridListAddColumn(shopGrid, "Price", 0.5) chooseLabel = guiCreateLabel(12, 24, 181, 15, "Choose one vehicle and click Buy", false, shopWindow) guiLabelSetColor(chooseLabel, 84, 238, 16) buyButton = guiCreateButton(12, 610, 98, 29, "Buy", false, shopWindow) colorButton = guiCreateButton(115, 610, 98, 29, "Choose Color", false, shopWindow) closeButton = guiCreateButton(218, 610, 98, 29, "Close", false, shopWindow) to this: shopWindow = guiCreateWindow(30, 352, 333, 650, "Vehicle Sales", false) guiWindowSetSizable(shopWindow, false) shopGrid = guiCreateGridList(10, 62, 312, 542, false, shopWindow) vehicleGrid = guiGridListAddColumn(shopGrid, "Vehicle", 0.5) priceGrid = guiGridListAddColumn(shopGrid, "Price", 0.5) chooseLabel = guiCreateLabel(12, 24, 181, 15, "Choose one vehicle and click Buy", false, shopWindow) guiLabelSetColor(chooseLabel, 84, 238, 16) buyButton = guiCreateButton(12, 610, 98, 29, "Buy", false, shopWindow) colorButton = guiCreateButton(115, 610, 98, 29, "Choose Color", false, shopWindow) closeButton = guiCreateButton(218, 610, 98, 29, "Close", false, shopWindow) guiSetVisible ( shopWindow, false )
LasHa Posted March 15, 2014 Author Posted March 15, 2014 okey gui fixed when start resource and join but why it doesn't opening with f2 and with /vehiclemenu its okey
Moderators Citizen Posted March 15, 2014 Moderators Posted March 15, 2014 Try this: addEventHandler ( "onPlayerJoin", root, function () bindKey ( source, "F2", "down", "vehiclemenu" ) end ) If it doesn't work, then try this workaround instead: addEventHandler ( "onPlayerJoin", root, function () bindKey ( source, "F2", "down", function ( player ) executeCommandHandler( "vehiclemenu", player ) end, source) end) If it's still not working, then try to bind it on another key.
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