Join the forums now, and start posting to receive access to our Scripts Vault!
everythink you need , is a function which update your last_login of your user in the database. so if you know how long wasnt the user online and what happened in this time, you can calculate everythink and update everythink if he comes back
$query = mysql_query("SELECT * FROM unit_movement WHERE arrival =< 'NOW()'") or die (mysql_error());while ($row = mysql_fetch_assoc($query)){ $action = $row['action']; switch ($action) { case attack: //run attack script case trade: //run trade script }}
hm.. i wouldnt now use the Now() function of SQL... if you have 1 million + inserts in the tabel unit_movement your Database would crash, calculate the time in PHP and use it instead of Now function
"SELECT * FROM events WHERE event_end BETWEEN $users_last_action AND $now AND user_id = $loggedinuser"...foreach($events as $event){switch eventsincrease or decrese somethinkmark event ids which need to be deleted or delete events which you already calculated}
Quote from: BlackScorp on May 25, 2011, 07:54:38 AMeverythink you need , is a function which update your last_login of your user in the database. so if you know how long wasnt the user online and what happened in this time, you can calculate everythink and update everythink if he comes backI also thought about that, but then this can happen.Another player attacks you while you aren't there and destroys your cropfield 1 level.. what now?Of a player robs your village while you aren't there, so he can only steal what was there once you last logged in?Example (assume 1 hours = 1 extra food):- I have 2 food when I log out...- After 10 hours I should have 12 food..- I get attacked after 10 hours, and the attacker can only steal 2 food (instead of 12), so he steals 2 food- This means that when I log back in after 20 hours... my food stock is 20 instead of 10Is this how it works in professional games? To be honnest, I'm not sure...
us = new User('A');us -> update_activity();us -> regenerate_things();
us = new User('B');us -> update_activity();us -> regenerate_things();them = new User('A');them -> regenerate_things();/* perform attack knowing everything is up-to-date */
FutureLost is right. Only update when there is interaction with the player.The code will be harder to figure out tough, but it's do able and way less server consuming.Another way is to update the DB everytime someone connects to the DB (any player), but that's again fairly server consuming.I just contacted the maker of "illyriad", asking how his mechanic works.Once he answers I'll post it here.EDIT: He doesn't respond, looks like they like to keep their secrets (which I totally understand)