Forum

> > CS2D > Scripts > how to change dropped weapon's ammo?
Forums overviewCS2D overview Scripts overviewLog in to reply

English how to change dropped weapon's ammo?

6 replies
To the start Previous 1 Next To the start

old Re: how to change dropped weapon's ammo?

useigor
User Off Offline

Quote
1
2
3
4
5
6
addhook("drop","bros")
function bros(id,iid,type)
	if type == 10 then
		timer(1,"parse","setammo "..iid.." 0 1000 0")
	end
end

iid is id of dropped item (on the map).
I used timer because condition is called before player drop item.

old Re: how to change dropped weapon's ammo?

useigor
User Off Offline

Quote
This code changes ammo of every M3 on the floor.
1
2
3
4
5
for _,iid in pairs(item(0,"table")) do
	if item(iid,"type") == 10 then
		parse("setammo "..iid.." 0 1000 0")
	end
end

old Re: how to change dropped weapon's ammo?

Avo
User Off Offline

Quote
I think that I can post my problem here, because it's related to this topic, I think. (too lazy to create another thread for this, though)

How can I get amount of ammo in weapon carried by a player? I couldn't manage to solve it by myself. I want to increase ammo in certain weapon, but change depends on the actual ammo count.

For example, I need to know ammo count in Deagle, which is carried by a player. As you know,
item(0, "table")

contains only IDs of all dropped weapons.

What about not-dropped weapons (owned by players)? Thank you in advance for your replies.

old Re: how to change dropped weapon's ammo?

DC
Admin Off Offline

Quote
This is not possible (it already has been discussed several times). The reason for this is that the ammo amount for the client may differ from the ammo amount of the server as client shots may not arrive due to bad network conditions. The following condition is always true though: client ammo <= server ammo (so ammo hacks can be detected by the server anyway).

I will probably add commands to get these values anyway but people have to be aware of the possible difference. It CAN lead to problems and unwanted effects.

Example:
• Client has 30 ammo and shoots 5 times
• Only 4 shots arrive at the server because a message got lost in the network
• Server uses a Lua script to give the player 5 additional shots by using the own ammo value (which is 30-4=26, the server is NOT aware of the actual client value which is 30-5=25)
• The client will now have 31 ammo, even though he was supposed to get just 5 additional shots.
• From the view of the client it looks like it got 6 additional ammo and not just 5.

You may think this is kinda fair because the one shot never arrived at the server and therefore didn't do any damage and was wasted - and you are actually right but it is quite confusing if you don't know the backgrounds of all this.

(btw: I'm not sending shots in a reliable way because this would do more damage than it would help. They would get too delayed by that anyway and they would also delay other packets leading to even bigger lag spikes.)
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview