• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

ZnoteACC - balance in characterprofile.php

therrax

Member
Joined
Jul 12, 2012
Messages
262
Solutions
1
Reaction score
11
Hello :)

Information: [ZnoteACC 1.5 TFS 1.0]

I am beginner ... :P
What should I add to my characterprofile.php to have balance of the character? Or how to show informations from my database, like VIP status or others :)
All suggestions are welcome. :)

Greets
 
This is all based on latest ZnoteAAC from https://github.com/Znote/ZnoteAAC/ and TFS 1.0.
To access data from your database you should always use the custom functions from ZnoteAAC, this way your script will always use the proper database driver.
mysql_select_single(query) - returns a single result. Note: even numbers are returned as a string, so you should always typecast the result to a number (int) if you want to do arithmethic (math) operations on it.
mysql_select_multi(query) - returns an array with results. Note from above also applies here.

For data from the 'players' table you can also use user_character_data(player_id, field[, additional fields]). If you're not familiar with SQL this is probably easier to use than for example mysql_select_single() but it only works if the data you need is in the 'players' table. Assuming that we already have the player_id stored in $user_id, in order to get the name and the balance of the player we could do like this:
PHP:
$data = user_character_data($user_id, 'name', 'balance');
echo 'Name: '.$data['name'].'<br />';
echo 'Balance: '.$data['balance'];

Similarly data from 'znote_players' table can be obtained through user_znote_character_data(player_id, field[, additional fields])

To give a concrete answer to your question, how to display the balance on the character profile:
Before you start changing things, it may be a good idea to back up the original file, just in case. You may also want to consider using the sub page system for your customized page, so the original remain unchanged. Quick how-to:
Copy characterprofile.php to /layout/sub/ and edit that file instead of the original. Add a case for your new page to /layout/sub.php. Just add a new case just like the others with an apropriate name and include /layout/sub/characterprofile.php.
PHP:
case 'characterprofile':
   include 'layout/sub/characterprofile.php';
break;
use /layout/sub.php?page=characterprofile to access your customized character profile. You need to edit your menu to link to the new URL.
Line 10 of characterprofile.php should look something like this:
PHP:
$profile_data = user_character_data($user_id, 'name', 'level', 'vocation', 'lastlogin', 'sex');
If we wanted to get the balance, the most efficient way would be to simply add 'balance' to the field list:
PHP:
$profile_data = user_character_data($user_id, 'name', 'level', 'vocation', 'lastlogin', 'sex', 'balance');
We now have the balance stored in $profile_data['balance']. Moving on, you can place a new <li> element anywhere you want inside ul element, <ul class="unstyled">, starting on line 25. To keep things simple I will just add the balance after "Created" date at line 66:
PHP:
<li><font class="profile_font" name="profile_font_created">Created: <?php echo getClock($profile_znote_data['created'], true); ?></font></li>
<li><font class="profile_font" name="profile_font_balance">Balance: <?php echo $profile_data['balance']; ?></font></li>

I don't know what the name property of the font element is used for, if anything, but I kept it in accordance with the others.
"But, hey, didn't you say that the database results are returned as a string, so we need to convert the balance into a number?" you may ask. Since we are not doing any math calculations, but rather just displaying the balance, we don't need to turn it into an actual number, in this case a string works just fine. However, if we wanted to check if the player have more than X amount in their balance, we would first need to convert the result to a number, which we can do by use of intval:
PHP:
$balance_as_number = intval($profile_data['balance']);

Long answer to a simple question, but I hope it is of some help though. :)
 
Back
Top