Raised This Month: $32 Target: $400
 8% 

[L4D2] Random guns ammo 1.1 [24-Dec-2022]


Post New Thread Reply   
 
Thread Tools Display Modes
Author
Iciaria
Member
Join Date: Aug 2022
Plugin ID:
8318
Plugin Version:
1.0
Plugin Category:
Gameplay
Plugin Game:
Left 4 Dead
Plugin Dependencies:
Servers with this Plugin:
 
Plugin Description:
Randomizes weapon ammo ,and works with other plugins to completely eliminate infinite ammo/weapon.
Old 12-07-2022 , 12:58   [L4D2] Random guns ammo 1.1 [24-Dec-2022]
Reply With Quote #1

About
Something I've always wanted, for my hard realism server.

I still couldn't get "m_iExtraPrimaryAmmo" to work, weapon's backup ammo still changes when I actively drop weapon.
After rewriting the plugin several times, I gave up on using it.

So I used a separate thing to hold the backup ammo value.

Feature list
-Randomizes ammo range for weapon clips (when you first pick up a new weapon).
-Randomizes a weapon's reserve ammo amount (when you first pick up a new weapon).
-Drop a weapon with the same equip slot as the target weapon before picking up the weapon.
Prevents weapon ammo from being refreshed(When approaching the weapon_spawn).


Credits
-Psykotik (Crasher_3637)
Ammunition Variation Plugin.
Gave me the idea to write this plugin.

-Machine, dcx2, Electr0 /z, Senip, Shao, Zheldorg
L4D2] Weapon Drop Plugin.
Refer to their code to solve the unexpected "IN_USE" problem.

-NoroHime
[L4D & L4D2] Take Ammo From Previous Weapon Plugin.
Learned from his plugin how to set the reserve ammo value, although mine now uses a separate ammo count.
The most surprising thing is that I now know that the "smlib" library.

[L4D & L4D2] HUD Hiddens Plugin.
Learn how to use Forward "OnGameFrame".


ConVar
The 1.1 version of convar has changed (mainly comments), but the configuration file does not need to be replaced, if you are confused by the previous comments, maybe you can take a look at it now.
Spoiler


Changelog
Spoiler



Dependencies

Left 4 DHooks

Default premise of this plugin: Weapons are NOT infinite.
@Earendil [L4D1 & L4D2] Weapon Amount Modifier

If the weapons in the gun cabinet are infinite, or the shotgun is a problem, try my version.
Make sure "l4d_weapon_amount_modifier.cfg" is configured to only allow a single weapon to spawn.

Here is my configuration:
Spoiler

Recommended Plugins
[L4D2] Weapon Drop
I haven't tested too much, recommend @Zheldorg's version,no problems so far.

[L4D/L4D2] Reserve (Ammo) Control
No problems.

[L4D & L4D2] Percentage Limited Ammo Pile
No problems.

Install

Don't click "Get Plugin", this plugin requires left4dhooks.

1.Download "l4d2_RandomAmmo.smx" and put it in "../addons/sourcemod/plugins/".
2.Download "l4d2_RandomAmmo.cfg" and put it in "../left4dead2/cfg/sourcemod/".

You need to modify the configuration file of the plugin (l4d2_RandomAmmo.cfg),Because the plugin is disabled by default.
Attached Files
File Type: sp Get Plugin or Get Source (l4d2_RandomAmmo.sp - 274 views - 31.6 KB)
File Type: smx l4d2_RandomAmmo.smx (16.0 KB, 231 views)
File Type: cfg l4d2_RandomAmmo.cfg (4.0 KB, 306 views)
__________________
Sorry,my english not good

Last edited by Iciaria; 12-23-2022 at 17:02. Reason: Update
Iciaria is offline
NoroHime
Veteran Member
Join Date: Aug 2016
Location: bed
Old 12-08-2022 , 09:26   Re: [L4D2] Random guns ammo 1.0 [07-Dec-2022]
Reply With Quote #2

excellent idea, looks you some confuses about set ammo.
m_iExtraPrimaryAmmo just available when weapon didnt carry by player yet, otherwise get m_iAmmo with ammotype offset. if dont known the weapon doesnt carrying or not, check the m_iState
seems we cant access m_iExtraPrimaryAmmo when weapon doesnt initialize the reserved ammo by survivor picking, if reserved ammo not initialize yet, we still can set m_iClip1, but when finnally initialized, the total ammo still correct .
these is all my knew by recent scripting about weapon(excluded m_nUpgradedPrimaryAmmoLoaded that little complex)
__________________
NoroHime is offline
Iciaria
Member
Join Date: Aug 2022
Old 12-23-2022 , 16:42   Re: [L4D2] Random guns ammo 1.0 [07-Dec-2022]
Reply With Quote #3

