Jump to content

bindKey to pickup weapons


kewizzle

Recommended Posts

1 hour ago, NeXuS™ said:

Giving the player a gun will always replace the gun which is on the same slot. You could do a custom weapon selection tho, using element datas for ammos, and just giving them weapons giveWeapon, and if he switches off, just take it away with takeWeapon.

well i wanna bindKey to pickup, not necessarily give a weapon. I want it to ask if you wanna replace the weapon in the slot before you pick it up. Say you have a colt45 and theres a silenced pistol and you walk over it i want it to ask before you pick it up and then press a key to pick it up.

Link to comment
1 hour ago, NeXuS™ said:

Is it okay if I give you just a little overview of functions you'll need to do this script?

sure  go for it maybe i can put it together. My zombies drop weapons at random from id 1-34 and they drop with a random ammo amount of 1-3 and when you collect a lot then youre supposed to sell it for $1 per bullet. all this works but my issue when i pickup a weapon in same slot some of them also reset the ammo count picked up.

Link to comment
function checkPickup()
if getKeyState( "l" ) == false then
			cancelEvent( onPickupUse )
			else
		end
	end
outputServerLog ( "***Drop System Loaded   ***" )
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), 0, math.random(1,3))
	addEventHandler("onPickupHit", dropped, destroyPickup) 
	setTimer(destroyElement, 15000, 1, dropped) 
	addEventHandler("onPickupHit", dropped, checkPickup)
		else
	end
end
end
addEventHandler ( "onPedWasted", getRootElement(), createDeathPickup )

i got this far but it still picks the pickup up without me pressing the key.

 

i guess im missing something?

Edited by kewizzle
Link to comment
21 minutes ago, NeXuS™ said:

Replace


function checkPickup()
	if getKeyState( "l" ) == false then
		cancelEvent( onPickupUse )
	else
	end
end

with


function checkPickup()
	if getKeyState("l") == false then
		cancelEvent()
	end
end

 

i did this but i get this

[09:19:17] ERROR: zombies\drops\server.lua:2: attempt to call global 'getKeyStat
e' (a nil value)

Link to comment

oh :~ yeah youre right one second

okay so now ive done this but player still picks the weapon up without asking first.

server

function checkPickupServer()
			triggerClientEvent ("checkPickup",source,checkPickup)
end
outputServerLog ( "***Drop System Loaded   ***" )
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), 0, math.random(1,3))
	addEventHandler("onPickupHit", dropped, destroyPickup) 
	setTimer(destroyElement, 15000, 1, dropped) 
	addEventHandler("onPickupHit", dropped, checkPickupServer)
		else
	end
end
end
addEventHandler ( "onPedWasted", getRootElement(), createDeathPickup )

client

addEvent("checkPickup",true) 
addEventHandler("checkPickup",root, 
function ()
	if getKeyState("l") == false then
		cancelEvent()
	end
end)

 

Link to comment

I did some more work and the event isnt cancelling at all. what am i doing wrong?

Server

outputServerLog ( "***Drop System Loaded   ***" )
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), 0, math.random(1,3))
	setTimer(destroyElement, 15000, 1, dropped) 
	addEventHandler("onPlayerPickupHit",getRootElement(),checkPickupServer)
		else
	end
end
end
addEventHandler ( "onPedWasted", getRootElement(), createDeathPickup )

function checkPickupServer(killer)
	if (getPickupType(dropped) == 2) then -- If it's an armour pickup
			triggerClientEvent ("checkPickup",killer,checkPickup)
	end
end

Client

addEvent("checkPickup",true) 
addEventHandler("checkPickup",root, 
function ()
	if getKeyState("l") == false then
	cancelEvent()
	else
	end
end)

 

Link to comment
local state = {}
local function bindState(player)
	bindKey(player, "l", "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)

outputServerLog ( "***Drop System Loaded   ***" )

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), 0, math.random(1,3))

	addEventHandler("onPickupHit", dropped, function(player)
		cancelEvent(state[player])
	end)

	setTimer(destroyElement, 15000, 1, dropped) 
	addEventHandler("onPickupHit", dropped, destroyPickup)
		else
	end
end
end
addEventHandler("onPedWasted", getRootElement(), createDeathPickup)

 

 

  • Like 1
Link to comment
1 hour ago, ZoRRoM said:

local state = {}
local function bindState(player)
	bindKey(player, "l", "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)

outputServerLog ( "***Drop System Loaded   ***" )

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), 0, math.random(1,3))

	addEventHandler("onPickupHit", dropped, function(player)
		cancelEvent(state[player])
	end)

	setTimer(destroyElement, 15000, 1, dropped) 
	addEventHandler("onPickupHit", dropped, destroyPickup)
		else
	end
end
end
addEventHandler("onPedWasted", getRootElement(), createDeathPickup)

 

 

it works but the pickup is destroyed still if l isnt pressed and so when it gets destroyed and i press l to pick it up it wont because its destroyed.

1 hour ago, kewizzle said:

it works but the pickup is destroyed still if l isnt pressed and so when it gets destroyed and i press l to pick it up it wont because its destroyed.

oh i see you have to hold l down so it doesnt pick it up is there a way to make it so you can hold it down to pick it up? i want it to be set to where you have to hold it to pick it up.

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...