ramzi Posted January 1, 2015 Share Posted January 1, 2015 guys i have a script works fine which is used to lock vehicles,when i create 1 vehicle it works fine,but i create too many vehicles,all the vehicles respawn up of each other(in 1 dimension) and this is the error msg: [2015-01-01 12:20:14] WARNING:lock\vehicles_server.lua:195: Bad argument @ 'respawnVehicle' [Expected element at argument 1] and here is the lua line 195: function respawnExplodedVehicle() setTimer(respawnVehicle, 5000, 1, source) end addEventHandler("onVehicleExplode", getRootElement(), respawnExplodedVehicle) function checkVehicles ( theVehicle ) local driver = getVehicleOccupant ( theVehicle ) if driver == false then respawnVehicle ( theVehicle ) end end Link to comment
ramzi Posted January 1, 2015 Author Share Posted January 1, 2015 Note:it happens when i create more than 1 vehicle Link to comment
ViRuZGamiing Posted January 1, 2015 Share Posted January 1, 2015 function respawnExplodedVehicle() if getVehicleOccupant(source) then setTimer(respawnVehicle, 5000, 1, source) end end addEventHandler("onVehicleExplode", getRootElement(), respawnExplodedVehicle) Link to comment
ramzi Posted January 1, 2015 Author Share Posted January 1, 2015 so i replace the whole code with this? Link to comment
ramzi Posted January 1, 2015 Author Share Posted January 1, 2015 still have a problem,vehicles didnt respawn. error msg: [2015-01-01 15:05:01] ERROR: lock\vehicles_server.lua:50: attempt to index local 'veh' (a nil value) lua line 50: local model, x, y, z, rot, color, upgrades = tonumber(veh["vehicleModel"]), tonumber(veh["posX"]), tonumber(veh["posY"]), tonumber(veh["posZ"]), tonumber(veh["rot"]), tostring(veh["color"]), tostring(veh["upgrades"]) Link to comment
ViRuZGamiing Posted January 2, 2015 Share Posted January 2, 2015 What on earth are you even trying here? Link to comment
ramzi Posted January 2, 2015 Author Share Posted January 2, 2015 What on earth are you even trying here? What do u mean? Link to comment
Mizudori Posted January 2, 2015 Share Posted January 2, 2015 still have a problem,vehicles didnt respawn.error msg: [2015-01-01 15:05:01] ERROR: lock\vehicles_server.lua:50: attempt to index local 'veh' (a nil value) lua line 50: local model, x, y, z, rot, color, upgrades = tonumber(veh["vehicleModel"]), tonumber(veh["posX"]), tonumber(veh["posY"]), tonumber(veh["posZ"]), tonumber(veh["rot"]), tostring(veh["color"]), tostring(veh["upgrades"]) What is this code all about ? You are taking this info from some table ? if you are taking it from element you need to use getElementPosition, GetVehicleColor, getVehicleModel, getElementModel and you dont need to make it to string and number posision is already in int, and other in strings Link to comment
ramzi Posted January 2, 2015 Author Share Posted January 2, 2015 i tried to do this: local model, x, y, z, rot, color, upgrades = tonumber("getvehicleModel"), tonumber("getvehicleposX"), tonumber("getvehicleposY"), tonumber(getvehicle"posZ"), tonumber(getvehicle["rot"]), tostring("getvehiclecolor"]), tostring(getvehicleupgrades"]) Link to comment
Mizudori Posted January 2, 2015 Share Posted January 2, 2015 i tried to do this: local model, x, y, z, rot, color, upgrades = tonumber("getvehicleModel"), tonumber("getvehicleposX"), tonumber("getvehicleposY"), tonumber(getvehicle"posZ"), tonumber(getvehicle["rot"]), tostring("getvehiclecolor"]), tostring(getvehicleupgrades"]) If you are using it in function respawnExplodedVehicle() you can just use source instead of veh local x,y,z = getElementPosition(veh) local c1,c2,c3,c4 = getVehicleColor(veh) local upgrades = getVehicleUpgrades(veh) <--- you need to use for cuz this is a table. local mode = getElementModel(veh) Link to comment
ramzi Posted January 2, 2015 Author Share Posted January 2, 2015 sry but some error appeared and the vehicles didnt respawn: lua codes line 27: local vehicle = createVehicle(tonumber(model),x,y,z,0,0,rot) with the lua u gave me: local x,y,z = getElementPosition(veh) local c1,c2,c3,c4 = getVehicleColor(veh) local upgrades = getVehicleUpgrades(veh) local mode = getElementModel(veh) error msg: [2014-12-20 16:58:12] WARNING: lock\vehicles_server.lua:27: Bad argument @ 'createVehicle' [Expected vector3 at argument 2, got boolean] should i replace createVehicle with createElement? Link to comment
Mizudori Posted January 2, 2015 Share Posted January 2, 2015 Can you copy paste the whole function? Link to comment
ramzi Posted January 2, 2015 Author Share Posted January 2, 2015 sure: function createPrivateVehicle(model, x, y, z, rot, color, upgrades, dataType, allowedTo) local vehicle = createVehicle(tonumber(model),x,y,z,0,0,rot) if (vehicle) then setElementData(vehicle, "dataType", dataType) setElementData(vehicle, "allowedTo", allowedTo) if (color and color ~= nil) then setVehicleColor(vehicle, unpack(fromJSON(color))) end if (upgrades and upgrades ~= nil) then for index, upgrade in ipairs(fromJSON(upgrades)) do addVehicleUpgrade(vehicle, upgrade) end end table.insert(vehicles, vehicle) addEventHandler("onVehicleExplode",vehicle, function () setTimer ( function ( vehicleID, vehicle ) if ( vehicleID and type ( vehicleID ) == "number" ) then table.remove(vehicles, vehicleID) if isElement( vehicle ) then destroyElement ( vehicle ) end local veh = executeSQLQuery("SELECT * FROM private_vehicles WHERE vehicleID = '".. tonumber(vehicleID) .."'")[1] local x,y,z = getElementPosition(veh) local c1,c2,c3,c4 = getVehicleColor(veh) local upgrades = getVehicleUpgrades(veh) local mode = getElementModel(veh) createPrivateVehicle(model, x, y, z, rot, color, upgrades, dataType, allowedTo) end end ,10000, 1, #vehicles, source ) end ) return vehicle end end Link to comment
Mizudori Posted January 2, 2015 Share Posted January 2, 2015 Oh so you are using SQLQuery to get info about vehicle.. so this won't work local x,y,z = getElementPosition(veh) local c1,c2,c3,c4 = getVehicleColor(veh) local upgrades = getVehicleUpgrades(veh) local mode = getElementModel(veh) Sorry I am using mysql most of the time so don't know SQL function here. If this is the same as mysql just try this local veh = executeSQLQuery("SELECT * FROM private_vehicles WHERE vehicleID = ?",tonumber(vehicleID)) local model = veh["getvehicleModel"] Link to comment
ramzi Posted January 3, 2015 Author Share Posted January 3, 2015 didnt work,anyway thnx so much for ur help! 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