roddydennvor Posted March 17, 2015 Share Posted March 17, 2015 I just edit this script from command to event handler , But how to add this to item system , so when i use helmet (item id 90) then this event running ... Thx B4 addEvent( "helmet", true ) local cases = {} for i,v in ipairs(getElementsByType("player"))do setElementData(v, "helmet", 0) end function helmet(player) if (getResourceState(getResourceFromName("bone_attach")) == "running") then if (getElementData(source, "helmet") ~=1) then setElementData(source, "helmet", 1) case = createObject(2054,0,0,0) exports.bone_attach:attachElementToBone(case,source,1,0,0.04,0.06,0,0,180) cases[source] = case outputChatBox("Helmet:- True.", source, 0, 255, 0) else setElementData(source, "helmet", 0) exports.bone_attach:detachElementFromBone(cases[source]) destroyElement(cases[source]) outputChatBox("Helmet:- False.", source, 255, 50, 0) end else outputChatBox("ERROR #2 Resource not found.", source, 255, 50, 0) end end addEventHandler( "helmet", player, helmet ) Link to comment
JR10 Posted March 18, 2015 Share Posted March 18, 2015 You need to use triggerEvent wherever the code for "using helmet" lies. Also change player to root in addEventHandler, player is not defined. Link to comment
roddydennvor Posted March 19, 2015 Author Share Posted March 19, 2015 I just add this event as server side, but when i try this , i got error like this : ERROR: Client (Arthur_Alvaro) triggered serverside event helmet, but event is not added serverside Link to comment
roddydennvor Posted March 19, 2015 Author Share Posted March 19, 2015 I just edit this script Server.lua addEvent( "helmet", true ) local cases = {} for i,v in ipairs(getElementsByType("player"))do setElementData(v, "helmet", 0) end function helmet(player) if (getResourceState(getResourceFromName("bone_attach")) == "running") then if (getElementData(source, "helmet") ~=1) then setElementData(source, "helmet", 1) case = createObject(1210,0,0,0) exports.bone_attach:attachElementToBone(case,player,12,0,0.05,0.27,0,180,0) cases[source] = case outputChatBox("Helmet:- True.", source, 0, 255, 0) else setElementData(source, "helmet", 0) exports.bone_attach:detachElementFromBone(cases[source]) destroyElement(cases[source]) outputChatBox("Helmet:- False.", source, 255, 50, 0) end else outputChatBox("ERROR #2 Resource not found.", source, 255, 50, 0) end end addEventHandler( "helmet", root, helmet ) Item server elseif (itemID==90) then --Helmet triggerServerEvent("helmet", source) takeItemFromSlot(source, itemSlot) I just try this, but i just get an output like this: Helmet:- True. why only outputs are working, why the helmet does not appear... I just change object to 1210, it's original files, 1210 is case, but it does not appear too Your help is greatly appreciated Link to comment
Dimmitry007 Posted March 19, 2015 Share Posted March 19, 2015 you're using player instead of source addEvent( "helmet", true ) local cases = {} for i,v in ipairs(getElementsByType("player"))do setElementData(v, "helmet", 0) end function helmet( source ) if (getResourceState(getResourceFromName("bone_attach")) == "running") then if (getElementData(source, "helmet") ~=1) then setElementData(source, "helmet", 1) case = createObject(1210,0,0,0) exports.bone_attach:attachElementToBone(case,player,12,0,0.05,0.27,0,180,0) cases[source] = case outputChatBox("Helmet:- True.", source, 0, 255, 0) else setElementData(source, "helmet", 0) exports.bone_attach:detachElementFromBone(cases[source]) destroyElement(cases[source]) outputChatBox("Helmet:- False.", source, 255, 50, 0) end else outputChatBox("ERROR #2 Resource not found.", source, 255, 50, 0) end end addEventHandler( "helmet", root, helmet ) Link to comment
Tomas Posted March 20, 2015 Share Posted March 20, 2015 addEvent( "helmet", true ) local cases = {} for i,v in ipairs(getElementsByType("player"))do setElementData(v, "helmet", 0) end function helmet(player) if (getResourceState(getResourceFromName("bone_attach")) == "running") then if (getElementData(player, "helmet") ~=1) then setElementData(player, "helmet", 1) case = createObject(1210,0,0,0) exports.bone_attach:attachElementToBone(case,player,12,0,0.05,0.27,0,180,0) cases[player] = case outputChatBox("Helmet:- True.", player, 0, 255, 0) else setElementData(player, "helmet", 0) exports.bone_attach:detachElementFromBone(cases[player]) destroyElement(cases[player]) outputChatBox("Helmet:- False.", player, 255, 50, 0) end else outputChatBox("ERROR #2 Resource not found.", player, 255, 50, 0) end end addEventHandler( "helmet", root, helmet ) elseif (itemID==90) then --Helmet triggerServerEvent("helmet", root, source) takeItemFromSlot(source, itemSlot) Link to comment
Dimmitry007 Posted March 20, 2015 Share Posted March 20, 2015 any errors in /debugscript 3? Link to comment
Dimmitry007 Posted March 20, 2015 Share Posted March 20, 2015 addEvent( "helmet", true ) local cases = {} for i,v in ipairs(getElementsByType("player"))do setElementData(v, "helmet", 0) end function helmet( source ) if (getResourceState(getResourceFromName("bone_attach")) == "running") then if (getElementData(source, "helmet") ~=1) then setElementData(source, "helmet", 1) case = createObject(1210,0,0,0) exports.bone_attach:attachElementToBone(case,source,12,0,0.05,0.27,0,180,0) cases[source] = case outputChatBox("Helmet:- True.", source, 0, 255, 0) else setElementData(source, "helmet", 0) exports.bone_attach:detachElementFromBone(cases[source]) destroyElement(cases[source]) outputChatBox("Helmet:- False.", source, 255, 50, 0) end else outputChatBox("ERROR #2 Resource not found.", source, 255, 50, 0) end end addEventHandler( "helmet", root, helmet ) elseif (itemID==90) then triggerServerEvent("helmet", root, source) takeItemFromSlot(source, itemSlot) Link to comment
roddydennvor Posted March 20, 2015 Author Share Posted March 20, 2015 Not working to.. Here is debugscript code [2015-03-20 09:48:52] WARNING: toys/toys.lua:20: Bad argument @ 'destroyElement' [Expected element at argument 1, got nil] Link to comment
Ryancit2 Posted March 20, 2015 Share Posted March 20, 2015 Probably because the table 'cases' doesn't have 'source' as one of its indexes. 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