kewizzle Posted March 19, 2017 Share Posted March 19, 2017 i would like to know how to do this so i can choose to pickup a weapon so it wont replace current slot, or maybe use all weapons at same time without replacing weapon thats already in the slot. Link to comment
NeXuS™ Posted March 19, 2017 Share Posted March 19, 2017 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. Link to comment
kewizzle Posted March 19, 2017 Author Share Posted March 19, 2017 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
NeXuS™ Posted March 19, 2017 Share Posted March 19, 2017 Is it okay if I give you just a little overview of functions you'll need to do this script? Link to comment
kewizzle Posted March 19, 2017 Author Share Posted March 19, 2017 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
NeXuS™ Posted March 19, 2017 Share Posted March 19, 2017 getSlotFromWeaponcancelEventbindKeygiveWeapon I think it can be written with these 4 functions. Link to comment
kewizzle Posted March 19, 2017 Author Share Posted March 19, 2017 event possibly would be onPickupHit? Link to comment
NeXuS™ Posted March 19, 2017 Share Posted March 19, 2017 Yeah, you are right. It would be that one. Link to comment
kewizzle Posted March 19, 2017 Author Share Posted March 19, 2017 1 hour ago, NeXuS™ said: Yeah, you are right. It would be that one. ill code it and post it here when i finish if it doesnt work and maybe we can see what is incorrect if it doesnt. Link to comment
NeXuS™ Posted March 19, 2017 Share Posted March 19, 2017 Good luck with it, I'll be here to help ya. Link to comment
kewizzle Posted March 19, 2017 Author Share Posted March 19, 2017 2 hours ago, NeXuS™ said: Good luck with it, I'll be here to help ya. i went to ihop lol so ima get started now Link to comment
kewizzle Posted March 19, 2017 Author Share Posted March 19, 2017 (edited) 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 March 19, 2017 by kewizzle Link to comment
NeXuS™ Posted March 19, 2017 Share Posted March 19, 2017 Where is your onPickupUse variable registered? @kewizzle Link to comment
Gordon_G Posted March 19, 2017 Share Posted March 19, 2017 (edited) The cancelEvent() function does not requiere arguments, excepted : [ bool cancel = true, string reason = "" ] and, to be honest, I've never used them Edited March 19, 2017 by Gordon_G Link to comment
NeXuS™ Posted March 19, 2017 Share Posted March 19, 2017 They are useful @Gordon_G. For example, this script. It blocks the player from picking up a pickup, just with one line. Link to comment
kewizzle Posted March 19, 2017 Author Share Posted March 19, 2017 4 hours ago, NeXuS™ said: Where is your onPickupUse variable registered? @kewizzle onPickupUse is a built in function so I thought it would work. Idk how I would define it. Link to comment
NeXuS™ Posted March 19, 2017 Share Posted March 19, 2017 Replace function checkPickup() if getKeyState( "l" ) == false then cancelEvent( onPickupUse ) else end end with function checkPickup() if getKeyState("l") == false then cancelEvent() end end Link to comment
Gordon_G Posted March 19, 2017 Share Posted March 19, 2017 12 minutes ago, NeXuS™ said: They are useful @Gordon_G. For example, this script. It blocks the player from picking up a pickup, just with one line. You didn't understand me, I was saying that for the optional arguments inside the cancelEvent() function Link to comment
kewizzle Posted March 19, 2017 Author Share Posted March 19, 2017 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
Gordon_G Posted March 19, 2017 Share Posted March 19, 2017 If you want to use the getKeyState() function, you'll have to put it client side Link to comment
kewizzle Posted March 19, 2017 Author Share Posted March 19, 2017 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
kewizzle Posted March 19, 2017 Author Share Posted March 19, 2017 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
undefined Posted March 20, 2017 Share Posted March 20, 2017 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) 1 Link to comment
kewizzle Posted March 20, 2017 Author Share Posted March 20, 2017 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
undefined Posted March 20, 2017 Share Posted March 20, 2017 (edited) As I understood; you want to pick up weapon while pressing L. local function bindState(player) state[player] = true bindKey(player, "l", "both", function(player) state[player] = not state[player] end) end Use it. Edited March 20, 2017 by ZoRRoM 1 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