• Announcements

    • jhxp

      Forums are online again after a maintenance.   18/03/17

      MTA Forums maintenance is completed, although some automatic time-heavy tasks are still in process and will be finished eventually in background. Expect some features such as Forum Search to not display all results until all processes are finished. Please let us know if you spot a forum feature that worked correctly before the maintenance but does not work anymore now. Thanks. --MTA Team
Sign in to follow this  
Followers 0
kewizzle

pickup weapon when button pressed inside of marker

6 posts in this topic

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 by kewizzle

Share this post


Link to post
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)

:)

 

Share this post


Link to post
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 '='

Share this post


Link to post
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 :P

 

Share this post


Link to post
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 :P

 

it works but one issue,my player picks the pickup up and then if i press F it picks it up a second time.

Share this post


Link to post

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 by kewizzle

Share this post


Link to post

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.