Raised This Month: $51 Target: $400
 12% 

returning a value


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
reinert
Veteran Member
Join Date: Feb 2007
Old 01-25-2011 , 11:49   returning a value
Reply With Quote #1

Hey, I've make native like get_user_skill, but it always returns 1... where is the problem ??

PHP Code:
get_user_skill(id)
{
    return ( (
iKills[id] / iDeaths[id]) + (iHeadshots[id] / iKills[id]) * 32 );

PHP Code:
client_printc(id"\g[ RANK ]\n You've %d skill, %d kills,  %d deaths, %d headshots."get_user_skill(id), iKills[id], iDeaths[id],  iHeadshots[id]) 
iKills = 6451
iDeaths = 4198
iHeadshots = 3216

(6451 / 4198) + (3216 / 6451) * 32 = ~17

Print output:

Quote:
[ RANK ] You've 1 skill, 6451 kills, 4198 deaths, 3216 headshots
reinert is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-25-2011 , 11:51   Re: returning a value
Reply With Quote #2

(6451 / 4198) + (3216 / 6451) * 32 = 1

6451 / 4192 = 1

3216 / 6451 = 0

0 * 32 = 0

1 + 0 = 1


/ is the entire division.
You should float the values, and round the result.


Or :

PHP Code:
get_user_skill(id)
{
    return ( (
1000*iKills[id] / iDeaths[id]) + (1000*iHeadshots[id] / iKills[id]) * 32 ) / 1000;

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 01-25-2011 at 11:56.
ConnorMcLeod is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 01-25-2011 , 11:55   Re: returning a value
Reply With Quote #3

Thanks! SOLVED

Last edited by reinert; 01-25-2011 at 12:09.
reinert is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 01-25-2011 , 12:43   Re: returning a value
Reply With Quote #4

Um I'm getting some errors in my logs, please help:

Quote:
L 01/25/2011 - 19:10:02: [AMXX] Displaying debug trace (plugin "rank.amxx")
L 01/25/2011 - 19:10:02: [AMXX] Run time error 11: divide
L 01/25/2011 - 19:10:02: [AMXX] [0] rank.sma::get_user_skill (line 314)
L 01/25/2011 - 19:10:02: [AMXX] [1] rank.sma::Save_MySql (line 283)
L 01/25/2011 - 19:10:02: [AMXX] [2] rank.sma::client_disconnect (line 303)
line 314:

PHP Code:
return ( (1000*iKills[id] / iDeaths[id]) + (1000*iHeadshots[id] / iKills[id]) * 1954 ) / 1000
Line 283:

PHP Code:
format(szTemp,charsmax(szTemp),"UPDATE `rank` SET `name` = '%s', `kills` = '%d', `deaths` = '%d', `headshots` = '%d', `skill` = '%d' WHERE `rank`.`SteamID` = '%s';",szNameiKills[id], iDeaths[id], iHeadshots[id], get_user_skill(id), szSteamID); 
Line 303:

PHP Code:
public client_disconnect(id)
{
    
Save_MySql(id); // <- 303
    
iKills[id] = 0;
    
iDeaths[id] = 0;
    
iHeadshots[id] = 0;
    
iBonus[id] = 0;

reinert is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-25-2011 , 14:38   Re: returning a value
Reply With Quote #5

Probably because you are dividing by 0.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 01-25-2011 , 14:43   Re: returning a value
Reply With Quote #6

So what shall I do ?
reinert is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-25-2011 , 14:50   Re: returning a value
Reply With Quote #7

Check if variables equal 0 and do something different?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 01-25-2011 , 14:58   Re: returning a value
Reply With Quote #8

In which part should I check it ? Before saving or where ?
PHP Code:
if(iKills[id] != || iDeaths[id] != 0)
{
   
client_printc(id"Your skill is"get_user_skill(id))

reinert is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-25-2011 , 15:52   Re: returning a value
Reply With Quote #9

Inside get_user_skill().
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
reinert
Veteran Member
Join Date: Feb 2007
Old 01-25-2011 , 15:59   Re: returning a value
Reply With Quote #10

should I return false, yes ?
reinert is offline
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 08:21.


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