Raised This Month: $ Target: $400
 0% 

[L4D] Limit ammo pile usage to 1 clip per use


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Hanzoligen
Junior Member
Join Date: Feb 2013
Old 02-20-2013 , 05:10   [L4D] Limit ammo pile usage to 1 clip per use
Reply With Quote #1

Hi coders,
I am trying to limit the ammo pile usage to 1 clip per usage but the script below always assigns the maximum of 360 ammo for rifle (for example).

PHP Code:
HookEvent("ammo_pickup"Event_AmmoPickupEventHookMode_Pre);

public 
Action:Event_AmmoPickup(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
client GetClientOfUserId(GetEventInt(event"userid")); //get the userid of the player picking up ammo
    
new weapon GetPlayerWeaponSlot(client0); //get his primary 1 weapon
        
    
new m_iPrimaryAmmoType GetEntProp(weaponProp_Send"m_iPrimaryAmmoType"); // Ammo type
    
new m_iClip1 = -1;
    new 
m_iAmmo_prim     = -1;
    
// Primary ammo
    
if(m_iPrimaryAmmoType != -1)
    {
        
m_iClip1 GetEntProp(weaponProp_Send"m_iClip1"); // weapon clip amount bullets
        
m_iAmmo_prim GetEntProp(clientProp_Send"m_iAmmo"_m_iPrimaryAmmoType); // Player ammunition for this weapon ammo type
        
PrintToChatAll("iClip1 %i iAmmo_prim %i"m_iClip1m_iAmmo_prim);
        
//SetEntProp(weapon, Prop_Send, "m_iClip1", 20); // Set weapon clip ammunition
        
SetEntProp(clientProp_Send"m_iAmmo"m_iAmmo_prim_m_iPrimaryAmmoType); // Set player ammunition of this weapon primary ammo type
    
}
    return 
Plugin_Handled;


I thought "m_iAmmo_prim" would deliver the current amount of ammo the player has got, but it always returns the maximum possible obviously. Any ideas how to retrieve the CURRENT amount of ammo for the player or what I am doing wrong here?
Hanzoligen is offline
QOOOOOOOOQ
Senior Member
Join Date: Dec 2012
Old 02-20-2013 , 18:45   Re: [L4D] Limit ammo pile usage to 1 clip per use
Reply With Quote #2

Next time try to search or google the exact problem you have, that's why it's there.

Possibly try this, you maybe missed it?
https://forums.alliedmods.net/showthread.php?t=81546

Last edited by QOOOOOOOOQ; 02-20-2013 at 18:46.
QOOOOOOOOQ is offline
Hanzoligen
Junior Member
Join Date: Feb 2013
Old 02-20-2013 , 18:52   [L4D] Limit ammo pile usage to 1 clip per use
Reply With Quote #3

I read this thread several times. It's almost the same method but he works with offsets. I tried to copy his code and received the same results.

I googled and searched everything for iAmmo but it doesnt return the actual amount the player has but the maximum possible.
Hanzoligen is offline
QOOOOOOOOQ
Senior Member
Join Date: Dec 2012
Old 02-20-2013 , 19:12   Re: [L4D] Limit ammo pile usage to 1 clip per use
Reply With Quote #4

Quote:
Originally Posted by Hanzoligen View Post
I read this thread several times. It's almost the same method but he works with offsets. I tried to copy his code and received the same results.

I googled and searched everything for iAmmo but it doesnt return the actual amount the player has but the maximum possible.


O..o well... idk if it'd work but what about when a client activates the ammo pickup event, get his weapon with GetClientWeapon, then GiveWeaponAmmo to that client based on what weapon it is, then return plugin handled?
QOOOOOOOOQ is offline
Hanzoligen
Junior Member
Join Date: Feb 2013
Old 02-20-2013 , 19:20   [L4D] Limit ammo pile usage to 1 clip per use
Reply With Quote #5

I can set a value of 99 ammo or whatever. But I cant get the current amount of ammo or add anything. Just set the amount.
Hanzoligen is offline
Marcus101RR
Veteran Member
Join Date: Aug 2009
Location: Tampa, FL
Old 02-25-2013 , 20:04   Re: [L4D] Limit ammo pile usage to 1 clip per use
Reply With Quote #6

Why the heck are you not using the convars?

ammo_assaultrifle_max = 50
ammo_buckshot_max = 10
ammo_huntingrifle_max = 15
ammo_smg_max = 50
__________________

Last edited by Marcus101RR; 02-25-2013 at 20:05.
Marcus101RR is offline
Send a message via AIM to Marcus101RR Send a message via Skype™ to Marcus101RR
Hanzoligen
Junior Member
Join Date: Feb 2013
Old 02-26-2013 , 04:06   [L4D] Limit ammo pile usage to 1 clip per use
Reply With Quote #7

Because I am trying to limit the amount of ammo in an ammo pile not the maximum amount of ammo in a gun.
Hanzoligen is offline
Marcus101RR
Veteran Member
Join Date: Aug 2009
Location: Tampa, FL
Old 02-26-2013 , 12:51   Re: [L4D] Limit ammo pile usage to 1 clip per use
Reply With Quote #8

Quote:
Originally Posted by Hanzoligen View Post
Because I am trying to limit the amount of ammo in an ammo pile not the maximum amount of ammo in a gun.
To limit the ammo file you are gonna have to do alot more scripting, first off you need to get the entitiy, second you need to store a value on how much ammo the survivors can take before it disappears. There is a plugin that uses that method but only limits the uses not the actually amount. Perhaps you should check it out and expand from there...
__________________
Marcus101RR is offline
Send a message via AIM to Marcus101RR Send a message via Skype™ to Marcus101RR
Hanzoligen
Junior Member
Join Date: Feb 2013
Old 02-26-2013 , 12:55   [L4D] Limit ammo pile usage to 1 clip per use
Reply With Quote #9

I did examine that plugin. It is clear to me what it does. I have all the code I need. I just cant get the value for the amount of ammo the survivor deploys. But I think this is because its not there. The game just sets ammo to max when using the pile. A guy tried to limit ammo pile usage to 1 clip and failed also
Hanzoligen is offline
Marcus101RR
Veteran Member
Join Date: Aug 2009
Location: Tampa, FL
Old 02-26-2013 , 14:08   Re: [L4D] Limit ammo pile usage to 1 clip per use
Reply With Quote #10

Quote:
Originally Posted by Hanzoligen View Post
I did examine that plugin. It is clear to me what it does. I have all the code I need. I just cant get the value for the amount of ammo the survivor deploys. But I think this is because its not there. The game just sets ammo to max when using the pile. A guy tried to limit ammo pile usage to 1 clip and failed also
Try both events, one for pre, one for post. Try to get the player's ammo on pre, and calculate how much they need based on post. Then subtract the amount from your entity's total. Once it reaches zero, kill the entity?
__________________
Marcus101RR is offline
Send a message via AIM to Marcus101RR Send a message via Skype™ to Marcus101RR
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 14:08.


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