Tycka Posted November 24, 2014 Share Posted November 24, 2014 Code: function moveRucksakOutOfInventory (itemName) local sack = getElementData ( source, "rucksak" ) if sack and sack[1] ~= 0 then local x,y,z = getElementPosition(source) local item,itemString = getItemTablePosition(itemName) local itemPickup = createItemPickup(item,x+math.random(-1.25,1.25),y+math.random(-1.25,1.25),z,itemString,sack) if elementBackpack[source] then detachElementFromBone(elementBackpack[source]) destroyElement(elementBackpack[source]) end setElementData ( source, "rucksak", { 0 } ) end end Error: attempt to index global 'elementBackpack' (a nil value) (Error line: if elementBackpack[source] then) Link to comment
Sasu Posted November 24, 2014 Share Posted November 24, 2014 Where have you defined 'source'? Link to comment
Tycka Posted November 24, 2014 Author Share Posted November 24, 2014 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) -- Here with backpack 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 ) Link to comment
Sasu Posted November 25, 2014 Share Posted November 25, 2014 I didn't see any errors. I think it doesn't create the table. Before the line where appears the error, put this and tell me what it says. outputChatBox(tostring(elementBackpack), source) Link to comment
Tycka Posted November 25, 2014 Author Share Posted November 25, 2014 I didn't see any errors. I think it doesn't create the table. Before the line where appears the error, put this and tell me what it says. outputChatBox(tostring(elementBackpack), source) In chat just say: nil Link to comment
Sasu Posted November 25, 2014 Share Posted November 25, 2014 So that means that the table 'elementBackpack' doesn't create. I suppose you are trying to create the table in the same script of the function, aren't you? If not, do it global. Link to comment
qaisjp Posted November 25, 2014 Share Posted November 25, 2014 We aren't your slaves. We will not fix your code if you just provide it to us. Did you do any debugging? You've just plonked some code in the middle of the forum. Read Debugging. Sasu, please don't help him. Link to comment
ViRuZGamiing Posted November 26, 2014 Share Posted November 26, 2014 Perhaps try being a bit friendlier to those who are people on the forum, @A Concerned Citizen Because I see all your replies and they all say the same, 'go to the wiki we don't help you'. If Sasu wants to help someone he can do that, that's polite. If you don't want/can't help then don't reply pls. Anyway keep on the good work Sasu, I remember you from waaaay back on the forum. Link to comment
Bonsai Posted November 26, 2014 Share Posted November 26, 2014 Well, its kinda true. Just throwing in some Code and an Error message and waiting for someone to fix that. Link to comment
Moderators IIYAMA Posted November 26, 2014 Moderators Share Posted November 26, 2014 (edited) There are too many of those stupid kids posting parts from DayZ/etc. gamemode, when they have no fu idea how to write a single line of code. It is shameful, disrespectful and against the forum rules. There are hardly any seriously posts. Edited November 26, 2014 by Guest Link to comment
ViRuZGamiing Posted November 26, 2014 Share Posted November 26, 2014 There are too many of those stupid kids posting parts from DayZ/etc. gamemode, when they have no fu idea how to write a single line of code.It is shameful, disrespectful and against the forum rules. Yes but we can just stop replying on them instead of starting to flame, etc. Link to comment
Moderators IIYAMA Posted November 26, 2014 Moderators Share Posted November 26, 2014 Citizen spoke the hard truth, sometimes that relieves. He didn't flame, just gave his opinion. The main reason why they created forums is for discussing problems. This is a problem, so we can discus it and give our opinion. It is a good thing to save Sasu from wasting time, he can play mta/(or help somebody else) instead of trying to help somebody who can't be helped. I would be glad if somebody did that for me. 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