ikzelf Posted May 4, 2012 Share Posted May 4, 2012 hi, i got a weird bug it doesnt set the right vehiclecolor code. i can't find the problem, anyone got a solution? the Code: function spawnVehs() for i, v in ipairs (getElementsByType("veh")) do local model = getElementData(v,"model") local ID = getElementData(v,"ID") local x = getElementData(v,"posX") local y = getElementData(v,"posY") local z = getElementData(v,"posZ") local rotZ = tonumber(getElementData(v,"rotation")) local color1 = getElementData(v,"color1") local color2 = getElementData(v,"color2") cars[i] = createVehicle(model,x,y,z,0,0,rotZ) setElementData (cars[i],"vehID",ID) setElementData (cars[i],"posX",x) setElementData (cars[i],"posY",y) setElementData (cars[i],"posZ",z) setElementData (cars[i],"rotation", rotZ) setElementData (cars[i], "color1", color1) setElementData (cars[i], "color2", color2) setVehicleColor(cars[i], tonumber(color1), tonumber(color2), 0, 0 ) local owner = getElementData(v,"owner") local team = getElementData(v,"team") local locked = getElementData(v,"Locked") if owner then setElementData(cars[i], "owner", owner) end if team then setElementData(cars[i], "team", team) end if locked then setElementData(cars[i], "Locked", locked) end toggleVehicleRespawn(v,true) setVehicleIdleRespawnDelay(v,120000) end end addEventHandler("onResourceStart",getResourceRootElement(),spawnVehs) and this is mine .map file: "15.173828125" color1="10" rotation="315.22521972656" posX="-1282.1806640625" ID="8780786" posZ="13.82702255249" model="429" color2="10"> "19.14453125" color1="6" rotation="313.68713378906" model="438" posX="-1285.8427734375" ID="3391522" posZ="14.153354644775" color2="76"> Link to comment
Jaysds1 Posted May 4, 2012 Share Posted May 4, 2012 theCode: addEventHandler("onResourceStart",resourceRoot,function() for i, v in ipairs (getElementsByType("veh")) do local model = getElementData(v,"model") local ID = getElementData(v,"ID") local x = getElementData(v,"posX") local y = getElementData(v,"posY") local z = getElementData(v,"posZ") local rotZ = tonumber(getElementData(v,"rotation")) local color1 = getElementData(v,"color1") local color2 = getElementData(v,"color2") cars[i] = createVehicle(model,x,y,z,0,0,rotZ) setElementData (cars[i],"vehID",ID) setElementData (cars[i],"posX",x) setElementData (cars[i],"posY",y) setElementData (cars[i],"posZ",z) setElementData (cars[i],"rotation", rotZ) setElementData (cars[i], "color1", color1) setElementData (cars[i], "color2", color2) setVehicleColor(cars[i], tonumber(color1), tonumber(color2), 0, 0 ) local owner = getElementData(v,"owner") local team = getElementData(v,"team") local locked = getElementData(v,"Locked") if owner then setElementData(cars[i], "owner", owner) end if team then setElementData(cars[i], "team", team) end if locked then setElementData(cars[i], "Locked", locked) end toggleVehicleRespawn(v,true) setVehicleIdleRespawnDelay(v,120000) end end) Link to comment
ikzelf Posted May 5, 2012 Author Share Posted May 5, 2012 @jaysds1 it still doesn't work, it just put a random color code on it Link to comment
ikzelf Posted May 5, 2012 Author Share Posted May 5, 2012 i tryed this code now it works only i got one debug and dont know how to fix it cars = { } allcars = {} allcars = allcars + 1 addEventHandler("onResourceStart",resourceRoot,function() local root = xmlLoadFile ("vehicles.map") local hroot = xmlFindChild (root,"cars",0) if (hroot) then for i, v in ipairs (xmlNodeGetChildren(hroot)) do local model = xmlNodeGetAttribute(v,"model") local ID = xmlNodeGetAttribute(v,"ID") local x = xmlNodeGetAttribute(v,"posX") local y = xmlNodeGetAttribute(v,"posY") local z = xmlNodeGetAttribute(v,"posZ") local rotZ = tonumber(xmlNodeGetAttribute(v,"rotation")) local color1 = xmlNodeGetAttribute(v,"color1") local color2 = xmlNodeGetAttribute(v,"color2") cars[i] = createVehicle(model,x,y,z,0,0,rotZ) setElementData (cars[i],"vehID",ID) setElementData (cars[i],"posX",x) setElementData (cars[i],"posY",y) setElementData (cars[i],"posZ",z) setElementData (cars[i],"rotation", rotZ) setElementData (cars[i], "color1", color1) setElementData (cars[i], "color2", color2) setVehicleColor(cars[i], tonumber(color1), tonumber(color2), 0, 0 ) local owner = xmlNodeGetAttribute(v,"owner") local team = xmlNodeGetAttribute(v,"team") local locked = xmlNodeGetAttribute(v,"Locked") if owner then setElementData(cars[i], "owner", owner) end if team then setElementData(cars[i], "team", team) end if locked then setElementData(cars[i], "Locked", locked) end toggleVehicleRespawn(cars[i],true) setVehicleIdleRespawnDelay(cars[i],120000) allcars = allcars+1 end end end) debug: lua:4: attempt to perform arithmetic on global 'allcars' (a table value) Link to comment
Guest Guest4401 Posted May 5, 2012 Share Posted May 5, 2012 At line 3 you have defined allcars as an empty table, so it is a table value. And then you add 1 to it, that's why you get error @ debug. Maybe you're trying to get the count of cars. If so, then use allcars = 0 instead of allcars = {} at line 3. Alternatively, you can use #cars to get the count. Link to comment
ikzelf Posted May 5, 2012 Author Share Posted May 5, 2012 At line 3 you have defined allcars as an empty table, so it is a table value. And then you add 1 to it, that's why you get error @ debug.Maybe you're trying to get the count of cars. If so, then use allcars = 0 instead of allcars = {} at line 3. Alternatively, you can use #cars to get the count. hm, i tryed it but there are now 2 cars at the same spot spawned, one on top of the other. 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