WelCome Posted March 15, 2018 Share Posted March 15, 2018 Why this code didnt work? tablee = {} col_table = {} local function take(thePlayer) if isElementWithinColShape(thePlayer,col) then local ammo = getPickupAmmo(pickup) local bron = getPickupWeapon(pickup) giveWeapon(thePlayer,bron,ammo) outputChatBox("test") table.remove(col_table) table.remove(tablee) end end local function weapon_drop (thePlayer) local bron = getPlayerWeapon(thePlayer) local ammo = getPedTotalAmmo(thePlayer) local slot = getPedWeaponSlot(thePlayer) local x,y,z = getElementPosition(thePlayer) local pickup_bron = getPedWeapon(thePlayer) local p = getPedWeapon(thePlayer) if slot >= 0 then if ammo >= 0 then pickup = createPickup(x,y,z,2,p,0,ammo) col = createColSphere(x,y,z,1.0) table.insert(col_table,col) takeWeapon(thePlayer,p,ammo) table.insert(tablee,pickup) addEventHandler("onPickupHit",pickup,take) end end end addCommandHandler("bind_q",function(thePlayer) bindKey(thePlayer,"U","down",weapon_drop,thePlayer) bindKey(thePlayer,"I","down",take,thePlayer) end) Link to comment
Mahlukat Posted March 15, 2018 Share Posted March 15, 2018 can you try this ? table = {} local function take(thePlayer) for i,pickup in pairs(getElementsByType("pickup", resourceRoot)) do if isElementWithinColShape(thePlayer,table[pickup]) then local ammo = getPickupAmmo(pickup) local bron = getPickupWeapon(pickup) giveWeapon(thePlayer,bron,ammo, true) outputChatBox(getWeaponNameFromID(bron).. " | "..ammo, thePlayer) destroyElement(table[pickup]) destroyElement(pickup) end end end local function weapon_drop (thePlayer) local bron = getPlayerWeapon(thePlayer) local ammo = getPedTotalAmmo(thePlayer) local slot = getPedWeaponSlot(thePlayer) local x,y,z = getElementPosition(thePlayer) local pickup_bron = getPedWeapon(thePlayer) local p = getPedWeapon(thePlayer) if slot > 0 then if ammo > 0 then local pickup = createPickup(x,y,z,2,p,0,ammo) table[pickup] = createColSphere(x,y,z,1) takeWeapon(thePlayer,p,ammo) end end end addCommandHandler("bind_q",function(thePlayer) bindKey(thePlayer,"U","down",weapon_drop,thePlayer) bindKey(thePlayer,"I","down",take,thePlayer) end) Link to comment
MIKI785 Posted March 15, 2018 Share Posted March 15, 2018 31 minutes ago, Mahlukat said: can you try this ? table = {} local function take(thePlayer) ... Overwriting table like this is not a good idea, there may not be table functions in your code but there could be some in other parts of the script that is not shown here and since you are doing this as a global, it will affect other files within the resource as well. 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