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

Percentage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bladell
Senior Member
Join Date: Jun 2012
Old 05-19-2013 , 09:09   Percentage
Reply With Quote #1

I want to make
Code:
LVL:%d/%d XP:%d% for next level
to be in percentage, like this for example...
Code:
31% until next level
This is my try...
Code:
	new message[64], temp[64]
	new heroIndex, MaxBinds, count, playerLevel, playerpowercount
	new menuid, mkeys
	new gPercent = (gPlayerXP[id]*100)/gXPLevel[playerLevel+1]

	count = 0
	playerLevel = gPlayerLevel[id]

	if ( playerLevel < gNumLevels ) {
		formatex(message, charsmax(message), "LVL:%d/%d XP:%d% for next level", playerLevel, gNumLevels, gPercent)
	}
	else {
		formatex(message, charsmax(message), "LVL:%d/%d XP:(%d)", playerLevel, gNumLevels, gPlayerXP[id])
	}
What is wrong?
Bladell is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 05-20-2013 , 06:26   Re: Percentage
Reply With Quote #2

What's wrong is that you are just making a bunch of variables but you never retrieve any values in them, so they are all just 0.

You need to loop through all players using a for loop, then, for each user get their XP and then calculate the percentage he is at before getting a new level, and then print it to him.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Bladell
Senior Member
Join Date: Jun 2012
Old 05-22-2013 , 09:47   Re: Percentage
Reply With Quote #3

This is to much for me...thanks anyway.
Bladell is offline
Bladell
Senior Member
Join Date: Jun 2012
Old 05-31-2013 , 05:17   Re: Percentage
Reply With Quote #4

Anyway...can you give me a example please?
Bladell is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 05-31-2013 , 08:23   Re: Percentage
Reply With Quote #5

Show the whole code, if you got more than that.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Bladell
Senior Member
Join Date: Jun 2012
Old 05-31-2013 , 09:40   Re: Percentage
Reply With Quote #6

This is the original code:
Code:
	// OK Test What Level this Fool is
	testLevel(id)

	new message[64], temp[64]
	new heroIndex, MaxBinds, count, playerLevel, playerpowercount
	new menuid, mkeys
	new gPercent = (gPlayerXP[id]*100)/gXPLevel[playerLevel+1]

	count = 0
	playerLevel = gPlayerLevel[id]

	if ( playerLevel < gNumLevels ) {
		formatex(message, charsmax(message), "LVL:%d/%d XP:%d% for next level", playerLevel, gNumLevels, gPercent)
	}
	else {
		formatex(message, charsmax(message), "LVL:%d/%d XP: (%d)", playerLevel, gNumLevels, gPlayerXP[id])
	}
This is my try:
Code:
	// OK Test What Level this Fool is
	testLevel(id)

	new message[64], temp[64]
	new heroIndex, MaxBinds, count, playerLevel, playerpowercount
	new menuid, mkeys
        new gDiff = (
	new gPercent = (gPlayerXP[id]*100)/gXPLevel[playerLevel+1]

	count = 0
	playerLevel = gPlayerLevel[id]

	if ( playerLevel < gNumLevels ) {
		formatex(message, charsmax(message), "LVL:%d/%d XP:%d% for next level", playerLevel, gNumLevels, gPercent)
	}
	else {
		formatex(message, charsmax(message), "LVL:%d/%d XP: (%d)", playerLevel, gNumLevels, gPlayerXP[id])
	}
This is all I have...

Last edited by Bladell; 06-01-2013 at 10:36.
Bladell is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 05-31-2013 , 16:53   Re: Percentage
Reply With Quote #7

PHP Code:
#include <superheromod>

new gPlayerLevel[33]
new 
gServerLevels[33]
new 
gRequiredXP[33]
new 
gPlayerXP[33]

public 
plugin_init()
{
    
register_plugin("Superhero show percent""1.0""Jelle")
    
    
set_task(1.0"get_level"__"b")
}

public 
get_level()
{
    new 
players[32], playerCount
    get_players
(playersplayerCount"ah")
    
    
gServerLevels sh_get_num_lvls()
    
    for ( new 
0playerCounti++ )
    {
        
gPlayerLevel[i] = sh_get_user_lvl(i)
        
        if ( 
gPlayerLevel[i] > gServerLevels )
        {
            
gRequiredXP[i] = sh_get_lvl_xp(gPlayerLevel[i])
        }
        
        else
        {
            
gRequiredXP[i] = 0
        
}
        
        
gPlayerXP[i] = sh_get_user_xp(i)
        
        
/*
        * Now show the message here
        */
    
}

I started it for you. Now you got all the values you would need to make such a thing, all you have to do is calculate it and print it.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Bladell
Senior Member
Join Date: Jun 2012
Old 06-11-2013 , 05:07   Re: Percentage
Reply With Quote #8

Exist there a variable wich tell me how much xp I need for my current lvl?Without this variable there is no way to make this plugin.
Bladell is offline
Jelle
[b]MOAR CANDY[/b]
Join Date: Aug 2009
Location: Denmark
Old 06-11-2013 , 08:11   Re: Percentage
Reply With Quote #9

You can see how much XP the player has, and how much is needed for the next level. From there you should be able to create an algorithm which calculate the XP needed in percent.
__________________
No idea what to write here...
Jelle is offline
Send a message via MSN to Jelle
Bladell
Senior Member
Join Date: Jun 2012
Old 06-11-2013 , 10:34   Re: Percentage
Reply With Quote #10

There is no way without a variable that know what is the necessary xp for prev level.
My superhero.ini is something like this:
Code:
100 300 500 900 2000 9000 10000
no something like this
Code:
100 200 400 800 1600
There is no way to create a algorithm wich calculate the necessary xp in percent if you don't know how much xp you need for prev level !!!
Show me a example if you know...
Bladell 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 20:26.


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