Jump to content
MakeWebGames

The problem with hooks


Sim

Recommended Posts

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).

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...