Page 1 of 1

how to get the HP to refresh the actual numbers

Posted: Thu Feb 13, 2014 4:34 pm
by KaL
Ok, i set the restore_rate= 0 from user_stat_types on myphpadmin. so i can stop the restore HP.


here is my module to reduce HP, it works! But the HP doesn't refresh it self. i verified it through the database and the numbers dropped but the website didn't. How can i refresh the HP on the website to show the actual numbers that are left?

$result = $db->Execute("select value from user_stats where stat_type = ?",1);
$hp = $result->fields[0];
header("Location: index.php");
$reducer = $hp - 5;
$db->Execute("update user_stats set value = $reducer WHERE stat_type = ?",1);
if ($hp < 6)
{
$result = $db->Execute("select value from user_stats where stat_type = ?",1);
$hp = $result->fields[0];
$add = $hp + 1;
$db->Execute("update user_stats set value = $add WHERE stat_type = ?",1);
}

Re: how to get the HP to refresh the actual numbers

Posted: Thu Feb 13, 2014 7:49 pm
by a_bertrand
The engine cache those value in the session, and only reload while loggin in or if you set stats_modified (in the users table) to yes

Re: how to get the HP to refresh the actual numbers

Posted: Thu Feb 13, 2014 10:52 pm
by KyleMassacre
I could be wrong and bert can correct me if so but I think if you use the $userStats you maybe able to achieve what you wish

Re: how to get the HP to refresh the actual numbers

Posted: Fri Feb 14, 2014 3:46 am
by KaL
Yeah! I added $userStat, It works! Thanks guys! I have 2 more question. How do I select all user from the database? I tried the * Sign for: where user_id =?",*)and fail and another question, If I change the stat modifed to yes will that slow the game down a bit?

Re: how to get the HP to refresh the actual numbers

Posted: Fri Feb 14, 2014 4:16 am
by KyleMassacre
KaL wrote:Yeah! I added $userStat, It works! Thanks guys! I have 2 more question. How do I select all user from the database? I tried the * Sign for: where user_id =?",*)and fail and another question, If I change the stat modifed to yes will that slow the game down a bit?
  1. Your very welcome
  2. Code: Select all

    $users = $db->Execute("select * from users where id = ?",$someUserId);
     
  3. Well with any query you are adding a bit of strain. Its best to be as optimal as you can when dealing with any kind of database manipulation. So to put it into laments terms, as long as you are limiting you update or select queries or whatever have you by using some sort of clause like "WHERE" or a "LIMIT" you should be fine.
Also like I said before, if you do for example:

Code: Select all

$stats = UserStat::LoadStats($users->fields[0]);
$stats['!Currency']->value += $someValue;
UserStat::SaveStats($stats, $users->fields[0]);
 
The SaveStats method should update stats_modified to 'yes' for you in most cases.

And another thing you should avoid using wildcards because that may produce unnecessary strain as well. Just select the fields you know your going to use.

Re: how to get the HP to refresh the actual numbers

Posted: Fri Feb 14, 2014 4:44 am
by a_bertrand
if you want to query all users, you don't put a condition ;)

Code: Select all

select * from users

Re: how to get the HP to refresh the actual numbers

Posted: Fri Feb 14, 2014 5:04 am
by KyleMassacre
a_bertrand wrote:if you want to query all users, you don't put a condition ;)

Code: Select all

select * from users
Well in my defense it was a tricky question. Did he want all the users or all the users info?
Kal wrote: How do I select all user from the database? I tried the * Sign for: where user_id =?",*)
Since he did have the condition I just went with that ;) Now that's neither her nor there But to answer you Kal, if you want all users information then don't use WHERE. if you want all information for a specific user then use WHERE

Re: how to get the HP to refresh the actual numbers

Posted: Wed Feb 19, 2014 1:28 am
by KaL
Thanks for the help again! I just learned how to use userstat load and save command now. This will come in handy! ;)

Re: how to get the HP to refresh the actual numbers

Posted: Wed Feb 19, 2014 5:13 am
by a_bertrand
the user stats should load and save automatically. You normally don't need to call those functions. What are you doing?

Re: how to get the HP to refresh the actual numbers

Posted: Wed Feb 19, 2014 5:00 pm
by KaL
I''m trying to build a module that will reduce all players HP every hour even if they are offline. This will then make all the item food in the game more unique. But i can't seem to get the cronjobs (host provider) to run it. I got it to work using the cron engine to run it daily= daily_cron.php. Is there something i'm missing?