MajdMTA Posted February 17, 2016 Share Posted February 17, 2016 Hello.. there's a small problem in addCommandHandler, because there's not function name. Check this addEvent("SpawnMyVehicle", true) addEventHandler("SpawnMyVehicle", root, function(id) if not playerVehicles[source] then playerVehicles[source] = {} end if #playerVehicles[source] >= 1 then for ind,car in ipairs(playerVehicles[source]) do if not isElement(car) then playerVehicles[source][ind] = nil end end end if #playerVehicles[source] >= 1 then exports.CSFtexts:output("You can only spawn 1 vehicle Destroy the Current vehicle first.", source, 255, 85, 0, true) return end local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountName(getPlayerAccount(source)), id), -1) if type(data) == "table" and #data ~= 0 then if getVehicleByID(id) then exports.CSFtexts:output("Your Vehicle "..getVehicleNameFromModel(data[1]["Model"]).." is already spawned.", source, 255, 85, 0, true) else local color = split(data[1]["Colors"], ',') r1 = color[1] or 255 g1 = color[2] or 255 b1 = color[3] or 255 r2 = color[4] or 255 g2 = color[5] or 255 b2 = color[6] or 255 vehicle = createVehicle(data[1]["Model"], data[1]["X"], data[1]["Y"], data[1]["Z"], 0, 0, data[1]["RotZ"]) setElementData(vehicle, "ID", id) table.insert(playerVehicles[source],vehicle) local fuelnu = data[1]["fuel"] or 100 local tune = fromJSON(data[1]["handling"]) -- outputChatBox(data[1]["handling"],source,255,0,0) --outputChatBox(tostring(tune),source,255,0,255) exports.CSFcarTune:setCarData(vehicle,tune,true) setElementData(vehicle, "vehicleFuel", fuelnu) local upd = split(tostring(data[1]["Upgrades"]), ',') for i, upgrade in ipairs(upd) do addVehicleUpgrade(vehicle, upgrade) end local Paintjob = data[1]["Paintjob"] or 3 setVehiclePaintjob(vehicle, Paintjob) setVehicleColor(vehicle, r1, g1, b1, r2, g2, b2) if data[1]["HP"] <= 255.5 then data[1]["HP"] = 255 end setElementHealth(vehicle, data[1]["HP"]) setElementData(vehicle, "Owner", source) vv[vehicle] = setTimer(function(source) -- if not isElement(source) and isTimer(vv[vehicle]) then killTimer(vv[source]) vv[source] = nil end -- if isElement(source) and getElementHealth(source) <= 255 then -- setElementHealth(source, 255.5) -- setVehicleDamageProof(source, true) -- setVehicleEngineState(source, false) -- end end, 50, 0, vehicle) addEventHandler("onVehicleDamage", vehicle, function(loss) local account = getAccountName(getPlayerAccount(getElementData(source, "Owner"))) setTimer(function(source) if isElement(source) then dbExec(db, "UPDATE VehicleList SET HP = ? WHERE Account = ? AND Model = ?", getElementHealth(source), account, getElementModel(source)) updateVehicleInfo(getElementData(source, "Owner")) end end, 100, 1, source) end) addEventHandler("onVehicleEnter", vehicle, function(player) if getElementHealth(source) <= 255.5 then setVehicleEngineState(source, false) else if isVehicleDamageProof(source) then setVehicleDamageProof(source, false) end end end) exports.CSFtexts:output("Your Vehicle "..getVehicleNameFromModel(data[1]["Model"]).." has been spawned.", source, 255, 85, 0, true) cur = getElementData(source,"spawnedcars") or {} table.insert(cur,getVehicleNameFromModel(data[1]["Model"])) setElementData(source,"spawnedcars",cur) end else exports.CSFtexts:output("There might be problem with this vehicle, please call an admin.", source, 255, 85, 0, true) end end) Can't you add addCommandHandler for this function? Link to comment
Bonus Posted February 17, 2016 Share Posted February 17, 2016 function spawnMyVehicle_func (id) if not playerVehicles[source] then playerVehicles[source] = {} end if #playerVehicles[source] >= 1 then for ind,car in ipairs(playerVehicles[source]) do if not isElement(car) then playerVehicles[source][ind] = nil end end end if #playerVehicles[source] >= 1 then exports.CSFtexts:output("You can only spawn 1 vehicle Destroy the Current vehicle first.", source, 255, 85, 0, true) return end local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountName(getPlayerAccount(source)), id), -1) if type(data) == "table" and #data ~= 0 then if getVehicleByID(id) then exports.CSFtexts:output("Your Vehicle "..getVehicleNameFromModel(data[1]["Model"]).." is already spawned.", source, 255, 85, 0, true) else local color = split(data[1]["Colors"], ',') r1 = color[1] or 255 g1 = color[2] or 255 b1 = color[3] or 255 r2 = color[4] or 255 g2 = color[5] or 255 b2 = color[6] or 255 vehicle = createVehicle(data[1]["Model"], data[1]["X"], data[1]["Y"], data[1]["Z"], 0, 0, data[1]["RotZ"]) setElementData(vehicle, "ID", id) table.insert(playerVehicles[source],vehicle) local fuelnu = data[1]["fuel"] or 100 local tune = fromJSON(data[1]["handling"]) -- outputChatBox(data[1]["handling"],source,255,0,0) --outputChatBox(tostring(tune),source,255,0,255) exports.CSFcarTune:setCarData(vehicle,tune,true) setElementData(vehicle, "vehicleFuel", fuelnu) local upd = split(tostring(data[1]["Upgrades"]), ',') for i, upgrade in ipairs(upd) do addVehicleUpgrade(vehicle, upgrade) end local Paintjob = data[1]["Paintjob"] or 3 setVehiclePaintjob(vehicle, Paintjob) setVehicleColor(vehicle, r1, g1, b1, r2, g2, b2) if data[1]["HP"] <= 255.5 then data[1]["HP"] = 255 end setElementHealth(vehicle, data[1]["HP"]) setElementData(vehicle, "Owner", source) vv[vehicle] = setTimer(function(source) -- if not isElement(source) and isTimer(vv[vehicle]) then killTimer(vv[source]) vv[source] = nil end -- if isElement(source) and getElementHealth(source) <= 255 then -- setElementHealth(source, 255.5) -- setVehicleDamageProof(source, true) -- setVehicleEngineState(source, false) -- end end, 50, 0, vehicle) addEventHandler("onVehicleDamage", vehicle, function(loss) local account = getAccountName(getPlayerAccount(getElementData(source, "Owner"))) setTimer(function(source) if isElement(source) then dbExec(db, "UPDATE VehicleList SET HP = ? WHERE Account = ? AND Model = ?", getElementHealth(source), account, getElementModel(source)) updateVehicleInfo(getElementData(source, "Owner")) end end, 100, 1, source) end) addEventHandler("onVehicleEnter", vehicle, function(player) if getElementHealth(source) <= 255.5 then setVehicleEngineState(source, false) else if isVehicleDamageProof(source) then setVehicleDamageProof(source, false) end end end) exports.CSFtexts:output("Your Vehicle "..getVehicleNameFromModel(data[1]["Model"]).." has been spawned.", source, 255, 85, 0, true) cur = getElementData(source,"spawnedcars") or {} table.insert(cur,getVehicleNameFromModel(data[1]["Model"])) setElementData(source,"spawnedcars",cur) end else exports.CSFtexts:output("There might be problem with this vehicle, please call an admin.", source, 255, 85, 0, true) end end addEvent("SpawnMyVehicle", true) addEventHandler("SpawnMyVehicle", root, spawnMyVehicle_func ) addCommandHandler ( "spawnvehicle", function ( player, _, int ) triggerEvent ( "SpawnMyVehicle", player, tonumber ( int ) ) end ) Link to comment
MajdMTA Posted February 17, 2016 Author Share Posted February 17, 2016 Omg i gave you wrong one, srry addEvent("DestroyMyVehicle", true) addEventHandler("DestroyMyVehicle", root, function (id) local vehicle = getVehicleByID(id) if isElement(vehicle) then local data = dbPoll(dbQuery(db, "SELECT * FROM VehicleList WHERE Account = ? AND ID = ?", getAccountName(getPlayerAccount(source)), id), -1) if type(data) == "table" and #data ~= 0 then local aman = getVehicleOccupant(vehicle) destroyVehicle(vehicle) if isElement(source) and playerVehicles[source] then for i=1,#playerVehicles[source] do if playerVehicles[source][i] == vehicle then table.remove(playerVehicles[source],i) break end end else playerVehicles[source] = nil end exports.CSFtexts:output ("Your Vehicle "..getVehicleNameFromModel(data[1]["Model"]).." has been destroyed.", source, 255, 85, 0, true) cur = getElementData(source,"spawnedcars") or {} for ind,veh in ipairs(cur) do if veh == getVehicleNameFromModel(data[1]["Model"]) then table.remove(cur,ind) end end setElementData(source,"spawnedcars",cur) else exports.CSFtexts:output("Select the Vehicle that you want to destroy.", source, 255, 85, 0, true) end else exports.CSFtexts:output("Your Vehicle is not spawned.", source, 255, 85, 0, true) end end) Link to comment
Bonus Posted February 17, 2016 Share Posted February 17, 2016 Do it yourself now. It's nearly the same. Link to comment
MajdMTA Posted February 18, 2016 Author Share Posted February 18, 2016 Tried.. vehicle didn't hide. 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