Best-Killer Posted January 21, 2016 Share Posted January 21, 2016 (edited) i'm trying to make Inventory System i did it and work fine i have 1 problem bad usage @'addEventHandler' onClientGUIDoubleClick with this function is already handled function onClientGUIDoubleClick ( ) if ( source == GUIEditor.gridlist[1] ) then selectedItem = nil local r, c = guiGridListGetSelectedItem ( source ) if ( r ~= -1 ) then local name = tostring ( guiGridListGetItemData ( source, r, 1 ) ) local c = getElementData(localPlayer,"SAEGUser:Items")[name] guiSetText ( GUIEditor.edit[1], items[name].desc ) selectedItem = name if ( items[name].requiresInVehicle ) then guiSetText ( GUIEditor.edit[1], guiGetText ( GUIEditor.edit[1] ) .."\n\nThis requires you to be in a vehicle." ) if ( not isPedInVehicle ( localPlayer ) ) then removeEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) end end if ( isPedInVehicle ( localPlayer ) and not items [ name ].useableInVehicle ) then removeEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) elseif ( not isPedInVehicle ( localPlayer ) and not items[name].requiresInVehicle ) then addEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) end end useItem ( selectedItem ) end end Edited January 21, 2016 by Guest Link to comment
tosfera Posted January 21, 2016 Share Posted January 21, 2016 The warning only gets thrown when you're trying to add an event handler which has already been added. You can simply ignore it since there won't be any performance issues. Your compiler is just telling you that there has been another eventHandler already linked to the same function and therefore isn't doing it anymore. If you want to clean the warning/errors being dropped in your face, you can always add a simple check to see if the eventHandler has already been added. Create a new boolean variable which gets set to true at this line; addEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) and false at this one ( 2x ); removeEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) If the variable is true, don't add the handler again. Or if you really want to do it even more simple. First remove the eventHandler and then add it back again, like so; function onClientGUIDoubleClick ( ) if ( source == GUIEditor.gridlist[1] ) then selectedItem = nil local r, c = guiGridListGetSelectedItem ( source ) if ( r ~= -1 ) then local name = tostring ( guiGridListGetItemData ( source, r, 1 ) ) local c = getElementData(localPlayer,"SAEGUser:Items")[name] guiSetText ( GUIEditor.edit[1], items[name].desc ) selectedItem = name if ( items[name].requiresInVehicle ) then guiSetText ( GUIEditor.edit[1], guiGetText ( GUIEditor.edit[1] ) .."\n\nThis requires you to be in a vehicle." ) if ( not isPedInVehicle ( localPlayer ) ) then removeEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) end end if ( isPedInVehicle ( localPlayer ) and not items [ name ].useableInVehicle ) then removeEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) elseif ( not isPedInVehicle ( localPlayer ) and not items[name].requiresInVehicle ) then removeEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) addEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) end end useItem ( selectedItem ) end end Link to comment
Best-Killer Posted January 21, 2016 Author Share Posted January 21, 2016 The warning only gets thrown when you're trying to add an event handler which has already been added. You can simply ignore it since there won't be any performance issues. Your compiler is just telling you that there has been another eventHandler already linked to the same function and therefore isn't doing it anymore.If you want to clean the warning/errors being dropped in your face, you can always add a simple check to see if the eventHandler has already been added. Create a new boolean variable which gets set to true at this line; addEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) and false at this one ( 2x ); removeEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) If the variable is true, don't add the handler again. Or if you really want to do it even more simple. First remove the eventHandler and then add it back again, like so; function onClientGUIDoubleClick ( ) if ( source == GUIEditor.gridlist[1] ) then selectedItem = nil local r, c = guiGridListGetSelectedItem ( source ) if ( r ~= -1 ) then local name = tostring ( guiGridListGetItemData ( source, r, 1 ) ) local c = getElementData(localPlayer,"SAEGUser:Items")[name] guiSetText ( GUIEditor.edit[1], items[name].desc ) selectedItem = name if ( items[name].requiresInVehicle ) then guiSetText ( GUIEditor.edit[1], guiGetText ( GUIEditor.edit[1] ) .."\n\nThis requires you to be in a vehicle." ) if ( not isPedInVehicle ( localPlayer ) ) then removeEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) end end if ( isPedInVehicle ( localPlayer ) and not items [ name ].useableInVehicle ) then removeEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) elseif ( not isPedInVehicle ( localPlayer ) and not items[name].requiresInVehicle ) then removeEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) addEventHandler ( "onClientGUIDoubleClick", GUIEditor.gridlist[1], onClientGUIDoubleClick ) end end useItem ( selectedItem ) end end Thanks u other problem example i have 20 Drug Cocaine in Inventory then i click dobuleclick on item all amount of cocaine used Link to comment
tosfera Posted January 21, 2016 Share Posted January 21, 2016 I have no idea what you're doing with that, that should be something on your server's side. Link to comment
Best-Killer Posted January 21, 2016 Author Share Posted January 21, 2016 function useItem ( item ) local rv = false local d = getElementData ( localPlayer, "SAEGUser:Items" ) if not d then return false end if not d[item] then return false end local amount = d[item] if ( amount <= 0 ) then return false end if ( item == 'FuelCans' ) then local c = getPedOccupiedVehicle ( localPlayer ) if ( getVehicleController ( c ) == localPlayer ) then local f = getElementData ( c, "fuel" ) if ( f <= 90 ) then rv = true setElementData ( c, "fuel", f + 10 ) exports.SAEGMessages:sendClientMessage ( "You have used a fuel can... +10% fuel", 0, 255, 0 ) else exports.SAEGMessages:sendClientMessage ( "Your fuel must be below 90% to use this item", 255, 0, 0 ) end else exports.SAEGMessages:sendClientMessage ( "You're not the driver of this vehicle.", 255, 255, 0 ) end elseif ( item == "Drug.LSD" ) then exports.SAEGDrugs:useDrug ( "LSD", 1 ) exports.SAEGMessages:sendClientMessage ( "You have decided to use LSD. Get ready for some crazy shit", 255, 255, 0 ) rv = true elseif ( item == "Drug.Marijuana" ) then exports.SAEGDrugs:useDrug ( "Marijuana", 1 ) --exports.SAEGMessages:sendClientMessage ( "~~~~~ Stoner ~~~~~", 0, 255, 0 ) --exports.SAEGMessages:sendClientMessage ( "You smoked some that grade A shit, man!", 255, 255, 0) exports.SAEGMessages:sendClientMessage ( "You'll get 2% health every second", 255, 0, 0 ) rv = true elseif ( item == "health_packs" ) then if ( exports.saeghealthpack:useHealthPack ( ) ) then rv = true else exports.saegmessages:sendClientMessage ( "You don't need a health pack right now!", 255, 255, 0 ) end elseif ( item == "armour" ) then triggerServerEvent ("armouritem",localPlayer,item) rv = true exports.SAEGMessages:sendClientMessage ( "You have used armour,", 255, 255, 0 ) else exports.saegmessages:sendClientMessage ( "You don't need a armour right now!", 255, 255, 0 ) end triggerServerEvent ( "SAEGInventory:onClientUseItem", localPlayer, item ) if rv then d[item] = d[item] - 1 setElementData ( localPlayer, "SAEGUser:Items", d ) reloadInvenPanel ( ) end return rv end function reloadInvenPanel ( ) local d = getElementData ( localPlayer, "SAEGUser:Items" ) local c = selectedItem closeInventoryWindow ( ) createInventoryWindow ( ) for i=0, guiGridListGetRowCount ( GUIEditor.gridlist[1] ) do local d = guiGridListGetItemData ( GUIEditor.gridlist[1], i, 1 ) if ( d == c ) then guiGridListSetSelectedItem ( GUIEditor.gridlist[1], i, 1 ) triggerEvent ( "onClientGUIDoubleClick", GUIEditor.gridlist[1] ) break end end c=nil return true end bindKey ( "I", "down", function ( ) if ( inven and isElement ( GUIEditor.window[1] ) ) then closeInventoryWindow ( ) else createInventoryWindow ( ) end end ) i click on item then all amount used pls help 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