Raised This Month: $ Target: $400
 0% 

[SOLVED] Setting ammo fails


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
dataviruset
AlliedModders Donor
Join Date: Feb 2009
Location: Hong Kong
Old 06-18-2010 , 16:45   [SOLVED] Setting ammo fails
Reply With Quote #1

Hello!

I am trying to set the ammo of the active weapons of two players.
It seems that is doesn't work sometimes and for certain players...

PHP Code:
StripAllWeapons(LRprogressplayer1);
StripAllWeapons(LRprogressplayer2);

// set HP
SetEntData(LRprogressplayer1FindSendPropOffs("CBasePlayer""m_iHealth"), 100);
SetEntData(LRprogressplayer2FindSendPropOffs("CBasePlayer""m_iHealth"), 100);

CreateTimer(GetConVarFloat(sm_hosties_lr_ns_delay), NSstart_TIMER_FLAG_NO_MAPCHANGE); 
PHP Code:
public Action:NSstart(Handle:timer)
{
    if ( (
IsClientInGame(LRprogressplayer1)) && (IsPlayerAlive(LRprogressplayer1))
    && (
IsClientInGame(LRprogressplayer2)) && (IsPlayerAlive(LRprogressplayer2))
    && (
LRtype == 6) )
    {
        
// play no scope start sound
        
if (!StrEqual(noscope_sound"-1"))
            
EmitSoundToAll(noscope_sound);


        
GivePlayerItem(LRprogressplayer1"weapon_knife");
        
GivePlayerItem(LRprogressplayer2"weapon_knife");

        
decl NSw1NSw2;
        if (
GetConVarInt(sm_hosties_lr_ns_weapon) == 1)
        {
            
NSw1 CreateEntityByName("weapon_scout");
            
NSw2 CreateEntityByName("weapon_scout");
        }
        else
        {
            
NSw1 CreateEntityByName("weapon_awp");
            
NSw2 CreateEntityByName("weapon_awp");
        }

        
DispatchSpawn(NSw1);
        
DispatchSpawn(NSw2);
        
EquipPlayerWeapon(LRprogressplayer1NSw1);
        
EquipPlayerWeapon(LRprogressplayer2NSw2);
        

        
// set ammo
        
new iWeapon GetEntDataEnt2(LRprogressplayer1FindSendPropInfo("CCSPlayer""m_hActiveWeapon"));
        
SetEntData(iWeaponFindSendPropInfo("CBaseCombatWeapon""m_iClip1"), 99);
        new 
iWeapon2 GetEntDataEnt2(LRprogressplayer2FindSendPropInfo("CCSPlayer""m_hActiveWeapon"));
        
SetEntData(iWeapon2FindSendPropInfo("CBaseCombatWeapon""m_iClip1"), 99);
    }

    return 
Plugin_Continue;


Last edited by dataviruset; 06-19-2010 at 21:53. Reason: I solved it :)
dataviruset is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 06-18-2010 , 20:12   Re: Setting ammo fails
Reply With Quote #2

Tried m_iAmmo? Clip 1 and clip 2 is the clip reserve for primary and secondary weapons I think.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
dataviruset
AlliedModders Donor
Join Date: Feb 2009
Location: Hong Kong
Old 06-18-2010 , 21:14   Re: Setting ammo fails
Reply With Quote #3

I don't think that's the problem because it always works for me, but for other players it doesn't, some times...
dataviruset is offline
rhelgeby
Veteran Member
Join Date: Oct 2008
Location: 0x4E6F72776179
Old 06-19-2010 , 09:43   Re: Setting ammo fails
Reply With Quote #4

If it's "random" it might depend on when you set the ammo. You already have a timer so it might be ok.

Also check the conditions for setting it. What is LRtype? Did you remember to make sure it has a valid/updated value before creating the timer? Any chance that it might be changed before the timer is triggered, like a new event before the other one is done?

And I assume LRprogressplayer1 and 2 are caches for global client indexes? Do they get updated properly too.

Since you actually got it working on one or more players, you should check the conditions when applying it. What if a player change to secondary/primary weapon? What if a player drop it and pick up another one.

I've also done mistakes where I've used the wrong variable in a feature, where it some how still worked for some players.
__________________
Richard Helgeby

Zombie:Reloaded | PawnUnit | Object Library
(Please don't send private messages for support, they will be ignored. Use the forum.)
rhelgeby is offline
Send a message via MSN to rhelgeby
dataviruset
AlliedModders Donor
Join Date: Feb 2009
Location: Hong Kong
Old 06-19-2010 , 10:42   Re: Setting ammo fails
Reply With Quote #5

It seems that I always get 99 ammo and some others as well, but it's always the same persons... O_o
dataviruset is offline
dataviruset
AlliedModders Donor
Join Date: Feb 2009
Location: Hong Kong
Old 06-19-2010 , 21:52   Re: Setting ammo fails
Reply With Quote #6

I got it to work, I had to do it this way instead... It isn't what I was looking for, but a more optimized solution to the problem:

PHP Code:
        decl NSw1NSw2;
        if (
GetConVarInt(sm_hosties_lr_ns_weapon) == 1)
        {
            
NSw1 CreateEntityByName("weapon_scout");
            
NSw2 CreateEntityByName("weapon_scout");
        }
        else
        {
            
NSw1 CreateEntityByName("weapon_awp");
            
NSw2 CreateEntityByName("weapon_awp");
        }

        
DispatchSpawn(NSw1);
        
DispatchSpawn(NSw2);
        
EquipPlayerWeapon(LRprogressplayer1NSw1);
        
EquipPlayerWeapon(LRprogressplayer2NSw2);

        
SetEntData(NSw1FindSendPropInfo("CBaseCombatWeapon""m_iClip1"), 99);
        
SetEntData(NSw2FindSendPropInfo("CBaseCombatWeapon""m_iClip1"), 99); 
dataviruset is offline
meng
Veteran Member
Join Date: Oct 2005
Location: us
Old 06-19-2010 , 22:26   Re: [SOLVED] Setting ammo fails
Reply With Quote #7

Just stash the offsets globally, especially if it helps with stability issues.
__________________
.
[ 1 Dumerils Boa | 1 Cali King ]...
.
I'm a lil' spirituous.
meng is offline
Send a message via Yahoo to meng
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 13:27.


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