Quote:
Originally Posted by NoroHime View Post
excellent idea, looks you some confuses about set ammo.
m_iExtraPrimaryAmmo just available when weapon didnt carry by player yet, otherwise get m_iAmmo with ammotype offset. if dont known the weapon doesnt carrying or not, check the m_iState
seems we cant access m_iExtraPrimaryAmmo when weapon doesnt initialize the reserved ammo by survivor picking, if reserved ammo not initialize yet, we still can set m_iClip1, but when finnally initialized, the total ammo still correct .
these is all my knew by recent scripting about weapon(excluded m_nUpgradedPrimaryAmmoLoaded that little complex)

Thanks, I did some checking and the problem seems to be in the "DropWeapon" function, if I don't drop the weapon before picking it up, the ammo value seems to be correct, but doing so, the player can utilize the "weapon_spawn" to refresh the ammo, I may rewrite the plugin at some point in the future, but for now the plugin works fine.

Anyway, thanks for the tip
__________________
Sorry,my english not good
Iciaria is offline
sonic155
Senior Member
Join Date: Mar 2019
Old 01-22-2023 , 06:32   Re: [L4D2] Random guns ammo 1.1 [24-Dec-2022]
Reply With Quote #4

L 01/22/2023 - 04:299: [SM] [1] Line 665, l4d2_RandomAmmo.sp::SetWeaponAmmo
L 01/22/2023 - 04:299: [SM] [2] Line 544, l4d2_RandomAmmo.sp::eWeaponCanUse
L 01/22/2023 - 04:299: [SM] Exception reported: Entity 283 (283) is invalid
L 01/22/2023 - 04:299: [SM] Blaming: l4d2_RandomAmmo.smx
L 01/22/2023 - 04:299: [SM] Call stack trace:
L 01/22/2023 - 04:299: [SM] [0] SetEntProp
L 01/22/2023 - 04:299: [SM] [1] Line 665, l4d2_RandomAmmo.sp::SetWeaponAmmo
L 01/22/2023 - 04:299: [SM] [2] Line 544, l4d2_RandomAmmo.sp::eWeaponCanUse
L 01/22/2023 - 04:299: [SM] Exception reported: Entity 283 (283) is invalid
L 01/22/2023 - 04:299: [SM] Blaming: l4d2_RandomAmmo.smx
L 01/22/2023 - 04:299: [SM] Call stack trace:
L 01/22/2023 - 04:299: [SM] [0] SetEntProp
L 01/22/2023 - 04:299: [SM] [1] Line 665, l4d2_RandomAmmo.sp::SetWeaponAmmo
L 01/22/2023 - 04:299: [SM] [2] Line 544, l4d2_RandomAmmo.sp::eWeaponCanUse
L 01/22/2023 - 04:29:40: [SM] Exception reported: Entity 283 (283) is invalid
L 01/22/2023 - 04:29:40: [SM] Blaming: l4d2_RandomAmmo.smx
L 01/22/2023 - 04:29:40: [SM] Call stack trace:
L 01/22/2023 - 04:29:40: [SM] [0] SetEntProp
L 01/22/2023 - 04:29:40: [SM] [1] Line 665, l4d2_RandomAmmo.sp::SetWeaponAmmo
L 01/22/2023 - 04:29:40: [SM] [2] Line 544, l4d2_RandomAmmo.sp::eWeaponCanUse
L 01/22/2023 - 04:29:40: [SM] Exception reported: Entity 283 (283) is invalid
L 01/22/2023 - 04:29:40: [SM] Blaming: l4d2_RandomAmmo.smx
L 01/22/2023 - 04:29:40: [SM] Call stack trace:
L 01/22/2023 - 04:29:40: [SM] [0] SetEntProp
L 01/22/2023 - 04:29:40: [SM] [1] Line 665, l4d2_RandomAmmo.sp::SetWeaponAmmo
L 01/22/2023 - 04:29:40: [SM] [2] Line 544, l4d2_RandomAmmo.sp::eWeaponCanUse

