Advertisement
EyesOfAHawk

getguildid.c

Dec 6th, 2017
146
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //===== Hercules Plugin ======================================
  2. //= BUILDIN(getguildid)
  3. //===== By ===================================================
  4. //= Wolfie of BlackoutRO (http://blackout-ro.net)
  5. //===== Version ==============================================
  6. //= 1.0 - December 7, 2017
  7. //===== Description ==========================================
  8. //= Gives your server the 'getguildid' script command.
  9. //  Usage:
  10. //      .@Guild$ = "My Guild";
  11. //      .@GID = getguild(.@Guild$);
  12. //      mesf("The GID of %s is %d.", .@Guild$, .@GID);
  13. //
  14. //  This example will give a message box saying,
  15. //  'The GID of My Guild is X.' (where x = the actual GID)
  16. //============================================================
  17.  
  18. #include "common/hercules.h" /* Should always be the first Hercules file included! (if you don't make it first, you won't be able to use interfaces) */
  19.  
  20. #include "map/guild.h"
  21. #include "map/script.h"
  22.  
  23. #include "common/HPMDataCheck.h" /* should always be the last Hercules file included! (if you don't make it last, it'll intentionally break compile time) */
  24.  
  25. HPExport struct hplugin_info pinfo = {
  26.     "BUILDIN(getguildid)",    // Plugin name
  27.     SERVER_TYPE_MAP,// Which server types this plugin works with?
  28.     "1.0",       // Plugin version
  29.     HPM_VERSION, // HPM Version (don't change, macro is automatically updated)
  30. };
  31.  
  32. /*==========================================
  33.  * getguildid("<Guild Name>")
  34.  * Returns the Guild ID from the provided
  35.  * guild name.
  36.  * Will return -1 if the guild does not
  37.  * exist.
  38.  *=========================================*/
  39.  
  40. BUILDIN(getguildid)
  41. {
  42.     struct guild *g = NULL;
  43.     char guild_name[NAME_LENGTH];
  44.     sprintf(guild_name, "%s", script_getstr(st, 2));
  45.  
  46.     if ((g = guild->searchname(guild_name)) == NULL) {
  47.         script_pushint(st, -1);
  48.         return true;
  49.     }
  50.  
  51.     script_pushint(st, g->guild_id);
  52.     return true;
  53. }
  54.  
  55. /* run when server starts */
  56. HPExport void plugin_init (void)
  57. {
  58.     // Atcommands only make sense on the map server
  59.     if (SERVER_TYPE == SERVER_TYPE_MAP) {
  60.         addScriptCommand("getguildid", "s", getguildid);
  61.     }
  62. }
Advertisement
RAW Paste Data Copied
Advertisement