AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   WeaponSpeed (https://forums.alliedmods.net/showthread.php?t=229403)

_GamerX 11-07-2013 04:43

WeaponSpeed
 
Hi please help with my script:
PHP Code:

public Item_GetMaxSpeed(iWeapon)
{
    new 
iId get_pdata_int(iWeapon434)
    if(
get_user_team(iId) == || iWeapon == 0) return HAM_IGNORED

    SetHamReturnFloat
(gun_speed[iWeapon] + float(L_gun[iId][iWeapon]))

    return 
HAM_SUPERCEDE


error:
Code:

L 11/07/2013 - 10:03:07: [AMXX] Run time error 4: index out of bounds
L 11/07/2013 - 10:03:07: [AMXX]    [0] FuriMod.sma::Item_GetMaxSpeed (line 9748)

Line 9748: SetHamReturnFloat(gun_speed[iWeapon] + float(L_gun[iId][iWeapon]))

hleV 11-07-2013 07:21

Re: WeaponSpeed
 
iWeapon is the weapon's entity ID, while iId is the weapon's ID (CSW_*). I don't think you should use iWeapon as index for gun_speed[] and L_gun[][] arrays, but it would help if you shown how you declare these arrays and describe their purpose.

_GamerX 11-07-2013 07:50

Re: WeaponSpeed
 
PHP Code:

new const Float:gun_speed[31] =
{
    
0.0,
    
250.0,
    
260.0,
    
250.0,
    
240.0,
    
250.0,
    
250.0,
    
240.0,
    
250.0,
    
250.0,
    
250.0,
    
250.0,
    
210.0,
    
240.0,
    
240.0,
    
250.0,
    
250.0,
    
210.0,
    
250.0,
    
220.0,
    
230.0,
    
230.0,
    
250.0,
    
210.0,
    
250.0,
    
250.0,
    
235.0,
    
221.0,
    
250.0,
    
245.0
}; 

PHP Code:

L_gun[33][31

index type CSW_*

TEST 2:
PHP Code:

public Item_GetMaxSpeed(iWeapon)
{
    new 
iId get_pdata_int(iWeapon434)
    new 
id get_pdata_int(iWeapon414)
    if(
get_user_team(id) == || iId == 0) return HAM_IGNORED
    SetHamReturnFloat
(gun_speed[iId] + float(L_gun[id][iId]))
    return 
HAM_SUPERCEDE


but still write error

ConnorMcLeod 11-07-2013 12:04

Re: WeaponSpeed
 
gun_speed array is missing a cell
you are using get_pdata_int instead of _cbase for m_pPlayer pdata.

Also, use offsets names, it prevents from making errors and helps a lot for readability.

PHP Code:

const XO_CBASEPLAYERITEM 4;
const 
m_pPlayer 41;
const 
m_iId 43;

new const 
Float:gun_speed[CSW_P90+1] =
{
    
0.0,
    
250.0,    // CSW_P228
    
0.0,
    
260.0,    // CSW_SCOUT
    
250.0,    // CSW_HEGRENADE
    
240.0,    // CSW_XM1014
    
250.0,    // CSW_C4
    
250.0,    // CSW_MAC10
    
240.0,    // CSW_AUG
    
250.0,    // CSW_SMOKEGRENADE
    
250.0,    // CSW_ELITE
    
250.0,    // CSW_FIVESEVEN
    
250.0,    // CSW_UMP45
    
210.0,    // CSW_SG550
    
240.0,    // CSW_GALIL
    
240.0,    // CSW_FAMAS
    
250.0,    // CSW_USP
    
250.0,    // CSW_GLOCK18
    
210.0,    // CSW_AWP
    
250.0,    // CSW_MP5NAVY
    
220.0,    // CSW_M249
    
230.0,    // CSW_M3
    
230.0,    // CSW_M4A1
    
250.0,    // CSW_TMP
    
210.0,    // CSW_G3SG1
    
250.0,    // CSW_FLASHBANG
    
250.0,    // CSW_DEAGLE
    
235.0,    // CSW_SG552
    
221.0,    // CSW_AK47
    
250.0,    // CSW_KNIFE
    
245.0    // CSW_P90
};

new 
Float:L_gun[33][CSW_P90+1]; // use Floats here, it is stupid to float values later...

public Item_GetMaxSpeed(iWeapon)
{
    new 
iId get_pdata_int(iWeaponm_iIdXO_CBASEPLAYERITEM);
    new 
id get_pdata_cbase(iWeaponm_pPlayerXO_CBASEPLAYERITEM);
    if( 
iId && id && get_user_team(id) != )
    {
        
SetHamReturnFloat(gun_speed[iId] + L_gun[id][iId]);
        return 
HAM_SUPERCEDE;
    }
    return 
HAM_IGNORED;
}  

public 
plugin_init()
{
    
register_pluginPLUGINVERSION"ConnorMcLeod" );



_GamerX 11-08-2013 01:57

Re: WeaponSpeed
 
Very thanks.


All times are GMT -4. The time now is 23:14.

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