unable to drop m60 once i pick it up each time i try this happens and it auto grabs the m60 over and over and over again

~~~~~~~~~~~~~~~~

i put debug mode on and got this

OnEntityCreated| =========================weapon_rifle_m60---274
---------------Set2 None Set Flag::15, Hand:0, Index:274, Type, R_Ammo: 0
========eWeaponCanUse======
eWeaponCanUse| Start=m_iExtraPrimaryAmmo========Data00,Sen d00 =========!
eWeaponCanUse| After=m_iExtraPrimaryAmmo=======Send:0,Send:0 =========!
===========Item_Pickup| :g_bAllowSetAmmo:1 - g_bRound: 0===========
===========Item_Pickup| New Weapon: 274 g_bAllowSetAmmo:0===========
===========Event_Player_Use| index: 792===========
---------Set2 None Set Flag:15, Hand:0, Index:274, Type, R_Ammo: 0
eWeaponCanUse| Handle Weapon:623, g_bAllowSetAmmo:1
DropWeapon| client:1, weapon:623 target: 274, buffer_target: weapon_rifle_m60
DropWeapon| Allow Target Weapon Type
DropWeapon| Allow Drop Weapn Type! client:1, weapon:623*, Type
eWeaponCanUse| -------------Index:274,Type
SetAmmo: Count:15, R_random: 0, random: 114
Item_Pickup| Start---------300---------
Item_Pickup| End---------0---------
===========Event_Player_Use| index: 623===========
---------------Set1 Find Flag::14, Hand:1, Index:623, Type:10, R_Ammo: 211
eWeaponCanUse| Handle Weapon:274, g_bAllowSetAmmo:0
DropWeapon| client:1, weapon:274 target: 623, buffer_target: weapon_rifle
DropWeapon| Allow Target Weapon Type
DropWeapon| Allow Drop Weapn Type! client:1, weapon:274*, Type:10
---------------Set1 Find Flag::14, Hand:1, Index:623, Type:10, R_Ammo: 211
===========Event_Player_Use| Old Weapon - Count: 14 R_Ammo: 10===========

Last edited by sonic155; 01-23-2023 at 02:42. Reason: adding more data
sonic155 is offline
sonic155
Senior Member
Join Date: Mar 2019
Old 01-27-2023 , 08:05   Re: [L4D2] Random guns ammo 1.1 [24-Dec-2022]
Reply With Quote #5

L 01/27/2023 - 053:04: [SM] Exception reported: Property "m_iPrimaryAmmoType" not found (entity 396/weapon_shotgun_chrome_spawn)
L 01/27/2023 - 053:04: [SM] Blaming: l4d2_RandomAmmo.smx
L 01/27/2023 - 053:04: [SM] Call stack trace:
L 01/27/2023 - 053:04: [SM] [0] GetEntProp
L 01/27/2023 - 053:04: [SM] [1] Line 872, l4d2_RandomAmmo.sp::Weapon_GetPrimaryAmmoType
L 01/27/2023 - 053:04: [SM] [2] Line 860, l4d2_RandomAmmo.sp::SetClientReservedAmmo
L 01/27/2023 - 053:04: [SM] [3] Line 697, l4d2_RandomAmmo.sp::Event_Player_Use
L 01/27/2023 - 056:15: Error log file session closed.
sonic155 is offline
z282846139
Member
Join Date: Aug 2018
Old 02-03-2023 , 04:58   Re: [L4D2] Random guns ammo 1.1 [24-Dec-2022]
Reply With Quote #6

