Hi, im making a full car shop for the community and my server, but i have problems, when i start the resource, the 2 guis appears in 1 time, and have a little bugs with the buttons i think, anyone can help me plz, or fix the start resource bug, code:
Server side
carShopMarker = createMarker (2133.59,-1149.29, 23.3, "cylinder", 3, 255, 255, 0, 127)
carShopMarker2 = createMarker (562, -1270, 16, "cylinder", 2, 255, 255, 0, 127)
carShopMarker3 = createMarker (-1954,299,34,"cylinder",2,255,255,0,127)
carShopMarker4 = createMarker (-1663,1208,6,"cylinder",2,255,255,0,127)
carShopMarker5 = createMarker (1946,2068,10,"cylinder",2,255,255,0,127)
createBlipAttachedTo(carShopMarker,55,2,0,255,0,0,0,200)
createBlipAttachedTo(carShopMarker2,55,2,0,255,0,0,0,200)
createBlipAttachedTo(carShopMarker3,55,2,0,255,0,0,0,200)
createBlipAttachedTo(carShopMarker4,55,2,0,255,0,0,0,200)
createBlipAttachedTo(carShopMarker5,55,2,0,255,0,0,0,200)
addEvent ("watchGUI", true)
function markerHit (hitPlayer, matchingDimension)
if (source == carShopMarker) or (source == carShopMarker2) or (source == carShopMarker3) or (source == carShopMarker4) or (source == carShopMarker5) then
triggerClientEvent ("watchGUI", hitPlayer)
end
end
addEventHandler ("onMarkerHit", getRootElement(), markerHit)
addEvent ("carShopBuy", true)
addEventHandler ("carShopBuy", getRootElement(),
function(id, cost, name)
if (getPlayerMoney (source) >= tonumber(cost)) then
outputChatBox ("Has comprado un " .. name, source, 0, 255, 0, false)
outputChatBox ("Precio: " .. cost, source, 0, 255, 0, false)
takePlayerMoney (source, tonumber (cost))
setAccountData (getPlayerAccount (source), "funmodev2-car", tonumber(id))
setAccountData (getPlayerAccount (source), "funmodev2-paintjob", 3)
setAccountData (getPlayerAccount (source), "funmodev2-carupg", 0)
else
outputChatBox ("No tienes suficiente dinero para comprar un" .. name, source, 255, 0, 0, false)
end
end)
addEvent ("carTeletransport", true)
addEvent ("carSell", true)
function carSpawn ()
if not (isGuestAccount (getPlayerAccount (source))) and not (isPedInVehicle(source)) then
if (getElementData (source, "hisCar")) and (getElementData (source, "hisCar") ~= nil) and (getElementType(getElementData (source, "hisCar")) == "vehicle") then
setElementVelocity (getElementData (source, "hisCar"), 0,0,0)
setElementPosition (getElementData (source, "hisCar"), 1631.3790283203,-1094.9102783203,23.90625)
outputChatBox ("El vehiculo ha sido teletransportado con exito.", source, 0, 255, 0)
elseif not (getElementData (source, "hisCar")) then
local accountData = getAccountData (getPlayerAccount (source), "funmodev2-car")
if (accountData) then
vehicleID = getAccountData (getPlayerAccount (source), "funmodev2-car")
x,y,z = getElementPosition (source)
vehicle = createVehicle (carID, x +2, y, z +1)
setElementID (vehicle, getAccountName (getPlayerAccount(source)))
setElementData (source, "hisCar", vehicle)
outputChatBox ("El vehiculo ha sido teletransportado con exito.", source, 255, 0, 0)
if (getAccountData (getPlayerAccount(source), "funmodev2-carupg")) then
local upgrades = nil
local upgrades = {}
local upgrades = getAccountData (getPlayerAccount(source), "funmodev2-carupg")
for i,v in ipairs (upgrades) do
addVehicleUpgrade (vehicle, v)
end
end
if (getAccountData (getPlayerAccount(source), "funmodev2-paintjob")) then
local paintjob = getAccountData (getPlayerAccount(source), "funmodev2-paintjob")
setVehiclePaintjob (vehicle, paintjob)
end
if (getAccountData (getPlayerAccount(source), "funmodev2-carcolor1")) and (getAccountData (getPlayerAccount(source), "funmodev2-carcolor2")) then
local c1 = getAccountData (getPlayerAccount(source), "funmodev2-carcolor1")
local c2 = getAccountData (getPlayerAccount(source), "funmodev2-carcolor2")
setVehicleColor (vehicle, c1,c2,0,0)
end
else
outputChatBox ("No tienes ningun vehiculo.", source, 255, 0, 0)
end
else
outputChatBox ("Ya estas en un vehiculo!", source, 255, 0, 0)
end
end
end
addEventHandler ("carSpawn", getRootElement(), carSpawn)
function carDestroy (cost)
if not (isGuestAccount (getPlayerAccount (source))) then
if (isPedInVehicle (source)) then
if (getElementID(getPedOccupiedVehicle(source)) == getAccountName (getPlayerAccount(source))) then
local sell = getPlayerAccount (source), "hisCar", tonumber(cost)
givePlayerMoney (sell (source, "hisCar"))
destroyElement (getPedOccupiedVehicle (source))
removeElementData (source, "hisCar")
outputChatBox ("Vehiculo vendido, te han sido devueltos " ..cost, source, 0, 255, 0)
else
outputChatBox ("Este no es tu vehiculo!", source, 255, 0, 0)
end
elseif (not (isPedInVehicle (source))) and (getElementData (source, "hisCar")) and (getElementData (source, "hisCar") ~= nil) then
car=getElementData(source, "hisCar")
cancelEvent()
outputchatbox ("Este carro es gratis y no se puede vender", source, 255, 0, 0)
end
end
end
addEventHandler ("carSell", getRootElement(), carDestroy)
function lightsSwitch ()
if (isPedInVehicle (source)) then
local veh = getPedOccupiedVehicle (source)
if (getVehicleOverrideLights(veh) ~= 2) then
setVehicleOverrideLights(veh, 2)
outputChatBox ("Las luces del vehiculo han sido encendidas.", source, 0, 0, 255)
elseif (getVehicleOverrideLights(veh) ~= 1) then
setVehicleOverrideLights(veh, 1)
outputChatBox ("Las luces del vehiculo han sido apagadas.", source, 0, 0, 255)
end
else
outputChatBox ("No estas en un vehiculo!", source, 255, 0, 0)
end
end
addEvent("lightsCar",true)
addEventHandler("lightsCar",getRootElement(),lightsSwitch)
function lockSwitch ()
if (isPedInVehicle (source)) then
local veh = getPedOccupiedVehicle (source)
if not (isVehicleLocked (veh)) then
setVehicleLocked (veh, true)
setVehicleDoorsUndamageable (veh, true)
setVehicleDoorState (veh, 0, 0)
setVehicleDoorState (veh, 1, 0)
setVehicleDoorState (veh, 2, 0)
setVehicleDoorState (veh, 3, 0)
outputChatBox ("El vehiculo ha sido cerrado.", source, 255, 0, 0)
elseif (isVehicleLocked (veh)) then
setVehicleLocked (veh, false)
setVehicleDoorsUndamageable (veh, false)
outputChatBox ("El vehiculo ha sido abierto.", source, 0, 255, 0)
end
else
outputChatBox ("No estas en un vehiculo!", source, 255, 0, 0)
end
end
addEvent("lockCar",true)
addEventHandler("lockCar",getRootElement(),lockSwitch )
addEventHandler ("onVehicleStartEnter", getRootElement(),
function(player, seat, jacked, door)
if (isVehicleLocked (source) == true) then
local mannetjeNaam = getAccountName (getPlayerAccount (player))
local autoNaam = getElementID (source)
if (mannetjeNaam == autoNaam) then
setVehicleLocked (source, false)
outputChatBox ("El vehiculo ha sido abierto!", player, 255, 0, 0, false)
end
end
end)
addEventHandler ("onVehicleExplode", getRootElement(),
function()
local theOwner = getAccountName (getPlayerAccount(getPlayerFromName (getElementID (source))))
if (theOwner) then
removeElementData (theOwner, "hisCar")
end
end)
addEventHandler ("onPlayerQuit", getRootElement(),
function(quitType, reason, responsibleElement)
if (getElementData (source, "hisCar")) then
blowVehicle (getElementData (source, "hisCar"))
removeElementData (source, "hisCar")
end
end)
addEventHandler( "onResourceStop", getResourceRootElement( getThisResource() ),
function ()
for i,v in ipairs (getElementsByType ("player")) do
if (getElementData (v, "hisCar")) then
setElementHealth (getElementData (v, "hisCar"), 0)
removeElementData (v, "hisCar")
end
end
end
)
function destroyOnExplode ()
setTimer (destroyElement, 2500, 1, source)
end
addEventHandler ("onVehicleExplode", getRootElement(), destroyOnExplode)
Client side:
local lp = getLocalPlayer()
GUIEditor = {
label = {},
button = {},
window = {},
gridlist = {},
memo = {}
}
shopwindows = guiCreateWindow(352, 156, 510, 519, "Tienda de autos por MultiKiller", false)
guiWindowSetMovable(shopwindows, false)
guiWindowSetSizable(shopwindows, false)
shopgrid = guiCreateGridList(9, 21, 288, 390, false, shopwindows)
guiGridListAddColumn(shopgrid, "Autos", 0.4)
guiGridListAddColumn(shopgrid, "Precios", 0.4)
guiGridListSetItemText(shopgrid, 0, 1, "Virgo", false, false)
guiGridListSetItemText(shopgrid, 0, 2, "20000$", false, false)
guiGridListSetItemText(shopgrid, 1, 1, "Uranus", false, false)
guiGridListSetItemText(shopgrid, 1, 2, "27000$", false, false)
guiGridListSetItemText(shopgrid, 2, 1, "Turismo", false, false)
guiGridListSetItemText(shopgrid, 2, 2, "25000$", false, false)
guiGridListSetItemText(shopgrid, 3, 1, "Super GT", false, false)
guiGridListSetItemText(shopgrid, 3, 2, "30000$", false, false)
guiGridListSetItemText(shopgrid, 4, 1, "Sultan", false, false)
guiGridListSetItemText(shopgrid, 4, 2, "40000$", false, false)
guiGridListSetItemText(shopgrid, 5, 1, "Euros", false, false)
guiGridListSetItemText(shopgrid, 5, 2, "30000$", false, false)
guiGridListSetItemText(shopgrid, 6, 1, "Romero", false, false)
guiGridListSetItemText(shopgrid, 6, 2, "30000$", false, false)
guiGridListSetItemText(shopgrid, 7, 1, "Regina", false, false)
guiGridListSetItemText(shopgrid, 7, 2, "28000$", false, false)
guiGridListSetItemText(shopgrid, 8, 1, "Rancher", false, false)
guiGridListSetItemText(shopgrid, 8, 2, "20000$", false, false)
guiGridListSetItemText(shopgrid, 9, 1, "Primo", false, false)
guiGridListSetItemText(shopgrid, 9, 2, "23500$", false, false)
guiGridListSetItemText(shopgrid, 10, 1, "Mr.Whooper", false, false)
guiGridListSetItemText(shopgrid, 10, 2, "25000$", false, false)
guiGridListSetItemText(shopgrid, 11, 1, "Kart", false, false)
guiGridListSetItemText(shopgrid, 11, 2, "18000$", false, false)
guiGridListSetItemText(shopgrid, 12, 1, "Jester", false, false)
guiGridListSetItemText(shopgrid, 12, 2, "24000$", false, false)
guiGridListSetItemText(shopgrid, 13, 1, "Infernus", false, false)
guiGridListSetItemText(shopgrid, 13, 2, "40000$", false, false)
guiGridListSetItemText(shopgrid, 14, 1, "Hotdog", false, false)
guiGridListSetItemText(shopgrid, 14, 2, "23000$", false, false)
guiGridListSetItemText(shopgrid, 15, 1, "Harvester", false, false)
guiGridListSetItemText(shopgrid, 15, 2, "29000$", false, false)
guiGridListSetItemText(shopgrid, 16, 1, "Emperor", false, false)
guiGridListSetItemText(shopgrid, 16, 2, "24000$", false, false)
guiGridListSetItemText(shopgrid, 17, 1, "Elegy", false, false)
guiGridListSetItemText(shopgrid, 17, 2, "25000$", false, false)
guiGridListSetItemText(shopgrid, 18, 1, "Elegant", false, false)
guiGridListSetItemText(shopgrid, 18, 2, "26000$", false, false)
guiGridListSetItemText(shopgrid, 19, 1, "Comet", false, false)
guiGridListSetItemText(shopgrid, 19, 2, "29000$", false, false)
guiGridListSetItemText(shopgrid, 20, 1, "Cheetah", false, false)
guiGridListSetItemText(shopgrid, 20, 2, "35000$", false, false)
guiGridListSetItemText(shopgrid, 21, 1, "Caddy", false, false)
guiGridListSetItemText(shopgrid, 21, 2, "19000$", false, false)
guiGridListSetItemText(shopgrid, 22, 1, "Bullet", false, false)
guiGridListSetItemText(shopgrid, 22, 2, "42000$", false, false)
guiGridListSetItemText(shopgrid, 23, 1, "Buffalo", false, false)
guiGridListSetItemText(shopgrid, 23, 2, "37000$", false, false)
guiGridListSetItemText(shopgrid, 24, 1, "Bravura", false, false)
guiGridListSetItemText(shopgrid, 24, 2, "27500$", false, false)
guiGridListSetItemText(shopgrid, 25, 1, "Blade", false, false)
guiGridListSetItemText(shopgrid, 25, 2, "28500$", false, false)
guiGridListSetItemText(shopgrid, 26, 1, "Banshee", false, false)
guiGridListSetItemText(shopgrid, 26, 2, "45000$", false, false)
guiGridListSetItemText(shopgrid, 27, 1, "Bandito", false, false)
guiGridListSetItemText(shopgrid, 27, 2, "30000$", false, false)
guiGridListSetItemText(shopgrid, 28, 1, "Admiral", false, false)
guiGridListSetItemText(shopgrid, 28, 2, "23000$", false, false)
GUIEditor.memo[1] = guiCreateMemo(0, 390, 40, 47, "", false, shopgrid)
GUIEditor.memo[2] = guiCreateMemo(10, 505, 20, 0, "", false, shopwindows)
GUIEditor.memo[3] = guiCreateMemo(10, 417, 277, 88, "Sistema de tienda de autos profesional, \nelige el auto comprarlo y apreta F2\npuedes comprar mas de 2 autos\npuedes cerrarlo, teleportarlo al punto de reparo, etc", false, shopwindows)
guiMemoSetReadOnly(GUIEditor.memo[3], true)
buy = guiCreateButton(326, 28, 153, 90, "Comprar", false, shopwindows)
guiSetFont(buy, "sa-header")
GUIEditor.label[1] = guiCreateLabel(313, 444, 187, 51, "Por MultiKiller con Ayuda de \nTigreBlanco\nSaludos de Juramento Server", false, shopwindows)
guiSetFont(GUIEditor.label[1], "clear-normal")
guiLabelSetColor(GUIEditor.label[1], 17, 255, 0)
addEvent ("watchGUI", true)
function watchGUI ()
if (getLocalPlayer() == source) then
guiSetVisible (shopgrid, true)
showCursor (true)
end
end
addEventHandler ("watchGUI", getRootElement(), watchGUI)
function onClientClick (button, state, absoluteX, absoluteYe)
if (source == buy) then guiSetVisible (shopwindows, false) showCursor (false)
if (guiGridListGetSelectedItem (shopwindows)) then
local vehicleName = guiGridListGetItemText (shopgrid, guiGridListGetSelectedItem (shopgrid), 1)
local vehicleID = getVehicleModelFromName (vehicleName)
local vehicleCost = guiGridListGetItemText (shopgrid, guiGridListGetSelectedItem (shopgrid), 2)
triggerServerEvent ("carShopBuy", getLocalPlayer(), vehicleID, vehicleCost, vehicleName)
end
end
end
addEventHandler ("onClientGUIClick", getRootElement(), onClientClick)
carwindows = guiCreateWindow(398, 193, 463, 396, "Panel de Carro Por MultiKiller", false)
guiWindowSetSizable(carwindows, false)
cargridlist = guiCreateGridList(10, 28, 139, 358, false, carwindows)
carcolumn = guiGridListAddColumn(cargridlist, "Autos", 0.9)
carrow = guiGridListAddRow(cargridlist)
teletransport = guiCreateButton(166, 28, 130, 97, "Teletransportar", false, carwindows)
guiSetFont(teletransport, "default-bold-small")
guiSetProperty(teletransport, "NormalTextColour", "C8FFFFFF")
sell = guiCreateButton(310, 28, 129, 97, "Vender", false, carwindows)
guiSetFont(sell, "default-bold-small")
guiSetProperty(sell, "NormalTextColour", "C8FFFFFF")
lock = guiCreateButton(168, 265, 130, 110, "Cerrar", false, carwindows)
guiSetFont(lock, "default-bold-small")
guiSetProperty(lock, "NormalTextColour", "C8FFFFFF")
lights = guiCreateButton(310, 265, 129, 110, "Luces ON/OFF", false, carwindows)
guiSetFont(lights, "default-bold-small")
guiSetProperty(lights, "NormalTextColour", "C8FFFFFF")
watch = guiCreateButton(168, 140, 128, 105, "Observar", false, carwindows)
guiSetFont(watch, "default-bold-small")
guiSetProperty(watch, "NormalTextColour", "C8FFFFFF")
mark = guiCreateButton(310, 139, 129, 106, "Marcar", false, carwindows)
guiSetFont(watch, "default-bold-small")
guiSetProperty(watch, "NormalTextColour", "C8FFFFFF")
function resourceStart ()
bindKey ("F2", "down", carPanel)
end
addEventHandler ("onClientResourceStart", getResourceRootElement ( getThisResource () ), resourceStart)
function carPanel ()
panel = guiGetVisible (carwindows)
if (panel == true) then
guiSetVisible (carwindows, false)
showCursor (false)
end
if (panel == false) then
guiSetVisible (carwindows, true)
showCursor (true)
end
end
addEvent ("carTeletransport", true)
addEvent ("carSell", true)
function guiClick (button, state, absoluteX, absoluteY)
if (source == teletransport) then
triggerServerEvent ("carTeletransport", lp)
elseif (source == sell) then
triggerServerEvent ("carSell", lp)
elseif (source == watch) then
triggerServerEvent ("lookCar", lp)
elseif (source == lock) then
triggerServerEvent ("lockCar", lp)
elseif (source == lights) then
triggerServerEvent ("lightsCar", lp)
end
end
addEventHandler ("onClientGUIClick", getRootElement(), guiClick)
addEventHandler( "onClientGUIClick", getRootElement(),
function(vehiclename)
if (source == mark) then
local v = getElementModel (vehiclename)
vehicleBlips[v] = createBlipAttachedTo( v, 27, 1 )
end
end
)
addEventHandler( "onClientGuiClick", getRootElement(),
function(vehiclename)
if (source == mark) then
local vb = getElementModel (vehiclename)
destroyElement( vb[source] )
vb[source] = nil
end
end
)
function vehicleGridlist()
if ( eventName == "onClientPlayerJoin" ) then
guiGridListSetItemText ( cargridlist, guiGridListAddRow ( cargridlist ), carcolumn, getElementModel ( source ), false, false )
elseif ( eventName == "onClientPlayerQuit" ) then
for carrow = 0, guiGridListGetRowCount ( cargridlist ) do
if ( guiGridListGetItemText ( cargridlist, carrow, carcolumn ) == getElementModel ( source ) ) then
guiGridListRemoveRow ( cargridlist, carrow )
end
end
elseif
( eventName == "onClientGuiClick" ) then
triggerServerEvent ("carSell", source)
for carrow = 0, guiGridListGetRowCount ( cargridlist ) do
if ( guiGridListGetItemText ( cargridlist, carrow, carcolumn ) == getElementModel ( source ) ) then
guiGridListRemoveRow ( cargridlist, carrow )
end
end
addEventHandler ( "onClientPlayerJoin", root, vehicleGridList )
addEventHandler ( "onClientPlayerQuit", root, vehicleGridList )
end
end
In the debugscript doesnt output messages
Be feel to edit now, when i fix it will be compiled