AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Question on read_data() (https://forums.alliedmods.net/showthread.php?t=108650)

Doc-Holiday 11-07-2009 19:21

Question on read_data()
 
Some reason i get an error on the line that is bolded
(code from that unlimited ammo from mini-midget.)

PHP Code:

#define    SLOT_SECONDARY    2 

PHP Code:

stock g_WeaponSlots[] = {
    
0,
    
2,    //CSW_P228
    
0,
    
2,    //CSW_ELITE
    
2,    //CSW_FIVESEVEN
    
2,    //CSW_USP
    
2,    //CSW_GLOCK18
    
2,    //CSW_DEAGLE
}

stock g_MaxBPAmmo[] = {
    
0,
    
52,   //CSW_P228
    
0,
    
120//CSW_ELITE
    
100//CSW_FIVESEVEN
    
100,  //CSW_USP
    
120,  //CSW_GLOCK18
    
35,    //CSW_DEAGLE


PHP Code:

public event_weapon(id)
{
    new 
wp read_data(2)
    
    if (
g_WeaponSlots[wp] == SLOT_SECONDARY//Run time error 4 here... no idea why it does that...
    
{
        new 
ammo cs_get_user_bpammo(idwp)
        
        if (
ammo g_MaxBPAmmo[wp])
        {
            
cs_set_user_bpammo(idwpg_MaxBPAmmo[wp])
        }
    }



edit:
I added in the whole plugin and it worked fine but when i strip out the whole primary nade and c4 part i get errors any idea why

ConnorMcLeod 11-07-2009 21:03

Re: Question on read_data()
 
PHP Code:

stock g_WeaponSlots[] = {
    
0,
    
2,    //CSW_P228
    
0,
    
2,    //CSW_ELITE
    
2,    //CSW_FIVESEVEN
    
2,    //CSW_USP
    
2,    //CSW_GLOCK18
    
2,    //CSW_DEAGLE


This is completly wrong.

Code:

/* Id of weapons in CS */
#define CSW_P228                1
#define CSW_SCOUT                3
#define CSW_HEGRENADE                4
#define CSW_XM1014                5
#define CSW_C4                        6
#define CSW_MAC10                7
#define CSW_AUG                        8
#define CSW_SMOKEGRENADE        9
#define CSW_ELITE                10
#define CSW_FIVESEVEN                11
#define CSW_UMP45                12
#define CSW_SG550                13
#define CSW_GALI                14
#define CSW_GALIL                14
#define CSW_FAMAS                15
#define CSW_USP                        16
#define CSW_GLOCK18                17
#define CSW_AWP                        18
#define CSW_MP5NAVY                19
#define CSW_M249                20
#define CSW_M3                        21
#define CSW_M4A1                22
#define CSW_TMP                        23
#define CSW_G3SG1                24
#define CSW_FLASHBANG                25
#define CSW_DEAGLE                26
#define CSW_SG552                27
#define CSW_AK47                28
#define CSW_KNIFE                29
#define CSW_P90                        30

Your code would looks like :

PHP Code:

stock g_WeaponSlots[] = {
    
0,
    
2,    //CSW_P228
    
0,
    
1,    //CSW_SCOUT
    
4,    //CSW_HEGRENADE
    
1,    //CSW_XM1014
    
5,    //CSW_C4
    
1,    //CSW_MAC10



You could do something like this :
PHP Code:

#define IsWeaponTypeSecondary(%1)    (%1 & GUNS_BITSUM)
const GUNS_BITSUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)

public 
Event_CurWeapon(id)
{
    new 
iCswId read_data(2)

    if( 
IsWeaponTypeSecondary(iCswId) ) //Run time error 4 here... no idea why it does that...
    
{
        
// don't do useless checks
        //new ammo = cs_get_user_bpammo(id, wp)
        //if (ammo < g_MaxBPAmmo[wp])
        //{
        
cs_set_user_bpammo(idiCswIdGetGunMaxBpAmmo[iCswId])
    }
}

GetGunMaxBpAmmoCSW_ID )
{
    switch( 
CSW_ID )
    {
        case 
CSW_P228:
        {
            return 
52
        
}
        case 
CSW_ELITECSW_GLOCK18:
        {
            return 
120
        
}
        case 
CSW_FIVESEVENCSW_USP:
        {
            return 
100
        
}
        case 
CSW_DEAGLE:
        {
            return 
35
        
}
    }



Doc-Holiday 11-07-2009 21:13

Re: Question on read_data()
 
Problem is solved thanks though due to the fact that it checks all of the weapon id's you cant only have pistols there so i disabled the check of all primary weapons and just have it doing secondary weapons it works now.


Next i have to redo my virtual reality stuff.

ConnorMcLeod 11-07-2009 21:35

Re: Question on read_data()
 
For pistol infinite ammo you can do this :

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>

#define VERSION "0.0.1"

#define EXTRAOFFSET_WEAPONS    4
#define m_iId                43
#define m_iClip            51
#define m_iClientClip        52

#define fm_cs_get_weapon_id(%1)    get_pdata_int(%1, m_iId, EXTRAOFFSET_WEAPONS)
#define fm_cs_get_weapon_ammo(%1)    get_pdata_int(%1, m_iClip, EXTRAOFFSET_WEAPONS)
#define fm_cs_set_weapon_ammo(%1,%2)    set_pdata_int(%1, m_iClip, %2, EXTRAOFFSET_WEAPONS)

stock const g_iDftMaxClip[CSW_P90+1] = {
    -
1,  13, -110,  1,  7,    13030,  1,  30
        
2025303525,   12201030100
        
303020,  2,    73030, -1,  50}

public 
plugin_init()
{
    
register_plugin("Infinite Pistol Ammo"VERSION"ConnorMcLeod")

    new 
iCswGuns[] = {CSW_P228CSW_ELITECSW_FIVESEVENCSW_USPCSW_GLOCK18CSW_DEAGLE}
    new 
szWeaponName[20]

    for(new 
iCswId 0iCswId<sizeof(iCswGuns); iCswId++)
    {
        
get_weaponname(iCswGuns[iCswId], szWeaponNamecharsmax(szWeaponName))
        
RegisterHam(Ham_Item_PostFrameszWeaponName"Pistols_PostFrame")
    }
}

public 
Pistols_PostFrame(iEnt)
{
    new 
iClip fm_cs_get_weapon_ammo(iEnt)
    new 
iClientClip get_pdata_int(iEntm_iClientClipEXTRAOFFSET_WEAPONS)
    if( 
iClip != iClientClip )
    {
        new 
iMaxClip g_iDftMaxClipfm_cs_get_weapon_id(iEnt) ]
        if( 
iClip != iMaxClip )
        {
            
fm_cs_set_weapon_ammo(iEntiMaxClip)
            
set_pdata_int(iEntm_iClientClipiMaxClipEXTRAOFFSET_WEAPONS)
            return 
HAM_HANDLED
        
}
    }
    return 
HAM_IGNORED



Doc-Holiday 11-07-2009 23:31

Re: Question on read_data()
 
Get an error on the fm_cs_set_weapon_ammo(iEnt, iMaxClip)

saying number of arguments dosent match definition

ConnorMcLeod 11-08-2009 06:02

Re: Question on read_data()
 
Fixed.

Doc-Holiday 11-08-2009 06:17

Re: Question on read_data()
 
Quote:

Originally Posted by ConnorMcLeod (Post 983928)
Fixed.

Thank you testing again

PHP Code:

static iMaxClip
new   iMaxClip GetGunMaxBpAmmoiEnt 

Might wanna fix that so that some one else searching doesn't have to figure it out yet its super simple

ConnorMcLeod 11-08-2009 06:56

Re: Question on read_data()
 
Removed "static iMaxClip".
And fixed maxclip != maxbpammo

Doc-Holiday 11-08-2009 07:09

Re: Question on read_data()
 
Quote:

Originally Posted by ConnorMcLeod (Post 983963)
Removed "static iMaxClip".
And fixed maxclip != maxbpammo


ill have to try again since its 4am here and i havent slept ahahahaha
Ok so i tested and it didnt do any thing.

i give weapons through menu. so not sure if that's an issue


All times are GMT -4. The time now is 17:39.

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