Jump to content

Weird issue


Eshtiz

Recommended Posts

I have this weird issue regarding Valhalla's carshop & Vedic's.

For some reason I can only use The vedic shop because the Valhalla one ONLY sells vehicles that Vedic's car shop "chooses", random vehicles from time to time. I've checked thru every single line and I haven't found anything at all yet.

This is Valhalla's, client:

local rc = 10 
local bike = 15 
local low = 25 
local offroad = 35 
local sport = 100 
local van = 50 
local bus = 75 
local truck = 200 
local boat = 300 -- except dinghy 
local heli = 500 
local plane = 750 
local race = 75 
local vehicleTaxes = { 
    offroad, low, sport, truck, low, low, 1000, truck, truck, 200, -- dumper, stretch 
    low, sport, low, van, van, sport, truck, heli, van, low, 
    low, low, low, van, low, 1000, low, truck, van, sport, -- hunter 
    boat, bus, 1000, truck, offroad, van, low, bus, low, low, -- rhino 
    van, rc, low, truck, 500, low, boat, heli, bike, 0, -- monster, tram 
    van, sport, boat, boat, boat, truck, van, 10, low, van, -- caddie 
    plane, bike, bike, bike, rc, rc, low, low, bike, heli, 
    van, bike, boat, 20, low, low, plane, sport, low, low, -- dinghy 
    sport, bike, van, van, boat, 10, 75, heli, heli, offroad, -- baggage, dozer 
    offroad, low, low, boat, low, offroad, low, heli, van, van, 
    low, rc, low, low, low, offroad, sport, low, van, bike, 
    bike, plane, plane, plane, truck, truck, low, low, low, plane, 
    plane * 10, bike, bike, bike, truck, van, low, low, truck, low, -- hydra 
    10, 20, offroad, low, low, low, low, 0, 0, offroad, -- forklift, tractor, 2x train 
    low, sport, low, van, truck, low, low, low, rc, low, 
    low, low, van, plane, van, low, 500, 500, race, race, -- 2x monster 
    race, low, race, heli, rc, low, low, low, offroad, 0, -- train trailer 
    0, 10, 10, offroad, 15, low, low, 3*plane, truck, low,-- train trailer, kart, mower, sweeper, at400 
    low, bike, van, low, van, low, bike, race, van, low, 
    0, van, 2*plane, plane, rc, boat, low, low, low, offroad, -- train trailer, andromeda 
    low, truck, race, sport, low, low, low, low, low, van, 
    low, low 
} 
  
car, wCars, bClose, bBuy, gCars, lCost, lColors, sCol1, sCol2 = nil 
activeShop, shopID = nil 
  
local function countVehicles( ) 
    vehiclecount = {} 
    for key, value in pairs( getElementsByType( "vehicle" ) ) do 
        if isElement( value ) then 
            local model = getElementModel( value ) 
            if vehiclecount[ model ] then 
                vehiclecount[ model ] = vehiclecount[ model ] + 1 
            else 
                vehiclecount[ model ] = 1 
            end 
        end 
    end 
end 
  
local function copy( t ) 
    if type(t) == 'table' then 
        local r = {} 
        for k, v in pairs( t ) do 
            r[k] = copy( v ) 
        end 
        return r 
    else 
        return t 
    end 
end 
  
local function sort( a, b ) 
    return a[2] < b[2] 
end 
  