Quote:
Originally Posted by sonic155 View Post
L 01/22/2023 - 04:299: [SM] [1] Line 665, l4d2_RandomAmmo.sp::SetWeaponAmmo
L 01/22/2023 - 04:299: [SM] [2] Line 544, l4d2_RandomAmmo.sp::eWeaponCanUse
L 01/22/2023 - 04:299: [SM] Exception reported: Entity 283 (283) is invalid
L 01/22/2023 - 04:299: [SM] Blaming: l4d2_RandomAmmo.smx
L 01/22/2023 - 04:299: [SM] Call stack trace:
L 01/22/2023 - 04:299: [SM] [0] SetEntProp
L 01/22/2023 - 04:299: [SM] [1] Line 665, l4d2_RandomAmmo.sp::SetWeaponAmmo
L 01/22/2023 - 04:299: [SM] [2] Line 544, l4d2_RandomAmmo.sp::eWeaponCanUse
L 01/22/2023 - 04:299: [SM] Exception reported: Entity 283 (283) is invalid
L 01/22/2023 - 04:299: [SM] Blaming: l4d2_RandomAmmo.smx
L 01/22/2023 - 04:299: [SM] Call stack trace:
L 01/22/2023 - 04:299: [SM] [0] SetEntProp
L 01/22/2023 - 04:299: [SM] [1] Line 665, l4d2_RandomAmmo.sp::SetWeaponAmmo
L 01/22/2023 - 04:299: [SM] [2] Line 544, l4d2_RandomAmmo.sp::eWeaponCanUse
L 01/22/2023 - 04:29:40: [SM] Exception reported: Entity 283 (283) is invalid
L 01/22/2023 - 04:29:40: [SM] Blaming: l4d2_RandomAmmo.smx
L 01/22/2023 - 04:29:40: [SM] Call stack trace:
L 01/22/2023 - 04:29:40: [SM] [0] SetEntProp
L 01/22/2023 - 04:29:40: [SM] [1] Line 665, l4d2_RandomAmmo.sp::SetWeaponAmmo
L 01/22/2023 - 04:29:40: [SM] [2] Line 544, l4d2_RandomAmmo.sp::eWeaponCanUse
L 01/22/2023 - 04:29:40: [SM] Exception reported: Entity 283 (283) is invalid
L 01/22/2023 - 04:29:40: [SM] Blaming: l4d2_RandomAmmo.smx
L 01/22/2023 - 04:29:40: [SM] Call stack trace:
L 01/22/2023 - 04:29:40: [SM] [0] SetEntProp
L 01/22/2023 - 04:29:40: [SM] [1] Line 665, l4d2_RandomAmmo.sp::SetWeaponAmmo
L 01/22/2023 - 04:29:40: [SM] [2] Line 544, l4d2_RandomAmmo.sp::eWeaponCanUse

unable to drop m60 once i pick it up each time i try this happens and it auto grabs the m60 over and over and over again

~~~~~~~~~~~~~~~~

i put debug mode on and got this

OnEntityCreated| =========================weapon_rifle_m60---274
---------------Set2 None Set Flag::15, Hand:0, Index:274, Type, R_Ammo: 0
========eWeaponCanUse======
eWeaponCanUse| Start=m_iExtraPrimaryAmmo========Data00,Sen d00 =========!
eWeaponCanUse| After=m_iExtraPrimaryAmmo=======Send:0,Send:0 =========!
===========Item_Pickup| :g_bAllowSetAmmo:1 - g_bRound: 0===========
===========Item_Pickup| New Weapon: 274 g_bAllowSetAmmo:0===========
===========Event_Player_Use| index: 792===========
---------Set2 None Set Flag:15, Hand:0, Index:274, Type, R_Ammo: 0
eWeaponCanUse| Handle Weapon:623, g_bAllowSetAmmo:1
DropWeapon| client:1, weapon:623 target: 274, buffer_target: weapon_rifle_m60
DropWeapon| Allow Target Weapon Type
DropWeapon| Allow Drop Weapn Type! client:1, weapon:623*, Type
eWeaponCanUse| -------------Index:274,Type
SetAmmo: Count:15, R_random: 0, random: 114
Item_Pickup| Start---------300---------
Item_Pickup| End---------0---------
===========Event_Player_Use| index: 623===========
---------------Set1 Find Flag::14, Hand:1, Index:623, Type:10, R_Ammo: 211
eWeaponCanUse| Handle Weapon:274, g_bAllowSetAmmo:0
DropWeapon| client:1, weapon:274 target: 623, buffer_target: weapon_rifle
DropWeapon| Allow Target Weapon Type
DropWeapon| Allow Drop Weapn Type! client:1, weapon:274*, Type:10
---------------Set1 Find Flag::14, Hand:1, Index:623, Type:10, R_Ammo: 211
===========Event_Player_Use| Old Weapon - Count: 14 R_Ammo: 10===========
The same thing happends in my server.
At the beginning bot will pick up shotgun and then drop it, after 5 seconds, there are 10+ shotgun
z282846139 is offline
Iciaria
Member
Join Date: Aug 2022
Old 02-04-2023 , 06:42   Re: [L4D2] Random guns ammo 1.1 [24-Dec-2022]
Reply With Quote #7

