SA-MP Forums Archive
Error help related to arrays - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Error help related to arrays (/showthread.php?tid=614941)



Error help related to arrays - barbarbar1 - 15.08.2016

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...


Re: Error help related to arrays - SyS - 15.08.2016

Код:
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.


Re: Error help related to arrays - barbarbar1 - 15.08.2016

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


Re: Error help related to arrays - Stinged - 15.08.2016

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;
}