function showCarshopUI(id) 
    shopID = id 
     
    countVehicles() 
    activeShop = copy( g_shops[id] ) 
     
    local width, height = 400, 200 
    local scrWidth, scrHeight = guiGetScreenSize() 
    local x = scrWidth - width 
    local y = scrHeight/10 
     
    wCars = guiCreateWindow(x, y, width, height, activeShop.name .. ": Purchase a Vehicle", false) 
    guiWindowSetSizable(wCars, false) 
     
    bClose = guiCreateButton(0.6, 0.85, 0.2, 0.1, "Close", true, wCars) 
    bBuy = guiCreateButton(0.825, 0.85, 0.2, 0.1, "Buy", true, wCars) 
    addEventHandler("onClientGUIClick", bClose, hideCarshopUI, false) 
    addEventHandler("onClientGUIClick", bBuy, buyCar, false) 
     
    car = createVehicle(451, unpack(activeShop.previewpos)) 
    setVehicleColor(car, 0, 0, 0, 0) 
    setVehicleEngineState(car, true) 
    setVehicleOverrideLights(car, 2) 
     
    if activeShop.rotate then 
        addEventHandler("onClientRender", getRootElement(), rotateCar) 
    end 
     
    -- sort by price 
    for key, value in ipairs( activeShop ) do 
        if value[1] and value[2] and vehiclecount[ value[1] ] then 
            value[2] = value[2] + ( vehiclecount[ value[1] ] or 0 ) * 600 
        end 
    end 
    table.sort( activeShop, sort ) 
     
    gCars = guiCreateGridList(0.05, 0.1, 0.5, 0.75, true, wCars) 
    addEventHandler("onClientGUIClick", gCars, updateCar, false) 
    local col = guiGridListAddColumn(gCars, "Vehicle Model", 0.9) 
    for key, value in ipairs( activeShop ) do 
        local row = guiGridListAddRow(gCars) 
        guiGridListSetItemText(gCars, row, col, tostring(getVehicleNameFromModel(value[1])), false, false) 
        guiGridListSetItemData(gCars, row, col, tostring(key), false, false) 
    end 
     
    lCost = guiCreateLabel(0.15, 0.85, 0.4, 0.1, "Cost: --- - Tax: ---", true, wCars) 
    guiSetFont(lCost, "default-bold-small") 
    guiLabelSetHorizontalAlign(lCost, "right") 
    guiGridListSetSelectedItem(gCars, 0, 1) 
     
    updateCar() 
     
    lColors = guiCreateLabel(0.6, 0.15, 0.2, 0.1, "Colors:", true, wCars) 
    guiSetFont(lColors, "default-bold-small") 
     
    sCol1 = guiCreateScrollBar(0.6, 0.25, 0.35, 0.1, true, true, wCars) 
    sCol2 = guiCreateScrollBar(0.6, 0.35, 0.35, 0.1, true, true, wCars) 
     
    addEventHandler("onClientGUIScroll", sCol1, updateColors) 
    addEventHandler("onClientGUIScroll", sCol2, updateColors) 
     
    guiSetProperty(sCol1, "StepSize", "0.01") 
    guiSetProperty(sCol2, "StepSize", "0.01") 
     
    setCameraMatrix(unpack(activeShop.cameramatrix)) 
     
    guiSetInputEnabled(true) 
     
    outputChatBox("Welcome to " .. activeShop.name .. ".") 
end 
addEvent("showCarshopUI", true) 
addEventHandler("showCarshopUI", getRootElement(), showCarshopUI) 
  
function updateCar() 
    local row, col = guiGridListGetSelectedItem(gCars) 
     
    if row ~= -1 and col ~= -1 then 
        local key = tonumber(guiGridListGetItemData(gCars, row, col)) 
        local value = activeShop[key] 
        setElementModel(car, value[1]) 
        guiSetText(lCost, "Cost: " .. tostring(value[2]) .. "$" .. " - Tax: " .. ( vehicleTaxes[value[1]-399] or 25 ) .. "$") 
         
        local money = exports.global:getMoney(getLocalPlayer()) 
        if value[2] > money then 
            guiLabelSetColor(lCost, 255, 0, 0) 
            guiSetEnabled(bBuy, false) 
        else 
            guiLabelSetColor(lCost, 0, 255, 0) 
            guiSetEnabled(bBuy, true) 
        end 
    else 
        guiSetEnabled(bBuy, false) 
    end 
end 
  
