kewizzle Posted March 21, 2017 Share Posted March 21, 2017 (edited) So basically i have a drop system and well i just got it to work thanks to some people here when you hold a button and then hit a pickup it picks it up. But my issue is when you hit the pickup without holding the button then press the button to pick it up nothing will happen. So i want to make it so if the player is within the marker that the pickup is in and the button is pressed it will pick the weapon up and give it to the player. heres my current code. outputServerLog ( "***Drop System Loaded ***" ) local state = {} local function bindState(player) state[player] = true bindKey(player, "f", "both", function(player) state[player] = not state[player] end) end addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType ("player")) do bindState(player) end end) addEventHandler("onPlayerJoin", root, function() bindState(source) end) function createDeathPickup ( totalammo, killer, killerweapon, bodypart ) --when a player dies if ( killer ) then if ( getElementType ( killer ) == "player" ) then x, y, z = getElementPosition ( source ) --get the position of the person who died and define it as x, y and z dropped = createPickup ( x, y, z, 2, math.random(22, 34), 15000, math.random(1,3)) dropmarker = createMarker ( x, y, z-0.5, "cylinder", 1, math.random(1, 255), math.random(1, 255), math.random(1, 255), 255) addEventHandler("onPickupHit", dropped, function(player) cancelEvent(state[player]) end) setTimer(destroyElement, 15000, 1, dropped) setTimer(destroyElement, 15000, 1, dropmarker) end end end addEventHandler("onPedWasted", getRootElement(), createDeathPickup) Edited March 21, 2017 by kewizzle Link to comment
Ayush Rathore Posted March 21, 2017 Share Posted March 21, 2017 5 hours ago, kewizzle said: So basically i have a drop system and well i just got it to work thanks to some people here when you hold a button and then hit a pickup it picks it up. But my issue is when you hit the pickup without holding the button then press the button to pick it up nothing will happen. So i want to make it so if the player is within the marker that the pickup is in and the button is pressed it will pick the weapon up and give it to the player. heres my current code. outputServerLog ( "***Drop System Loaded ***" ) local state = {} local function bindState(player) state[player] = true bindKey(player, "f", "both", function(player) state[player] = not state[player] end) end addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType ("player")) do bindState(player) end end) addEventHandler("onPlayerJoin", root, function() bindState(source) end) function createDeathPickup ( totalammo, killer, killerweapon, bodypart ) --when a player dies if ( killer ) then if ( getElementType ( killer ) == "player" ) then x, y, z = getElementPosition ( source ) --get the position of the person who died and define it as x, y and z dropped = createPickup ( x, y, z, 2, math.random(22, 34), 15000, math.random(1,3)) dropmarker = createMarker ( x, y, z-0.5, "cylinder", 1, math.random(1, 255), math.random(1, 255), math.random(1, 255), 255) addEventHandler("onPickupHit", dropped, function(player) cancelEvent(state[player]) end) setTimer(destroyElement, 15000, 1, dropped) setTimer(destroyElement, 15000, 1, dropmarker) end end end addEventHandler("onPedWasted", getRootElement(), createDeathPickup) Try this outputServerLog ( "***Drop System Loaded ***" ) local state = {} local function bindState(player) bindKey(player, "f", "down", function(player) if isElement(getElementData(player,"pickup")) then usePickup(getElementData(player,"pickup"),player) removeElementData(player,"pickup") end end) end function getElementsWithinMarker(marker) if (not isElement(marker) or getElementType(marker) ~= "marker") then return false end local markerColShape = getElementColShape(marker) local elements = getElementsWithinColShape(markerColShape) return elements end addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType ("player")) do bindState(player) end end) addEventHandler("onPlayerJoin", root, function() bindState(source) end) function createDeathPickup ( totalammo, killer, killerweapon, bodypart ) --when a player dies if ( killer ) then if ( getElementType ( killer ) == "player" ) then x, y, z = getElementPosition ( source ) --get the position of the person who died and define it as x, y and z dropped = createPickup ( x, y, z, 2, math.random(22, 34), 15000, math.random(1,3)) dropmarker = createMarker ( x, y, z-0.5, "cylinder", 1, math.random(1, 255), math.random(1, 255), math.random(1, 255), 255) addEventHandler("onMarkerHit", dropmarker, function(player) if isElement(player) and getElementType(player) = 'player' then setElementData(player,"pickup",dropped) end end) setTimer(destroyElement, 15000, 1, dropped) setTimer(destroyElement, 15000, 1, dropmarker) end end end addEventHandler("onPedWasted", getRootElement(), createDeathPickup) Link to comment
kewizzle Posted March 21, 2017 Author Share Posted March 21, 2017 7 hours ago, Ayush Rathore said: Try this outputServerLog ( "***Drop System Loaded ***" ) local state = {} local function bindState(player) bindKey(player, "f", "down", function(player) if isElement(getElementData(player,"pickup")) then usePickup(getElementData(player,"pickup"),player) removeElementData(player,"pickup") end end) end function getElementsWithinMarker(marker) if (not isElement(marker) or getElementType(marker) ~= "marker") then return false end local markerColShape = getElementColShape(marker) local elements = getElementsWithinColShape(markerColShape) return elements end addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType ("player")) do bindState(player) end end) addEventHandler("onPlayerJoin", root, function() bindState(source) end) function createDeathPickup ( totalammo, killer, killerweapon, bodypart ) --when a player dies if ( killer ) then if ( getElementType ( killer ) == "player" ) then x, y, z = getElementPosition ( source ) --get the position of the person who died and define it as x, y and z dropped = createPickup ( x, y, z, 2, math.random(22, 34), 15000, math.random(1,3)) dropmarker = createMarker ( x, y, z-0.5, "cylinder", 1, math.random(1, 255), math.random(1, 255), math.random(1, 255), 255) addEventHandler("onMarkerHit", dropmarker, function(player) if isElement(player) and getElementType(player) = 'player' then setElementData(player,"pickup",dropped) end end) setTimer(destroyElement, 15000, 1, dropped) setTimer(destroyElement, 15000, 1, dropmarker) end end end addEventHandler("onPedWasted", getRootElement(), createDeathPickup) i got an error server.lua:39: then expected near '=' Link to comment
Ayush Rathore Posted March 21, 2017 Share Posted March 21, 2017 35 minutes ago, kewizzle said: i got an error server.lua:39: then expected near '=' outputServerLog ( "***Drop System Loaded ***" ) local state = {} local function bindState(player) bindKey(player, "f", "down", function(player) if isElement(getElementData(player,"pickup")) then usePickup(getElementData(player,"pickup"),player) removeElementData(player,"pickup") end end) end function getElementsWithinMarker(marker) if (not isElement(marker) or getElementType(marker) ~= "marker") then return false end local markerColShape = getElementColShape(marker) local elements = getElementsWithinColShape(markerColShape) return elements end addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType ("player")) do bindState(player) end end) addEventHandler("onPlayerJoin", root, function() bindState(source) end) function createDeathPickup ( totalammo, killer, killerweapon, bodypart ) --when a player dies if ( killer ) then if ( getElementType ( killer ) == "player" ) then x, y, z = getElementPosition ( source ) --get the position of the person who died and define it as x, y and z dropped = createPickup ( x, y, z, 2, math.random(22, 34), 15000, math.random(1,3)) dropmarker = createMarker ( x, y, z-0.5, "cylinder", 1, math.random(1, 255), math.random(1, 255), math.random(1, 255), 255) addEventHandler("onMarkerHit", dropmarker, function(player) if isElement(player) and getElementType(player) == 'player' then setElementData(player,"pickup",dropped) end end) setTimer(destroyElement, 15000, 1, dropped) setTimer(destroyElement, 15000, 1, dropmarker) end end end addEventHandler("onPedWasted", getRootElement(), createDeathPickup) try this my bad Link to comment
kewizzle Posted March 21, 2017 Author Share Posted March 21, 2017 2 hours ago, Ayush Rathore said: outputServerLog ( "***Drop System Loaded ***" ) local state = {} local function bindState(player) bindKey(player, "f", "down", function(player) if isElement(getElementData(player,"pickup")) then usePickup(getElementData(player,"pickup"),player) removeElementData(player,"pickup") end end) end function getElementsWithinMarker(marker) if (not isElement(marker) or getElementType(marker) ~= "marker") then return false end local markerColShape = getElementColShape(marker) local elements = getElementsWithinColShape(markerColShape) return elements end addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType ("player")) do bindState(player) end end) addEventHandler("onPlayerJoin", root, function() bindState(source) end) function createDeathPickup ( totalammo, killer, killerweapon, bodypart ) --when a player dies if ( killer ) then if ( getElementType ( killer ) == "player" ) then x, y, z = getElementPosition ( source ) --get the position of the person who died and define it as x, y and z dropped = createPickup ( x, y, z, 2, math.random(22, 34), 15000, math.random(1,3)) dropmarker = createMarker ( x, y, z-0.5, "cylinder", 1, math.random(1, 255), math.random(1, 255), math.random(1, 255), 255) addEventHandler("onMarkerHit", dropmarker, function(player) if isElement(player) and getElementType(player) == 'player' then setElementData(player,"pickup",dropped) end end) setTimer(destroyElement, 15000, 1, dropped) setTimer(destroyElement, 15000, 1, dropmarker) end end end addEventHandler("onPedWasted", getRootElement(), createDeathPickup) try this my bad it works but one issue,my player picks the pickup up and then if i press F it picks it up a second time. Link to comment
kewizzle Posted March 22, 2017 Author Share Posted March 22, 2017 (edited) okay so it almost works but when i kill more than one enemy it wont let me pick up the other pickups and it only picks up the last pickup made. outputServerLog ( "***Drop System Loaded ***" ) local state = {} local function bindState(player) bindKey(player, "f", "down", function(player) if isElement(getElementData(player,"pickup")) then usePickup(getElementData(player,"pickup"),player) removeElementData(player,"pickup") end end) end function getElementsWithinMarker(marker) if (not isElement(marker) or getElementType(marker) ~= "marker") then return false end local markerColShape = getElementColShape(marker) local elements = getElementsWithinColShape(markerColShape) return elements end addEventHandler("onResourceStart", resourceRoot, function() for _, player in pairs(getElementsByType ("player")) do bindState(player) end end) addEventHandler("onPlayerJoin", root, function() bindState(source) end) function createDeathPickup ( totalammo, killer, killerweapon, bodypart ) --when a player dies if ( killer ) then if ( getElementType ( killer ) == "player" ) then x, y, z = getElementPosition ( source ) --get the position of the person who died and define it as x, y and z dropped = createPickup ( x, y, z, 2, math.random(22, 34), 15000, math.random(1,3)) dropmarker = createMarker ( x, y, z-0.5, "cylinder", 1, math.random(1, 255), math.random(1, 255), math.random(1, 255), 255) addEventHandler("onPickupHit", dropped, HitPick) addEventHandler("onMarkerHit", dropmarker, function(player) if isElement(player) and getElementType(player) == 'player' then setElementData(player,"pickup",dropped) end end) setTimer(destroyElement, 15000, 1, dropped) setTimer(destroyElement, 15000, 1, dropmarker) end end end addEventHandler("onPedWasted", getRootElement(), createDeathPickup) function HitPick ( ) if isElement ( dropped ) then cancelEvent() end end Edited March 22, 2017 by kewizzle 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