Zeggy Posted February 21, 2010 Share Posted February 21, 2010 Introduction Modules are located in the sub-folder /modules. Almost everything you see on ezRPG is a module - login, register, logout, members list, account settings, etc. You can see the most basic code for a module in /modules/skeleton.php: defined('IN_EZRPG') or exit; class Module_Skeleton extends Base_Module { public function start() { requireLogin(); } } This is probably the best place to start whenever you write a new module - just copy the code in skeleton.php and work from there. Rules There are some rules that you need to follow when writing modules for them to integrate properly with ezRPG: Modules go in their own /modules/ModuleName sub-folder. Always. Admin modules go in the /admin/ModuleName sub-folder. Module class names must begin with the Module_ prefix, followed by the module name. Modules are accessed by their class name, minus the Module_prefix. For example, Module_Blabla will be accessed throughindex.php?mod=Blabla. Modules must extend the Base_Module class in order to access database, template and player objects. Modules must have a public start() method. This is the method that will be called when your module is viewd by a player. Class Variables In every module, there are three class variables available to you, as well as global functions and constants: $this->db - This is the database object. Check out the documentation for the database class to see what kind of stuff you can do! Example of writing a database query: //Count the number of players $result = $this->db->fetchRow('SELECT COUNT(`id`) AS `count` FROM `players`'); echo $result->count; //Display the result $this->tpl - This is the smarty template object. Check out the included modules to see how you can display templates or assign variables! For example, to display a template you can use $this->tpl->display('example.tpl');. $this->player - This is the player object. It contains all player data as class variables. For example, to access the player's username, you can use $this->player->username;. Other Files If you add template files, they belong in /smarty/templates. If you are adding many template files for your mod, you can place them in their own sub-folder. If you add files like images or CSS stylesheets, they belong in /static. If you want to add your own global functions, place the files in /lib. After they have been put in the lib folder, you can add an include to that file in /init.php and it will be included globally in the game. Examples For examples of how real modules are used, check out the source code! All the modules included in ezRPG are completely usable, and demonstrate different ways of writing different types of modules. Quote Link to comment Share on other sites More sharing options...
JesterC Posted March 20, 2010 Share Posted March 20, 2010 Very nice, Im workin on some stuff atm :) Quote Link to comment Share on other sites More sharing options...
Zeggy Posted March 20, 2010 Author Share Posted March 20, 2010 Awesome! :) Have you checked out the wiki yet? It's got some more info that you might find useful: http://code.google.com/p/ezrpg/wiki/GettingStarted If you've got any questions, just ask! Quote Link to comment Share on other sites More sharing options...
JesterC Posted March 20, 2010 Share Posted March 20, 2010 How would you call a hook in the TPL file? Can you? This would make it easier to display $msg. Can you use Javascript in TPL files? How would you do mysql_fetch_assoc() in $db? Quote Link to comment Share on other sites More sharing options...
Djkanna Posted March 20, 2010 Share Posted March 20, 2010 "How would you do mysql_fetch_assoc() in $db?" I think it's $this->db->fetch() As for hook in tpl file I would assume you'd use {$var} Quote Link to comment Share on other sites More sharing options...
Zeggy Posted March 20, 2010 Author Share Posted March 20, 2010 How would you call a hook in the TPL file? Can you? This would make it easier to display $msg. Sorry, hooks aren't available in template files. To use $msg to display messages to the user, you can either redirect to the same url with &msg=text. Or you can manually set the template variable GET_MSG. Header redirects are used throughout ezrpg, mostly for security, to stop repeat refreshes and accidental refreshes. Can you use Javascript in TPL files? Yes, you can use javascript in template files. How would you do mysql_fetch_assoc() in $db? The fetch function uses mysql_fetch_object by default. Is there any reason why you want an array result set instead? I could add it to the class in the next release if you want. Quote Link to comment Share on other sites More sharing options...
JesterC Posted March 20, 2010 Share Posted March 20, 2010 Thanks, A little extra work doesn't hurt when you want security. :) 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.