Raised This Month: $ Target: $400
 0% 

WeaponSpeed


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
_GamerX
AlliedModders Donor
Join Date: Jun 2011
Location: Fun Server
Old 11-07-2013 , 04:43   WeaponSpeed
Reply With Quote #1

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]))

Last edited by _GamerX; 11-07-2013 at 04:44.
_GamerX is offline
Send a message via ICQ to _GamerX Send a message via Skype™ to _GamerX
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 11-07-2013 , 07:21   Re: WeaponSpeed
Reply With Quote #2

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.
__________________
hleV is offline
_GamerX
AlliedModders Donor
Join Date: Jun 2011
Location: Fun Server
Old 11-07-2013 , 07:50   Re: WeaponSpeed
Reply With Quote #3

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

Last edited by _GamerX; 11-07-2013 at 08:21.
_GamerX is offline
Send a message via ICQ to _GamerX Send a message via Skype™ to _GamerX
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 11-07-2013 , 12:04   Re: WeaponSpeed
Reply With Quote #4

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" );

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 11-07-2013 at 12:05.
ConnorMcLeod is offline
_GamerX
AlliedModders Donor
Join Date: Jun 2011
Location: Fun Server
Old 11-08-2013 , 01:57   Re: WeaponSpeed
Reply With Quote #5

Very thanks.
_GamerX is offline
Send a message via ICQ to _GamerX Send a message via Skype™ to _GamerX
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 23:22.


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