function updateColors() 
    local col1 = guiScrollBarGetScrollPosition(sCol1) 
    local col2 = guiScrollBarGetScrollPosition(sCol2) 
    setVehicleColor(car, col1, col2, col1, col2) 
end 
  
function rotateCar() 
    local rx, ry, rz = getElementRotation(car) 
    setElementRotation(car, rx > 5 and rx < 355 and 0 or rx, ry > 5 and ry < 355 and 0 or ry, rz+1) 
     
    local x, y, z = unpack(activeShop.previewpos) 
    if getDistanceBetweenPoints3D(x, y, z, getElementPosition(car)) > 2 then 
        setElementPosition(car, x, y, z) 
    end 
end 
  
function hideCarshopUI() 
    destroyElement(bClose) 
    bClose = nil 
     
    destroyElement(bBuy) 
    bBuy = nil 
     
    destroyElement(car) 
    car = nil 
     
    destroyElement(gCars) 
    gCars = nil 
     
    destroyElement(lCost) 
    lCost = nil 
     
    destroyElement(lColors) 
    lColors = nil 
     
    destroyElement(sCol1) 
    sCol1 = nil 
     
    destroyElement(sCol2) 
    sCol2 = nil 
     
    destroyElement(wCars) 
    wCars = nil 
     
    if activeShop.rotate then 
        removeEventHandler("onClientRender", getRootElement(), rotateCar) 
    end 
     
    activeShop = nil 
    shopID = nil 
  
    setCameraTarget(getLocalPlayer()) 
    guiSetInputEnabled(false) 
end 
  
function buyCar(button) 
    if (button=="left") then 
        if exports.global:hasSpaceForItem(getLocalPlayer(), 3) then 
            local row, col = guiGridListGetSelectedItem(gCars) 
            local key = tonumber(guiGridListGetItemData(gCars, row, col)) 
            local value = activeShop[key] 
            local car = value[1] 
            local cost = value[2] 
            local col1 = guiScrollBarGetScrollPosition(sCol1) 
            local col2 = guiScrollBarGetScrollPosition(sCol2) 
             
            local px, py, pz, prz = unpack(activeShop.player) 
            local x, y, z, rz = unpack(activeShop.car) 
            local shopid = shopID 
  
            hideCarshopUI() 
            triggerServerEvent("buyCar", getLocalPlayer(), car, cost, col1, col2, x, y, z, rz, px, py, pz, prz, shopid) 
        else 
            outputChatBox("You can't carry the car keys - your inventory is full.", 255, 0, 0) 
        end 
    end 
end 
  
  

server:

local mysql = exports.mysql 
  
local priceCache = { } 
local vehiclecount = { } 
  
carshopPickup = createPickup(544.4990234375, -1292.7890625, 17.2421875, 3, 1239) 
exports['anticheat-system']:changeProtectedElementDataEx(carshopPickup, "shopid", 1, false) 
  
boatshopPickup = createPickup(715.35546875, -1705.5791015625, 2.4296875, 3, 1239) 
exports['anticheat-system']:changeProtectedElementDataEx(boatshopPickup, "shopid", 2, false) 
  
cheapcarshopPickup = createPickup( 2131.8115234375, -1151.3212890625, 24.060283660889, 3, 1239) 
exports['anticheat-system']:changeProtectedElementDataEx(cheapcarshopPickup, "shopid", 3, false) 
  
function pickupUse(thePlayer) 
    if getElementData(source, "shopid") then 
        if getElementData(thePlayer, "license.car") == 1 then 
            triggerClientEvent(thePlayer, "showCarshopUI", thePlayer, getElementData(source, "shopid")) 
        else 
            outputChatBox("You need a Driving License to buy a car.", thePlayer, 255, 0, 0) 
        end 
    end 
    cancelEvent() 
end 
addEventHandler("onPickupHit", getResourceRootElement(), pickupUse) 
  
local function copy( t ) 
    if type(t) == 'table' then 
        local r = {} 
        for k, v in pairs( t ) do 
            r[k] = copy( v ) 
        end 
        return r 
    else 
        return t 
    end 
