One way to prevent the lag caused by spamming the drop button is to limit the number of images that are generated. You can do this by adding a counter variable that keeps track of the number of images currently in use, and only allowing the drop function to execute if the counter is below a certain threshold. Additionally, you can also add a delay between each drop, so the player can't spam the button too quickly.
Here's an example of how you could implement this in your code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
local image_counter = 0
local max_images = 20
local drop_delay = 0.5
addhook("drop", "_drop")
function _drop(id, iid, type, ammoin, ammo, mode, xpos, ypos)
if os.clock() - Player[id].last_drop > drop_delay and image_counter < max_images then
local z = math.random(0, 359)
if type == 1 then
Player[id].image = image('gfx/cs2dbr/skinsystem/usp/drop/'..usp[id]..'.png', 0, 0, 0)
imagepos(Player[id].image, xpos*32+16, ypos*32+16, z)
weapon_i[iid] = Player[id].image
image_counter = image_counter + 1
Player[id].last_drop = os.clock()
end
end
end
addhook("collect", "_collect")
function _collect(id, iid, type, ain, a, mode)
if type == 1 then
freeimage(weapon_i[iid])
weapon_i[iid] = nil
image_counter = image_counter - 1
end
end
This code limits the number of images that can be created, and also adds a delay between each drop, so that the player can't spam the button too quickly.