Format returning SERVER:UNKNOWN COMMAND
#1

Hello,
I m experiencing problem while trying to divide UserStats[targetid][WeaponHitsOP] with UserStats[targetid][MissedWeaponHits]

PHP Code:
    format(stringsizeof(string), "{FF0000}[STATS] {FFFFFF}Kills: %d, Deaths: %d, Ratio: %0.2f, Hit accuracy: %d"UserStats[targetid][Kills],UserStats[targetid][Deaths],floatdiv(UserStats[targetid][Kills], UserStats[targetid][Deaths]), UserStats[targetid][WeaponHitsOP]/UserStats[targetid][MissedWeaponHits]);
    
SendClientMessage(playeridCOLOR_WHITEstring); 
Command would return "SERVER: Unknown command" error. Why?
If I remove that part of code, or just the accuracy, everything would be fine.
Reply
#2

Can you show me the full of code?
Reply
#3

Here you go.

PHP Code:
CMD<ALL>:stats(cmdidplayeridparams[])
{
    new 
targetidstring[128];
    if(
sscanf(params"u"targetid)) targetid playerid;
    if(!
IsPlayerConnected(targetid)) return SCM(playeridCOLOR_REDNOPLAYER);
    if(!
LoggedIn[targetid]) return SCM(playeridCOLOR_REDNOTLOGGEDIN);
    
SendClientMessage(playeridCOLOR_TOMATO"");
    
format(stringsizeof(string), "..:: %s's account statistic ::.."GetName(targetid));
    
SendClientMessage(playeridCOLOR_TOMATOstring);
    
format(stringsizeof(string), "{FF0000}[WEAPON KILLS] {FFFFFF}Deagle: %d, Sniper: %d, M4: %d, Shotgun: %d, Combat: %d, MP5: %d, SawnOff: %d"UserStats[targetid][DeagleKills],UserStats[targetid][SniperKills],UserStats[targetid][M4Kills], UserStats[targetid][ShotgunKills],UserStats[targetid][CombatKills],UserStats[targetid][MP5Kills],UserStats[targetid][SawnOffKills]);
    
SendClientMessage(playeridCOLOR_WHITEstring);
    
format(stringsizeof(string), "{FF0000}[STATS] {FFFFFF}Kills: %d, Deaths: %d, Ratio: %0.2f, Hit accuracy: %d"UserStats[targetid][Kills],UserStats[targetid][Deaths],floatdiv(UserStats[targetid][Kills], UserStats[targetid][Deaths]), UserStats[targetid][WeaponHitsOnPlayer]/UserStats[targetid][MissedWeaponHits]);
    
SendClientMessage(playeridCOLOR_WHITEstring);
    
SendClientMessage(playeridCOLOR_TOMATO"");
    return 
1;

The command works if I don't include that part.
Reply
#4

Quote:
Originally Posted by kovac
View Post
Here you go.

PHP Code:
format(stringsizeof(string), "{FF0000}[STATS] {FFFFFF}Kills: %d, Deaths: %d, Ratio: %0.2f, Hit accuracy: %d"UserStats[targetid][Kills],UserStats[targetid][Deaths],floatdiv(UserStats[targetid][Kills], UserStats[targetid][Deaths]), UserStats[targetid][WeaponHitsOnPlayer]/UserStats[targetid][MissedWeaponHits]); // -----  is this slash should be really there? 
The command works if I don't include that part.
I just found something correct me if i'm wrong
PHP Code:
CMD<ALL>:stats(cmdidplayeridparams[]) 

    new 
targetidstring[128]; 
    if(
sscanf(params"u"targetid)) targetid playerid
    if(!
IsPlayerConnected(targetid)) return SCM(playeridCOLOR_REDNOPLAYER); 
    if(!
LoggedIn[targetid]) return SCM(playeridCOLOR_REDNOTLOGGEDIN); 
    
SendClientMessage(playeridCOLOR_TOMATO""); 
    
format(stringsizeof(string), "..:: %s's account statistic ::.."GetName(targetid)); 
    
SendClientMessage(playeridCOLOR_TOMATOstring); 
    
format(stringsizeof(string), "{FF0000}[WEAPON KILLS] {FFFFFF}Deagle: %d, Sniper: %d, M4: %d, Shotgun: %d, Combat: %d, MP5: %d, SawnOff: %d"UserStats[targetid][DeagleKills],UserStats[targetid][SniperKills],UserStats[targetid][M4Kills], UserStats[targetid][ShotgunKills],UserStats[targetid][CombatKills],UserStats[targetid][MP5Kills],UserStats[targetid][SawnOffKills]); 
    
SendClientMessage(playeridCOLOR_WHITEstring); 
    
format(stringsizeof(string), "{FF0000}[STATS] {FFFFFF}Kills: %d, Deaths: %d, Ratio: %0.2f, Hit accuracy: %d"UserStats[targetid][Kills],UserStats[targetid][Deaths],floatdiv(UserStats[targetid][Kills], UserStats[targetid][Deaths]), UserStats[targetid][WeaponHitsOnPlayer], UserStats[targetid][MissedWeaponHits]); 
    
SendClientMessage(playeridCOLOR_WHITEstring); 
    
SendClientMessage(playeridCOLOR_TOMATO""); 
    return 
1

Reply
#5

Let me guess your problem:
You are trying to divide with zero...

When the player has hits but never missed, they will get that error in commands.

You need to check first if MissedWeaponHits has positive value, then you can divide with it. When both is zero, simply tells the player has no accuracy, otherwise 100% accuracy.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)