Quote:
Originally Posted by z282846139 View Post
The same thing happends in my server.
At the beginning bot will pick up shotgun and then drop it, after 5 seconds, there are 10+ shotgun
Multiple shotguns appearing out of thin air?
__________________
Sorry,my english not good
Iciaria is offline
z282846139
Member
Join Date: Aug 2018
Old 02-04-2023 , 09:46   Re: [L4D2] Random guns ammo 1.1 [24-Dec-2022]
Reply With Quote #8

Quote:
Originally Posted by Iciaria View Post
Multiple shotguns appearing out of thin air?
Yes, it happends when I pickup a shotgun.
When I pickup a shotgun, it drop a new one(a extra one), by the way: when there is on shotgun on the ground, I use E pickup one shotgun, an the same time, another shotgun drops from my hand. Can you image that? A shotgun comes from my hand like I create it from air.

Last edited by z282846139; 02-04-2023 at 09:47.
z282846139 is offline
z282846139
Member
Join Date: Aug 2018
Old 02-04-2023 , 09:50   Re: [L4D2] Random guns ammo 1.1 [24-Dec-2022]
Reply With Quote #9

And these are error logs:
Code:
L 02/04/2023 - 14:49:14: [SM] Blaming: l4d2_RandomAmmo.smx
L 02/04/2023 - 14:49:14: [SM] Call stack trace:
L 02/04/2023 - 14:49:14: [SM]   [0] GetEntProp
L 02/04/2023 - 14:49:14: [SM]   [1] Line 872, l4d2_RandomAmmo.sp::Weapon_GetPrimaryAmmoType
L 02/04/2023 - 14:49:14: [SM]   [2] Line 860, l4d2_RandomAmmo.sp::SetClientReservedAmmo
L 02/04/2023 - 14:49:14: [SM]   [3] Line 697, l4d2_RandomAmmo.sp::Event_Player_Use
L 02/04/2023 - 14:49:14: [SM] Exception reported: Property "m_iPrimaryAmmoType" not found (entity 642/weapon_shotgun_chrome_spawn)
L 02/04/2023 - 14:49:14: [SM] Blaming: l4d2_RandomAmmo.smx
L 02/04/2023 - 14:49:14: [SM] Call stack trace:
L 02/04/2023 - 14:49:14: [SM]   [0] GetEntProp
L 02/04/2023 - 14:49:14: [SM]   [1] Line 872, l4d2_RandomAmmo.sp::Weapon_GetPrimaryAmmoType
L 02/04/2023 - 14:49:14: [SM]   [2] Line 860, l4d2_RandomAmmo.sp::SetClientReservedAmmo
L 02/04/2023 - 14:49:14: [SM]   [3] Line 697, l4d2_RandomAmmo.sp::Event_Player_Use
L 02/04/2023 - 14:49:14: [SM] Exception reported: Property "m_iPrimaryAmmoType" not found (entity 642/weapon_shotgun_chrome_spawn)
L 02/04/2023 - 14:49:14: [SM] Blaming: l4d2_RandomAmmo.smx
L 02/04/2023 - 14:49:14: [SM] Call stack trace:
L 02/04/2023 - 14:49:14: [SM]   [0] GetEntProp
L 02/04/2023 - 14:49:14: [SM]   [1] Line 872, l4d2_RandomAmmo.sp::Weapon_GetPrimaryAmmoType
L 02/04/2023 - 14:49:14: [SM]   [2] Line 860, l4d2_RandomAmmo.sp::SetClientReservedAmmo
L 02/04/2023 - 14:49:14: [SM]   [3] Line 697, l4d2_RandomAmmo.sp::Event_Player_Use
z282846139 is offline
Iciaria
Member
Join Date: Aug 2022
Old 02-04-2023 , 09:55   Re: [L4D2] Random guns ammo 1.1 [24-Dec-2022]
Reply With Quote #10

Quote:
Originally Posted by z282846139 View Post
Yes, it happends when I pickup a shotgun.
When I pickup a shotgun, it drop a new one(a extra one), by the way: when there is on shotgun on the ground, I use E pickup one shotgun, an the same time, another shotgun drops from my hand. Can you image that? A shotgun comes from my hand like I create it from air.
Can you provide the *cfg file of the plugin?
__________________
Sorry,my english not good
Iciaria is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:27.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode