AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [L4D] Limit ammo pile usage to 1 clip per use (https://forums.alliedmods.net/showthread.php?t=209023)

Hanzoligen 02-20-2013 05:10

[L4D] Limit ammo pile usage to 1 clip per use
 
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?

QOOOOOOOOQ 02-20-2013 18:45

Re: [L4D] Limit ammo pile usage to 1 clip per use
 
Next time try to search or google the exact problem you have, that's why it's there. :P

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

Hanzoligen 02-20-2013 18:52

[L4D] Limit ammo pile usage to 1 clip per use
 
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.

QOOOOOOOOQ 02-20-2013 19:12

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

Originally Posted by Hanzoligen (Post 1898580)
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?

Hanzoligen 02-20-2013 19:20

[L4D] Limit ammo pile usage to 1 clip per use
 
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.

Marcus101RR 02-25-2013 20:04

Re: [L4D] Limit ammo pile usage to 1 clip per use
 
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

Hanzoligen 02-26-2013 04:06

[L4D] Limit ammo pile usage to 1 clip per use
 
Because I am trying to limit the amount of ammo in an ammo pile not the maximum amount of ammo in a gun.

Marcus101RR 02-26-2013 12:51

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

Originally Posted by Hanzoligen (Post 1902168)
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...

Hanzoligen 02-26-2013 12:55

[L4D] Limit ammo pile usage to 1 clip per use
 
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

Marcus101RR 02-26-2013 14:08

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

Originally Posted by Hanzoligen (Post 1902414)
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?


All times are GMT -4. The time now is 13:29.

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