end 
  
local function countVehicles( ) 
    vehiclecount = {} 
    for key, value in pairs( getElementsByType( "vehicle" ) ) do 
        if isElement( value ) then 
            local model = getElementModel( value ) 
            if vehiclecount[ model ] then 
                vehiclecount[ model ] = vehiclecount[ model ] + 1 
            else 
                vehiclecount[ model ] = 1 
            end 
        end 
    end 
end 
  
  
function buildPriceCache(shopID) 
    priceCache[shopID] = { } 
     
    local activeShop = copy( g_shops[shopID] ) 
    for key, value in ipairs( activeShop ) do 
        if value[1] and value[2] and vehiclecount[ value[1] ] then 
            priceCache[shopID][ value[1] ] = value[2] + ( vehiclecount[ value[1] ] or 0 ) * 600 
        end 
    end 
     
end 
  
function buyCar(id, cost, col1, col2, x, y, z, rz, px, py, pz, prz, shopID) 
    countVehicles() 
    buildPriceCache(shopID) 
  
    if not(priceCache[shopID][id]) then 
        exports.logs:logMessage("[CAR SHOP] " .. getPlayerIP(client).." \ ".. getPlayerName( client ) .. "  tried to buy an " .. getVehicleNameFromModel( id ) .. " at an non existing shop for $".. cost..")", 32) 
        return 
    end 
     
    if not (priceCache[shopID][id] == cost) then 
        exports.logs:logMessage("[CAR SHOP] " .. getPlayerIP(client).." \ " .. getPlayerName( client ) .. "  tried to buy an " .. getVehicleNameFromModel( id ) .. " at shop ".. shopID .." for $".. cost..")", 32) 
        return 
    end 
     
    if exports.global:hasMoney(client, cost) then 
        if exports.global:canPlayerBuyVehicle(client) then 
            outputChatBox("You bought a " .. getVehicleNameFromModel(id) .. " for " .. cost .. "$. Enjoy!", client, 255, 194, 14) 
             
            if shopID == 1 then 
                outputChatBox("You can set this vehicles spawn position by parking it and typing /park", client, 255, 194, 14) 
                outputChatBox("Vehicles parked near the dealership or bus spawn point will be deleted without notice.", client, 255, 0, 0) 
            elseif shopID == 2 then 
                outputChatBox("You can set this boats spawn position by parking it and typing /park", client, 255, 194, 14) 
                outputChatBox("Boats parked near the marina will be deleted without notice.", client, 255, 0, 0) 
            end 
            outputChatBox("If you do not use /park within an hour, your car will be DELETED.", client, 255, 0, 0) 
            outputChatBox("Press 'K' to unlock this vehicle.", client, 255, 194, 14) 
            makeCar(client, id, cost, col1, col2, x, y, z, rz, px, py, pz, prz) 
        else 
            outputChatBox("You tried to buy a car, but you have too many vehicles already.", client, 255, 0, 0) 
        end 
    end 
end 
addEvent("buyCar", true) 
addEventHandler("buyCar", getRootElement(), buyCar) 
  
