Sim Posted November 30, 2020 Share Posted November 30, 2020 new Hook("userAction", function ($action) { global $user, $db, $html, $page; global $traveled; $traveled = false; $dropPerc = 50; $dropReward = 2; //$rewardType = "money"; $rewardType = "points"; //$rewardType = "bullets"; if($action["module"] == "travel") { if($action["success"]) { $rand = mt_rand(1,100); if($dropPerc > $rand) { $traveled = true; // var_dump($page); debug(var_dump($html)); debug($dropReward . " " . $rewardType); } debug($action); } } }); So here's the main problem with the hooks system. Altering or displaying extra information into the template or page is not that simple. Adding any of these variations will not work, but should work $page->buildElement('info', array("text" => "You found " . $dropReward . " " . $rewardType . " during your travels")); Or $html .= $page->buildElement('info', array("text" => "You found " . $dropReward . " " . $rewardType . " during your travels")); The first spent even add the display message. The $html .= Displays the message before the whole template as the HTML is empty when the action hook is called. The purpose of this Mod was to reward players for traveling more, but displaying a message when rewarded for traveling is nearly impossible (and just not worth it). Quote Link to comment Share on other sites More sharing options...
Tom V Posted November 30, 2020 Share Posted November 30, 2020 If the purpose is just to reward players for travelling, then why don't you just alter the function method_fly in travel.inc.php and change the alert message? Wouldn't that be a lot less complicated? Quote Link to comment Share on other sites More sharing options...
Sim Posted November 30, 2020 Author Share Posted November 30, 2020 It's alot easier to upload a folder, and if anyone has altered there travel page, no one has to do any editing. Quote Link to comment Share on other sites More sharing options...
ags_cs4 Posted December 1, 2020 Share Posted December 1, 2020 Sim check the github wiki there is a hook that change module template and another for globaltemplate Quote Link to comment Share on other sites More sharing options...
Dayo Posted December 1, 2020 Share Posted December 1, 2020 This isn't a problem with Hooks in general but the fact there is a missing hook. For now why not send the user a notification with what they have found Ill make a modification to v2.3.0 to do $page->alert("Hello", "success"); Quote Link to comment Share on other sites More sharing options...
Sim Posted December 1, 2020 Author Share Posted December 1, 2020 5 hours ago, ags_cs4 said: Sim check the github wiki there is a hook that change module template and another for globaltemplate I'm aware of that hook. To alter the template with this simple modification, I'm having to check if traveled, why the global $traveled is in the userAction hook. Problem with what you mentioned is $traveled is never true in the template hooks. But no one should have to do this. As @Dayo stated something such as $page->alert("type", "text") should be included. Hooks are to to supposed to be make things simplier for the developer to. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.