Mod Harvest

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • Mod Harvest

      Help me deal with these modes ?(
      Images
      • Безымянный.jpg

        105.73 kB, 768×368, viewed 132 times

      The post was edited 2 times, last by Coswars ().

    • PHP Source Code

      1. <?php
      2. class ShowHarvestPage extends AbstractGamePage {
      3. public static $requireModule = 0;
      4. var $HarvestPrice = array(1=>500,3=>1000,6=>2000, 15=>4000); // (weeks => price dm)
      5. function __construct() {
      6. parent::__construct();
      7. }
      8. function show() {
      9. global $CONF, $LNG, $PLANET, $USER, $resource, $UNI;
      10. $db = Database::get();
      11. if($USER['harvest_delay'] < TIMESTAMP - 24*60*60){
      12. if($USER['harvest_time'] < 5){
      13. $time = TIMESTAMP;
      14. $db->update("UPDATE `uni1_users` SET `harvest_time` = 5, `harvest_delay` = ".$time." where `id` = ".$USER['id'].";");
      15. $this->printMessage("Whe are setting back your harvest counters to 5.", true, array('game.php?page=harvest', 2));
      16. die();
      17. } else{
      18. $time = TIMESTAMP;
      19. $db->update("UPDATE `uni1_users` SET `harvest_delay` = ".$time." where `id` = ".$USER['id'].";");
      20. $this->printMessage("Loading your data.", true, array('game.php?page=harvest', 2));
      21. die();
      22. }
      23. }
      24. if(!empty($USER['urlaubs_modus'])){
      25. $this->printMessage("You can't access this page while you are in V mode!", true, array('game.php?page=overview', 2));
      26. die();
      27. }
      28. if($_POST){
      29. $mode = HTTP::_GP('con', '');
      30. switch($mode){
      31. case 'extra':
      32. $take = HTTP::_GP('buy',0);
      33. if(!array_key_exists($take,$this->HarvestPrice)){
      34. $this->printMessage("Invalid Option", true, array('?page=Harvest', 3));
      35. }else{
      36. //option is ok . go forward
      37. //enough dm ?
      38. if($USER['darkmatter'] < $this->HarvestPrice[$take]){
      39. $this->printMessage("Not enough DM", true, array('?page=Harvest', 3));
      40. die();
      41. }
      42. $USER['darkmatter'] -= $this->HarvestPrice[$take];
      43. $db->update("UPDATE %%USERS%% SET `harvest_time` = `harvest_time` + ".($take)." WHERE `id` = ".$USER['id']." ; ");
      44. $this->printMessage("You have bought ".$take." Harvest Points", true, array('?page=Harvest', 3));
      45. die();
      46. }
      47. break;
      48. case 'gather':
      49. if($USER['harvest_time'] == 0 ){
      50. $this->printMessage("No Harvest Points Left!", true, array('game.php?page=Harvest', 2));
      51. die();
      52. }
      53. if (!isset($_POST['check_planet']) && !isset($_POST['check_moons']))
      54. $this->redirectTo('game.php?page=harvest');
      55. if(!isset($_POST['check_planet']))
      56. $_POST['check_planet'] = array();
      57. foreach($_POST['check_planet'] as $ID => $Value) {
      58. $sur = $db->select("SELECT id, metal, crystal, deuterium FROM %%PLANETS%% where `id` = '".$Value."';");
      59. $db->nativeQuery("LOCK TABLE %%PLANETS%% WRITE; UPDATE %%PLANETS%% SET `metal` = metal - ".$sur['metal'].", `crystal` = crystal - ".$sur['crystal'].", `deuterium` = deuterium - ".$sur['deuterium']." WHERE `id` = '".$Value."'; UNLOCK TABLES;");
      60. $PLANET['metal'] += $sur['metal'];
      61. $PLANET['crystal'] += $sur['crystal'];
      62. $PLANET['deuterium'] += $sur['deuterium'];
      63. }
      64. if(!isset($_POST['check_moons']))
      65. $_POST['check_moons'] = array();
      66. foreach($_POST['check_moons'] as $ID => $Value) {
      67. $surr = $db->select("SELECT metal, crystal, deuterium FROM %%PLANETS%% where `id` = '".$Value."';");
      68. $db->nativeQuery("LOCK TABLE %%PLANETS%% WRITE; UPDATE %%PLANETS%% SET `metal` = metal - ".$surr['metal'].", `crystal` = crystal - ".$surr['crystal'].", `deuterium` = deuterium - ".$surr['deuterium']." WHERE `id` = '".$Value."'; UNLOCK TABLES;");
      69. $PLANET['metal'] += $surr['metal'];
      70. $PLANET['crystal'] += $surr['crystal'];
      71. $PLANET['deuterium'] += $surr['deuterium'];
      72. }
      73. $db->update("UPDATE %%USERS%% SET `harvest_time` = `harvest_time` - 1 where `id` = '".$USER['id']."';");
      74. $this->printMessage($LNG['h_ok'], true, array('game.php?page=harvest', 4));
      75. break;
      76. }
      77. }
      78. $Planets= array();
      79. $Moons = array();
      80. if (isset($USER['PLANETS'])) {
      81. $USER['PLANETS'] = getPlanets($USER);
      82. }
      83. foreach($USER['PLANETS'] as $ID => $PlanetQuery) {
      84. if ($ID == $PLANET['id']) continue;
      85. if ($PlanetQuery['planet_type'] == 3) {
      86. $Moons[$PlanetQuery['id']] = " [" . $PlanetQuery['galaxy'] . ":" . $PlanetQuery['system'] . ":" . $PlanetQuery['planet'] . "]";
      87. } elseif ($PlanetQuery['planet_type'] == 1) {
      88. $Planets[$PlanetQuery['id']] = " [".$PlanetQuery['galaxy'] . ":" . $PlanetQuery['system'] . ":" . $PlanetQuery['planet'] . "]";
      89. }
      90. }
      91. $this->tplObj->loadscript("jquery.countdown.js");
      92. $this->tplObj->assign_vars(array(
      93. 'prices' => $this->HarvestPrice,
      94. 'PlanetsList'=> $Planets,
      95. 'MoonsList'=> $Moons,
      96. 'harvest'=> $USER['harvest_time'],
      97. 'p_state' => $USER['harvest_time'],
      98. 'p_delay' => ((($USER['harvest_delay']+24*60*60) < TIMESTAMP) ? true : (($USER['harvest_delay']+24*60*60) - TIMESTAMP)),
      99. ));
      100. $this->display('page.harvest.default.tpl');
      101. }
      102. }
      103. ?>
      Display All

      The post was edited 1 time, last by Coswars ().

    • Help with teleportation gives an error



      NOTICE
      Message: Undefined index: metal
      File: /includes/pages/game/ShowHarvestPage.class.php
      Line: 70
      URL: coswars.space/game.php?page=Harvest
      PHP-Version: 5.6.35
      PHP-API: litespeed
      2Moons Version: 2.0.git
      Debug Backtrace:
      #0 /includes/pages/game/ShowHarvestPage.class.php(70): errorHandler(8, 'Undefined index...', 'FILEPATH ...', 70, Array)
      #1 /game.php(57): ShowHarvestPage->show()
      #2 {main}
    • Check the data you return the on $sur

      I have made a personal available anywhere is it works very well for resources and for the fleet
      I remain at your disposal on the forum for any questions or help.

      A help is of course not a creation of a mod



      -------------------------------------------------------
      Spaccon
      • Uni Xterium Comming Soon
      • Uni Ogame Comming Soon
    • No there is not
      I remain at your disposal on the forum for any questions or help.

      A help is of course not a creation of a mod



      -------------------------------------------------------
      Spaccon
      • Uni Xterium Comming Soon
      • Uni Ogame Comming Soon
    • New

      Coswars wrote:

      I have the same problem


      I change SQL %%PLANETS%% to uni1_planets
      $sur = $db->select("SELECT id, metal, crystal, deuterium FROM `uni1_planets` where `id` = '".$Value."';");


      $sur['metal'] Undefined index: metal




      Does anyone have advice?





      NOTICE
      Message: Undefined index: metalFile: /includes/pages/game/ShowHarvestPage.class.php
      Line: 70
      URL: coswars.space/game.php?page=Harvest
      PHP-Version: 5.6.35
      PHP-API: litespeed
      2Moons Version: 2.0.git
      Debug Backtrace:
      #0 /includes/pages/game/ShowHarvestPage.class.php(70): errorHandler(8, 'Undefined index...', 'FILEPATH ...', 70, Array)
      #1 /game.php(57): ShowHarvestPage->show()
      #2 {main}

    • New

      This will work.

      Source Code

      1. private function HarvestResources($Harvest) {
      2. global $USER, $PLANET, $resource, $pricelist, $LNG;
      3. /**/ // Attack
      4. $AttackCount = Database::get()->selectSingle("SELECT COUNT(*) as count FROM %%FLEETS%% WHERE fleet_target_owner = :id AND (fleet_mission = 1 OR fleet_mission = 2 OR fleet_mission = 9) AND fleet_start_time > :timestamp;", array(
      5. ':id' => $USER['id'],
      6. ':timestamp' => TIMESTAMP,
      7. ), 'count');
      8. if ($AttackCount > 0)
      9. {
      10. $this->printMessage('While under foreign enemy activity, you can not use this function', array(
      11. array(
      12. 'label' => $LNG['sys_back'],
      13. 'url' => 'game.php?page=imperium'
      14. )
      15. ));
      16. }
      17. if ($Harvest == 1) // All
      18. {
      19. $TakeFrom = "";
      20. }
      21. elseif ($Harvest == 2) // Planets only
      22. {
      23. $TakeFrom = "planet_type = '1' AND";
      24. }
      25. elseif ($Harvest == 3) // Planets only
      26. {
      27. $TakeFrom = "planet_type = '3' AND";
      28. }
      29. elseif ($Harvest == 4) // Megastructures only
      30. {
      31. $TakeFrom = "planet_type > '3' AND";
      32. }
      33. $SelectedPlanets = Database::get()->select("SELECT * FROM %%PLANETS%% WHERE " . $TakeFrom . " id_owner = :id_owner AND id != :id;", array(
      34. ':id_owner' => $USER['id'],
      35. ':id' => $PLANET['id'],
      36. ));
      37. foreach ($SelectedPlanets as $CPLANET) {
      38. $planetUpdater = new ResourceUpdate();
      39. list($USER, $CPLANET) = $planetUpdater->CalcResource($USER, $CPLANET);
      40. }
      41. $TotalResourceSQL = "SELECT SUM(metal) as metal, SUM(crystal) as crystal,SUM(deuterium) as deuterium FROM %%PLANETS%% WHERE " . $TakeFrom . " id_owner = :id_owner AND id != :id ;";
      42. $Resource = Database::get()->selectSingle($TotalResourceSQL, array(
      43. ':id_owner' => $USER['id'],
      44. ':id' => $PLANET['id'],
      45. ));
      46. $PLANET[$resource[901]] += $Resource['metal'];
      47. $PLANET[$resource[902]] += $Resource['crystal'];
      48. $PLANET[$resource[903]] += $Resource['deuterium'];
      49. Database::get()->update("UPDATE %%PLANETS%% SET metal = 0, crystal = 0, deuterium = 0 WHERE " . $TakeFrom . " id_owner = :id_owner AND id != :id ;", array(
      50. ':id_owner' => $USER['id'],
      51. ':id' => $PLANET['id'],
      52. ));
      53. $this->printMessage($LNG['err_imperium_hr_success'], array(
      54. array(
      55. 'label' => $LNG['sys_back'],
      56. 'url' => 'game.php?page=imperium'
      57. )
      58. ));
      59. }
      Display All



      after global on function show

      Source Code

      1. $Harvest = HTTP::_GP('harvest', '');
      2. if (!empty($Harvest) && $_SERVER['REQUEST_METHOD'] === 'POST' && $USER['urlaubs_modus'] == 0) {
      3. $this->HarvestResources($Harvest);
      4. }
      5. /* ....... */
      6. $ResourcesToHarvest = array(
      7. 0 => array(
      8. 901 => 0,
      9. 902 => 0,
      10. 903 => 0
      11. ) ,
      12. 1 => array(
      13. 901 => 0,
      14. 902 => 0,
      15. 903 => 0
      16. ) ,
      17. 3 => array(
      18. 901 => 0,
      19. 902 => 0,
      20. 903 => 0
      21. ) ,
      22. 4 => array(
      23. 901 => 0,
      24. 902 => 0,
      25. 903 => 0
      26. ) ,
      27. );
      28. // Harvester
      29. $ResourcesToHarvest[0][901] += $CPLANET[$resource[901]];
      30. $ResourcesToHarvest[0][902] += $CPLANET[$resource[902]];
      31. $ResourcesToHarvest[0][903] += $CPLANET[$resource[903]];
      32. if ($CPLANET['planet_type'] == 1) {
      33. $ResourcesToHarvest[1][901] += $CPLANET[$resource[901]];
      34. $ResourcesToHarvest[1][902] += $CPLANET[$resource[902]];
      35. $ResourcesToHarvest[1][903] += $CPLANET[$resource[903]];
      36. }
      37. elseif ($CPLANET['planet_type'] == 3) {
      38. $ResourcesToHarvest[3][901] += $CPLANET[$resource[901]];
      39. $ResourcesToHarvest[3][902] += $CPLANET[$resource[902]];
      40. $ResourcesToHarvest[3][903] += $CPLANET[$resource[903]];
      41. }
      42. elseif ($CPLANET['planet_type'] > 3) {
      43. $ResourcesToHarvest[4][901] += $CPLANET[$resource[901]];
      44. $ResourcesToHarvest[4][902] += $CPLANET[$resource[902]];
      45. $ResourcesToHarvest[4][903] += $CPLANET[$resource[903]];
      46. }
      47. /*....*/
      48. $this->assign(array(
      49. /*....*
      50. 'ResourcesToHarvest' => $ResourcesToHarvest,
      Display All

      TPL

      Source Code

      1. <table class="table table-dark">
      2. <form action="game.php?page=imperium" method="post" >
      3. <thead>
      4. <tr>
      5. <th></th>
      6. <th>{$LNG.cr_type}</th>
      7. <th>{$LNG.tech.901}</th>
      8. <th>{$LNG.tech.902}</th>
      9. <th>{$LNG.tech.903}</th>
      10. </tr>
      11. </thead>
      12. <tbody>
      13. <tr>
      14. <th scope="row"><input name="harvest" id="type0" type="radio" value="1" checked="checked"></th>
      15. <th scope="row">All</th>
      16. <td>{$ResourcesToHarvest.0.901|number}</td>
      17. <td>{$ResourcesToHarvest.0.902|number}</td>
      18. <td>{$ResourcesToHarvest.0.903|number}</td>
      19. </tr>
      20. <tr>
      21. <th scope="row"><input name="harvest" id="type1" type="radio" value="2"></th>
      22. <th scope="row">{$LNG.type_planet_1}</th>
      23. <td>{$ResourcesToHarvest.1.901|number}</td>
      24. <td>{$ResourcesToHarvest.1.902|number}</td>
      25. <td>{$ResourcesToHarvest.1.903|number}</td>
      26. </tr>
      27. <tr>
      28. <th scope="row"><input name="harvest" id="type3" type="radio" value="3"></th>
      29. <th scope="row">{$LNG.type_planet_3}</th>
      30. <td>{$ResourcesToHarvest.3.901|number}</td>
      31. <td>{$ResourcesToHarvest.3.902|number}</td>
      32. <td>{$ResourcesToHarvest.3.903|number}</td>
      33. </tr>
      34. <tr>
      35. <th scope="row"><input name="harvest" id="type4" type="radio" value="4"></th>
      36. <th scope="row">{$LNG.type_planet_short_0}</th>
      37. <td>{$ResourcesToHarvest.4.901|number}</td>
      38. <td>{$ResourcesToHarvest.4.902|number}</td>
      39. <td>{$ResourcesToHarvest.4.903|number}</td>
      40. </tr>
      41. <tr>
      42. <td colspan="5"><button type="submit" class="btn btn-xs btn-primary col-12">{$LNG.gl_collect}</button></td>
      43. </tr>
      44. </tbody>
      45. </form>
      46. </table>
      Display All

      This was posted in rush and it's adapted for my game needs. I won't support but this works if you simply copy-paste it.
      Looking for good VPS to host your game? Use DigitalOcean and get 10$ bonus credit!

      Private project - stellaron.space
    • New

      some call 2moons 1.8 others 1.9 and others 2. They are all the same in the code so it works with 2moons in general
      Looking for good VPS to host your game? Use DigitalOcean and get 10$ bonus credit!

      Private project - stellaron.space
    • New

      Hello there,
      I solved my problem.

      İs the code
      $surr = $db->selects("SELECT metal, crystal, deuterium FROM %%PLANETS%% where `id` = '".$Value."';");

      i change the code
      $surr = $db->selectsingle("SELECT metal, crystal, deuterium FROM %%PLANETS%% where `id` = '".$Value."';");

      I m using 2moons 1.9
    • New

      $db->nativeQuery("LOCK TABLE %%PLANETS%% WRITE; UPDATE %%PLANETS%% SET `metal` = metal - ".$surr['metal'].", `crystal` = crystal - ".$surr['crystal'].", `deuterium` = deuterium - ".$surr['deuterium']." WHERE `id` = '".$Value."'; UNLOCK TABLES;");


      What to do with these lines
    • New

      Nothing.

      Hellvodoo wrote:

      $db->nativeQuery("LOCK TABLE %%PLANETS%% WRITE; UPDATE %%PLANETS%% SET `metal` = metal - ".$surr['metal'].", `crystal` = crystal - ".$surr['crystal'].", `deuterium` = deuterium - ".$surr['deuterium']." WHERE `id` = '".$Value."'; UNLOCK TABLES;");


      What to do with these lines