function makeCar(thePlayer, id, cost, col1, col2, x, y, z, rz, px, py, pz, prz) 
    if not exports.global:takeMoney(thePlayer, cost) then 
        return 
    end 
     
    if not exports.global:canPlayerBuyVehicle(source) then 
        return 
    end 
     
    local rx = 0 
    local ry = 0 
         
    setElementPosition(thePlayer, px, py, pz) 
    setPedRotation(thePlayer, prz) 
     
    local username = getPlayerName(thePlayer) 
    local dbid = getElementData(thePlayer, "dbid") 
     
    local letter1 = string.char(math.random(65,90)) 
    local letter2 = string.char(math.random(65,90)) 
    local plate = letter1 .. letter2 .. math.random(0, 9) .. " " .. math.random(1000, 9999) 
    local locked = 0 
         
    local insertid = mysql:query_insert_free("INSERT INTO vehicles SET model='" .. mysql:escape_string(id) .. "', x='" .. mysql:escape_string(x) .. "', y='" .. mysql:escape_string(y) .. "', z='" .. mysql:escape_string(z) .. "', rotx='" .. mysql:escape_string(rx) .. "', roty='" .. mysql:escape_string(ry) .. "', rotz='" .. mysql:escape_string(rz) .. "', color1='" .. mysql:escape_string(col1) .. "', color2='" .. mysql:escape_string(col2) .. "', faction='-1', owner='" .. mysql:escape_string(dbid) .. "', plate='" .. mysql:escape_string(plate) .. "', currx='" .. mysql:escape_string(x) .. "', curry='" .. mysql:escape_string(y) .. "', currz='" .. mysql:escape_string(z) .. "', currrx='0', currry='0', currrz='" .. mysql:escape_string(rz) .. "', locked='" .. mysql:escape_string(locked) .. "'") 
     
    if (insertid) then 
        local veh = call( getResourceFromName( "vehicle-system" ), "createShopVehicle", insertid, id, x, y, z, 0, 0, rz, plate ) 
         
        exports['anticheat-system']:changeProtectedElementDataEx(veh, "fuel", 100, false) 
        exports['anticheat-system']:changeProtectedElementDataEx(veh, "Impounded", 0) 
         
        setVehicleRespawnPosition(veh, x, y, z, 0, 0, rz) 
        exports['anticheat-system']:changeProtectedElementDataEx(veh, "respawnposition", {x, y, z, 0, 0, rz}, false) 
        setVehicleLocked(veh, false) 
         
        setVehicleColor(veh, col1, col2, col1, col2) 
         
        setVehicleOverrideLights(veh, 1) 
        setVehicleEngineState(veh, false) 
        setVehicleFuelTankExplodable(veh, false) 
         
        -- make sure it's an unique key 
        call( getResourceFromName( "item-system" ), "deleteAll", 3, insertid ) 
        exports.global:giveItem( thePlayer, 3, insertid ) 
         
        exports['anticheat-system']:changeProtectedElementDataEx(veh, "fuel", 100, false) 
        exports['anticheat-system']:changeProtectedElementDataEx(veh, "engine", 0, false) 
        exports['anticheat-system']:changeProtectedElementDataEx(veh, "oldx", x, false) 
        exports['anticheat-system']:changeProtectedElementDataEx(veh, "oldy", y, false) 
        exports['anticheat-system']:changeProtectedElementDataEx(veh, "oldz", z, false) 
        exports['anticheat-system']:changeProtectedElementDataEx(veh, "faction", -1) 
        exports['anticheat-system']:changeProtectedElementDataEx(veh, "owner", dbid, false) 
        exports['anticheat-system']:changeProtectedElementDataEx(veh, "job", 0, false) 
         
        exports['vehicle-system']:reloadVehicle(insertid) 
        if getVehicleType" class="kw2">getVehicleType(veh) == "Boat" then 
            exports.global:givePlayerAchievement(thePlayer, 27) 
        else 
            exports.global:givePlayerAchievement(thePlayer, 17) -- my ride 
        end 
         
        exports.logs:logMessage("[CAR SHOP] " .. getPlayerName( thePlayer ) .. " bought car #" .. insertid .. " (" .. getVehicleNameFromModel( id ) .. ")", 9) 
    end 
end 
  
  

there are like 15 other scripts from Vedic's car shop ._. Anyone else bumped into this problem and knows the fix?

Edited by Guest
Link to comment

I do understand most parts of the script, I just don't see where the problem lays at.

It do not say anything at all in debugscript 3, and yes, the script is "wired" to my mySQL database in order to make the script function-able.

Everything works, every vehicle that should show up in the list shows, it just doesn't let people buy all of them. It is somehow connected to the other vehicle shop, EVEN if I turn it off it's the same problem, I have absolutely no idea where to start looking nor how to fix it.

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