Hello fellow buddies,
I'm currently trying to establish a script which should change the colours of vehicles which where set with the map editor.
However, whenever I want to access a vehicle by its id, it results in the following error:
[2018-08-25 18:06:39] ERROR: spawn\main.lua:2: attempt to call global 'getElementById' (a nil value)
The script:
function onSpawn()
local veh = getElementById("noobfaggio1")
setVehicleColor(veh, math.random(255), math.random(255), math.random(255))
toggleVehicleRespawn(veh, true)
setVehicleIdleRespawnDelay(veh, 300)
end
addEventHandler("onResourceStart", getRootElement(), onSpawn)
The map file:
<map edf:definitions="editor_main">
<vehicle id="noobfaggio1" sirens="false" paintjob="3" interior="0" alpha="255" model="462" plate="PDNZQ6O" dimension="0" color="42,119,161,245,245,245,0,0,0,0,0,0" posX="-1984.4004" posY="147.90039" posZ="27.4" rotX="0" rotY="0" rotZ="49.999"></vehicle>
<vehicle id="noobfaggio2" sirens="false" paintjob="3" interior="0" alpha="255" model="462" plate="PPTMYC2" dimension="0" color="42,119,161,245,245,245,0,0,0,0,0,0" posX="-1984.2002" posY="150.7998" posZ="27.4" rotX="0" rotY="0" rotZ="49.999"></vehicle>
<vehicle id="noobfaggio3" sirens="false" paintjob="3" interior="0" alpha="255" model="462" plate="N55KKY2" dimension="0" color="42,119,161,245,245,245,0,0,0,0,0,0" posX="-1984.2002" posY="153.7002" posZ="27.4" rotX="0" rotY="0" rotZ="49.999"></vehicle>
<vehicle id="noobfaggio4" sirens="false" paintjob="3" interior="0" alpha="255" model="462" plate="Y7958TZ" dimension="0" color="42,119,161,245,245,245,0,0,0,0,0,0" posX="-1984.3" posY="156.7" posZ="27.4" rotX="0" rotY="0" rotZ="49.999"></vehicle>
<vehicle id="noobfaggio5" sirens="false" paintjob="3" interior="0" alpha="255" model="462" plate="IJU827X" dimension="0" color="42,119,161,245,245,245,0,0,0,0,0,0" posX="-1984.4" posY="160" posZ="27.4" rotX="0" rotY="0" rotZ="49.999"></vehicle>
<vehicle id="noobfaggio6" sirens="false" paintjob="3" interior="0" alpha="255" model="462" plate="VFJE4AE" dimension="0" color="42,119,161,245,245,245,0,0,0,0,0,0" posX="-1984.5" posY="163.5" posZ="27.4" rotX="0" rotY="0" rotZ="49.999"></vehicle>
</map>
Little bit clueless here. Can somebody give me hand?
Thanks in advance!