local elementBackpack = {}
function backPackBack (dataName,oldValue)
if getElementType(source) == "player" and dataName =="rucksak" then
local newValue = getElementData(source,dataName)
if not #newValue or #newValue <= 0 then
setElementData ( source, "rucksak", { 0 } )
return true
end
if not oldValue or not #oldValue then
oldValue = { 0 }
end
if newValue[1] == 0 then
if elementBackpack[source] then
detachElementFromBone(elementBackpack[source])
destroyElement(elementBackpack[source])
elementBackpack[source] = false
end
elseif newValue[1] ~= oldValue[1] then
if elementBackpack[source] then
detachElementFromBone(elementBackpack[source])
destroyElement(elementBackpack[source])
elementBackpack[source] = false
end
local x,y,z = getElementPosition(source)
local rx,ry,rz = getElementRotation(source)
local model = newValue[1]
if model == 1 then
elementBackpack[source] = createObject(3026,x,y,z)
elseif model == 2 then
elementBackpack[source] = createObject(1248,x,y,z)
elseif model == 3 then
elementBackpack[source] = createObject(1575,x,y,z)
elseif model == 4 then
elementBackpack[source] = createObject(1252,x,y,z)
elseif model == 5 then
elementBackpack[source] = createObject(2405,x,y,z)
else
return false
end
if model == 3 then
attachElementToBone(elementBackpack[source],source,3,0,-0.16,0.05,270,0,180)
else
attachElementToBone(elementBackpack[source],source,3,0,-0.225,0.05,90,0,0)
end
end
end
if getElementType(source) == "player" and dataName == "helmetOn" then
if getElementData ( source, dataName ) then
local x, y, z = getElementPosition(source)
local helmet = createObject(2052, x, y, z)
setElementData ( source, "helmetObject", helmet )
local skin = getElementModel ( source )
if skin == 73 then
attachElementToBone(helmet, source, 1, 0, 0.02, -0.53, 0, 0, 90)
elseif skin == 287 then
attachElementToBone(helmet, source, 1, 0, 0.01, -0.56, 0, 0, 90)
elseif skin == 18 then
attachElementToBone(helmet, source, 1, 0.015, 0.025, -0.54, 0, 0, 90)
elseif skin == 23 then
attachElementToBone(helmet, source, 1, 0, 0.015, -0.574, 0, 0, 90)
elseif skin == 24 then
attachElementToBone(helmet, source, 1, 0, 0.015, -0.575, 0, 0, 90)
elseif skin == 1 then
attachElementToBone(helmet, source, 1, 0, 0.015, -0.545, 0, 0, 90)
elseif skin == 2 then
attachElementToBone(helmet, source, 1, 0.015, 0.025, -0.59, 0, 0, 90)
else
attachElementToBone(helmet, source, 1, 0, 0.015, -115, 0, 0, 90)
end
else
if isElement ( getElementData ( source, "helmetObject" ) ) then
detachElementFromBone( getElementData ( source, "helmetObject" ) )
destroyElement ( getElementData ( source, "helmetObject" ) )
setElementData ( source, "helmetObject", false )
end
end
end
end
addEventHandler ( "onElementDataChange", getRootElement(), backPackBack )