Jump to content
MakeWebGames

Main Engine Modication - Access any Module Function


Recommended Posts

Posted

OPEN:

class/modules

Around line 5, find: or something similar.

public $alerts = array(), $html = '', $page, $user, $db, $methodData, $construct = true, $_settings;

ADD at end of line 

$mods = array();

To create this:

public $alerts = array(), $html = '', $page, $user, $db, $methodData, $construct = true, $_settings, $mods = array();

Around line 25, find:

$this->buildMethodData();

Add this after:

$this->loadModuleFunctions();

 

At end of file, find:

    	
    }
?>

 

Add this function, method before

        
  public function loadModuleFunctions()
  {
 $moduleDirectories = scandir("modules/installed/");
        
      /* Load modules first */
      foreach ($moduleDirectories as $moduleName) 
      {
          if ($moduleName[0] == ".") continue;
          
          $moduleIncFile = "modules/installed/" . $moduleName . "/" . $moduleName . ".inc.php";
          $moduleAcpDile = "modules/installed/" . $moduleName . "/" . $moduleName . ".admin.php";
          
          if (file_exists($moduleIncFile)) {
              include $moduleIncFile;
              $this->mod[$moduleName] = new $moduleName();
          }
      } 
  }
        	

 

And now you can acess any function, method from any module in any  module.

Examples:

$this->mods["crimes"]->method_commit(); //will commit crime If proper Crime ID is set in crime={ID} in url

$this->mods["jail"]->getJailUsers(); return's list of users in jail based upon player location

$this->mods["travel"]->method_fly(); //move player to location if location ID is set in ex url ?page=punchMod&action=punch&user=1ocation=2

So the last one, as you can see the only way to use the majority of functions from other modules is by adding the GET variable (s) associated with the module functions you wish to use.

 

Since I am heavily moding GL, I been changing the functions to pass a paramater instead of using GET variables. This small core code for is a great addition to interact with other modules. 

@Dayo you should include this in the next update or your own version of it.

  • Like 3
Posted

here a way of accessing functions (not methods) inside a mod instead of copy posting them in every mod that use it

lets say this is our function

public function get_user($uid){
	return $uid;
}

normaly to use it you have to have it insideur module .inc.php file and use $this->foo

but you can have it inside the .hook.php and the remove the "public" from it should be like this

function get_user($uid){
	return $uid;
}

inside  it use global $db; for databese use ($user, $page ...)

and now u can acces it from any mod in the engine using

echo get_user(1);

if you have lot of functions add a unic name for each function so they stay separated.

  • Like 1
  • Thanks 1
Posted

yes and by the way you can use it like lets say you see {number_format our_number_val} you can have ur costum function in hooks and use it with it

like my cosstum number func it will show short version numbers like 20K instead of 20,000

but it only accept 1 value

function ($our_number_val){
	return ($our_number_val > 999)? short_number($our_number_val) : number_format($our_number_val) ;
}

some think like this

Posted (edited)

I would more lean towards the way @ags_cs4 is doing it but i would go one step further and do it like this:

module.class.php

<?php

	class itemMod extends module {
		
		public function getItems() {
			$this->db->selectAll(" ... ");
		}

	}

module.hooks.php

<?php

	require "./module.class.php";

module.inc.php

<?php

	class moduleName extends module {
        
		public function constructModule() {
			$mod = new itemMod();
			$items = $mod->getItems();
		}
	
	}

 

The benifit of this way is when installing a mod the user does not need to touch code, if at any point the user needs to touch code it is either your mod that is at fault or the engine.

Edited by Dayo
Posted (edited)

saw this idea but wasnt sure how to use it 😄 ty for explaining it,

why not add it to the wiki, i think it said "soon"

------------------------------

inventory.class.php
Line: 2
Error: Class 'module' not found
Type: E_RECOVERABLE_ERROR

got his error 

now im sure this need to be in the wiki 😄 

Edited by ags_cs4
Posted

I would rather not have had to edit any fileto get the item mod to work, but now that I know this i can make proper changes.

Can these functions be used in the admin panel

Posted
4 hours ago, ags_cs4 said:

saw this idea but wasnt sure how to use it 😄 ty for explaining it,

why not add it to the wiki, i think it said "soon"

------------------------------

inventory.class.php Line: 2 Error: Class 'module' not found Type: E_RECOVERABLE_ERROR


inventory.class.php
Line: 2
Error: Class 'module' not found
Type: E_RECOVERABLE_ERROR

got his error 

now im sure this need to be in the wiki 😄 

Ahh it seems i include the module class a t a later point, this is a bug and ill fix it in the next release

 

Posted
4 hours ago, ags_cs4 said:

@Dayo no problem, will be looking forward to that, with the template update ❤️  

Looking forward to what? Did I miss something

Posted
14 hours ago, Sim said:

Looking forward to what? Did I miss something

the module class with some fixes to the template engine, and something is getting made will be very cool for us devs 🤩 

Posted
2 hours ago, ags_cs4 said:

the module class with some fixes to the template engine, and something is getting made will be very cool for us devs 🤩 

It looks like some of my ideas finally paid off. I hope all our mods still work. The templating engine does need some upgrading.

That text of yours finally paid off

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