Error help related to arrays
#1

I'm trying to create damage system which displays all damage a player takes. I've encountered a problem.
Whenever a player takes a headshot, I want function GetWeaponDamage(I made it) to multiply and show it as, for example, 60 instead of 30. This is the error:
pawn Код:
error 033: array must be indexed (variable "GetWeaponDamage")
The actual line:
pawn Код:
format(AddStr, sizeof(AddStr), "\n%d hits from %s("COL_RED"-%d"COL_WHITE") to HEAD", ShotAt[playerid][i][Bodypart][z], WeaponName(i), GetWeaponDamage(i)*2), strcat(dmgstring, AddStr);
The GetWeaponDamage(i)*2 does the error


This is GetWeaponDamage:
pawn Код:
GetWeaponDamage(WeaponID)
{
    new wepdamage[20];
    switch(WeaponID)
    {
        case 0,1..8: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_BRASS));
        case 22: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_COLT));
        case 23: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_SILENCED));
        case 24: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_DEAGLE));
        case 25: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_SHOTGUN));
        case 27: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_COMBAT));
        case 28: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_UZI));
        case 29: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_MP5));
        case 30: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_AK47));
        case 31: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_M4));
        case 32: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_TEC9));
        case 33: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_RIFLE));
        case 34: format(wepdamage,sizeof(wepdamage), "%d", floatround(WEAPON_DMG_SNIPER));
    }
    return wepdamage;
}
And the defines of WEAPON_DMG_something are 5.0, 20.0 etc...
Reply
#2

Код:
format(AddStr, sizeof(AddStr), "\n%d hits from %s("COL_RED"-%d"COL_WHITE") to HEAD", ShotAt[playerid][i][Bodypart][z], WeaponName(i), GetWeaponDamage(i)*2), strcat(dmgstring, AddStr);
remove red paranthesis.
Reply
#3

Quote:
Originally Posted by Sreyas
Посмотреть сообщение
Код:
format(AddStr, sizeof(AddStr), "\n%d hits from %s("COL_RED"-%d"COL_WHITE") to HEAD", ShotAt[playerid][i][Bodypart][z], WeaponName(i), GetWeaponDamage(i)*2), strcat(dmgstring, AddStr);
remove red paranthesis.
Not that. I am making two functions in one. If you pay attention, the strcat is not related to the format, thus its not the solution
Reply
#4

A string cannot be multiplied.

Код:
GetWeaponDamage(WeaponID)
{
    switch(WeaponID)
    {
        case 0,1..8: return floatround(WEAPON_DMG_BRASS);
        case 22: return floatround(WEAPON_DMG_COLT);
        case 23: return floatround(WEAPON_DMG_SILENCED);
        case 24: return floatround(WEAPON_DMG_DEAGLE);
        case 25: return floatround(WEAPON_DMG_SHOTGUN);
        case 27: return floatround(WEAPON_DMG_COMBAT);
        case 28: return floatround(WEAPON_DMG_UZI);
        case 29: return floatround(WEAPON_DMG_MP5);
        case 30: return floatround(WEAPON_DMG_AK47);
        case 31: return floatround(WEAPON_DMG_M4);
        case 32: return floatround(WEAPON_DMG_TEC9);
        case 33: return floatround(WEAPON_DMG_RIFLE);
        case 34: return floatround(WEAPON_DMG_SNIPER);
    }
    return -1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)