how to get the HP to refresh the actual numbers

General Chat, Comments
Post Reply
KaL
Posts: 344
Joined: Mon Jan 13, 2014 5:44 am

how to get the HP to refresh the actual numbers

Post 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);
}
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

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

Post 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
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

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

Post 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
KaL
Posts: 344
Joined: Mon Jan 13, 2014 5:44 am

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

Post 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?
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

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

Post 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.
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

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

Post by a_bertrand »

if you want to query all users, you don't put a condition ;)

Code: Select all

select * from users
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
KyleMassacre
Posts: 573
Joined: Wed Nov 27, 2013 12:42 pm

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

Post 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
KaL
Posts: 344
Joined: Mon Jan 13, 2014 5:44 am

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

Post by KaL »

Thanks for the help again! I just learned how to use userstat load and save command now. This will come in handy! ;)
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

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

Post by a_bertrand »

the user stats should load and save automatically. You normally don't need to call those functions. What are you doing?
Creator of Dot World Maker
Mad programmer and annoying composer
KaL
Posts: 344
Joined: Mon Jan 13, 2014 5:44 am

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

Post 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?
Post Reply

Return to “General”