Well, i've always heard many people disagress about using eval'd due to potential exploits can bring to your code, but if you know how to use it, I believe there are no problems.
I have serious problems on keeping my code beautiful, I hate ton of foreaches and endless lines just to express a few things, so I decided to make a mission system, that includes tutorial or another interesting grinding quests (such Destroy X from achievements) that may interest you.
Is that safe? Yes.
So how does it work?
Add these lines in ShowOverviewPage.class.php before the $this->assign
Display All
Then you'll need to add the following piece of TPL. Adapt for your game since this is strict copy-paste from mine.
Display All
We are not finished. Now we need to run the following query:
Display All
The missions are on the SQL file I'll upload here. I can't upload as .sql extension, so it goes as .txt.
The column "reward" is to multiply the current user production * hours as resource reward. The resource921 is in case you want to give him dark matter.
The column "class" is in case you want to create quests with progress.
The column "grind" is in case you want to create a mission like "Destroy X resources" and when user achieves, has do destroy another X. You can see the demo file in "Warmonger.txt" as mission to destroy X ships.
To end, this is the template, if you want to create new missions, that goes to the "code" box.
You can add as much requirements as you want, aswell missions, it's a huge and good alternative to my very old and classic Achievements system. This template is experimental, requirements goes to the 'req' associative from $A, $B, $C ... $Z array. Want to add a requirement? Simply copypaste $C and replace to $D, etc.
Display All
I have serious problems on keeping my code beautiful, I hate ton of foreaches and endless lines just to express a few things, so I decided to make a mission system, that includes tutorial or another interesting grinding quests (such Destroy X from achievements) that may interest you.
Is that safe? Yes.
- I presume only you have access to your database?
- There are not any forms
- You can first import to the database to check the missions if you think this is untrusted, then change the files.
So how does it work?
Add these lines in ShowOverviewPage.class.php before the $this->assign
PHP Source Code: ShowOverviewPage.class.php
- // /**/ Missions category
- $Quests = array();
- // /*
- if(!isset($USER['mission']) || is_null($USER['mission']) || empty($USER['mission'])){
- $UserMission = array();
- }else{
- $UserMission = unserialize($USER['mission']);
- }
- $Quest = Database::get()->select("SELECT DISTINCT class, grind FROM uni1_missions ORDER BY priority ASC;", array());
- foreach($Quest as $Row){
- if(!array_key_exists($Row['class'], $UserMission)){
- $UserMission[$Row['class']] = 1;
- }
- // Only unlock additional missions after finish tutorial
- $MissionTracker = $Row['grind'] == 1 ? $Row['class'].'_'.$UserMission[$Row['class']] : $Row['class'];
- // Current Mission
- $Mission = Database::get()->selectSingle("SELECT * FROM uni1_missions where id = :mission;", array(':mission' => $MissionTracker));
- // Has mission ended?
- if(!isset($Mission) || empty($Mission)) continue;
- eval($Mission['code']);
- $Quests[] = array(
- 'tracker' => $MissionTracker,
- 'grind' => $Mission['grind'],
- 'id' => $Mission['id'],
- 'class' => $Mission['class'],
- 'requirements' => isset($Requirements) ? $Requirements : NULL,
- );
- }
- // */
- // /**/ Missions category
- /* add this to $this->assign */
- 'Quests' => $Quests,
Then you'll need to add the following piece of TPL. Adapt for your game since this is strict copy-paste from mine.
HTML Source Code: page.overview.default.tpl
- <table class="table table-dark">
- {foreach $Quests as $Row}
- <tr>
- <td style="text-align:left;">
- <b>{$LNG["mission_{$Row.class}"]}</b>{if $Row.grind == 1}: {$LNG["mission_{$Row.id}"]}{/if}
- <p>{$LNG["mission_{$Row.id}_desc"]}
- {foreach $Row.requirements as $K => $C}<br>{if $C.locked != 0}<i class="fa fa-check" style="color:lime"></i>{else}<i class="fa fa-times" style="color:red"></i>{/if} {$C.text}{/foreach}
- {if isset($LNG["mission_{$Row.tracker}_0"])}<br> <i class="fa fa-question-circle-o" style="color:orange"></i> <a href="#" class="tooltip" data-tooltip-content='{$LNG["mission_{$Row.tracker}_0"]}'>Tips & Help</a>{/if}
- </td>
- </tr>
- {/foreach}
- </table>
SQL-Query
- ALTER TABLE uni1_users ADD `mission` text NULL;
- CREATE TABLE `uni1_missions` (
- `id` varchar(64) NOT NULL,
- `class` varchar(64) NOT NULL,
- `reward901` int(11) DEFAULT '0',
- `reward902` int(11) DEFAULT '0',
- `reward903` int(11) DEFAULT '0',
- `reward921` int(11) DEFAULT '0',
- `code` text,
- `grind` int(11) NOT NULL DEFAULT '1',
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
The missions are on the SQL file I'll upload here. I can't upload as .sql extension, so it goes as .txt.
The column "reward" is to multiply the current user production * hours as resource reward. The resource921 is in case you want to give him dark matter.
The column "class" is in case you want to create quests with progress.
The column "grind" is in case you want to create a mission like "Destroy X resources" and when user achieves, has do destroy another X. You can see the demo file in "Warmonger.txt" as mission to destroy X ships.
To end, this is the template, if you want to create new missions, that goes to the "code" box.
You can add as much requirements as you want, aswell missions, it's a huge and good alternative to my very old and classic Achievements system. This template is experimental, requirements goes to the 'req' associative from $A, $B, $C ... $Z array. Want to add a requirement? Simply copypaste $C and replace to $D, etc.
Source Code
- $A = array('req' => Database::get()->selectSingle("SELECT COUNT(*) FROM %%PLANETS%% WHERE planet_type = '1' AND id_owner = ".$USER['id'].";")['COUNT(*)'], 'value' => 10);
- $B = array('req' => $USER['computer_tech'], 'value' => 10);
- $C = array('req' => $PLANET['metal_mine'], 'value' => 10);
- $Requirements = array(
- $A['req'] >= $A['value'] ? 1 : 0,
- $B['req'] >= $B['value'] ? 1 : 0,
- $C['req'] >= $C['value'] ? 1 : 0,
- );
- if(count($Requirements) == array_sum($Requirements)){
- $PLANET[$resource[901]] += $MetalProduction * $Mission['reward901'];
- $PLANET[$resource[902]] += $CrystalProduction * $Mission['reward902'];
- $PLANET[$resource[903]] += $DeuteriumProduction * $Mission['reward903'];
- $USER[$resource[921]] += $Mission['reward921'];
- $UserMission[$Row['class']] += 1;
- Database::get()->update("UPDATE %%USERS%% SET mission = :missions WHERE id = :id;", array(':missions' => serialize($UserMission), ':id' => $USER['id']));
- }
- $Requirements = array(
- 1 => array('locked' => $A['req'] >= $A['value'] ? 1 : 0, 'text' => sprintf($LNG['mission_'.$MissionTracker.'_1'], $A['value'])),
- 2 => array('locked' => $B['req'] >= $B['value'] ? 1 : 0, 'text' => sprintf($LNG['mission_'.$MissionTracker.'_2'], $B['value'])),
- 3 => array('locked' => $C['req'] >= $C['value'] ? 1 : 0, 'text' => sprintf($LNG['mission_'.$MissionTracker.'_3'], $C['value'])),
- );
The post was edited 2 times, last by Qwa ().