Advertisement
EyesOfAHawk

getalliance.c

Dec 6th, 2017
154
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. //===== Description ==========================================
  6. //= Gives your server the 'getalliance' script command.
  7. //  Sample Script:
  8. /**************************************
  9.     getalliance(getcharid(CHAR_ID_GUILD));
  10.  
  11.     dispbottom(sprintf("Alliances found: %d", $@guildallycount), 0x00FFFF);
  12.     for (.@i = 0; .@i < $@guildallycount; .@i++)
  13.         dispbottom(sprintf("%d. %s (GID - %d)", (.@i + 1), $@guildallyname$[.@i], $@guildallygid[.@i]), 0x00FFFF);
  14.  
  15.     dispbottom(sprintf("Opposition found: %d", $@guildoppositioncount), 0x00FFFF);
  16.     for (.@i = 0; .@i < $@guildoppositioncount; .@i++)
  17.         dispbottom(sprintf("%d. %s (GID - %d)", (.@i + 1), $@guildoppositionname$[.@i], $@guildoppositiongid[.@i]), 0x00FFFF);
  18.     end;
  19. **************************************/
  20. //  This sample script will send a message to the invoked
  21. //  player's chat informing them of how many allies and
  22. //  oppositions they have, as well as their name(s) and GID(s).
  23. //===== Comments =============================================
  24. //= Read below to find the 'documentation' of the script
  25. //  command which explains it better.
  26. //============================================================
  27.  
  28. #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) */
  29.  
  30. #include "common/mmo.h"
  31. #include "map/guild.h"
  32. #include "map/mapreg.h"
  33. #include "map/script.h"
  34.  
  35. #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) */
  36.  
  37. HPExport struct hplugin_info pinfo = {
  38.     "BUILDIN(getalliance)", // Plugin name
  39.     SERVER_TYPE_MAP, // Which server types this plugin works with?
  40.     "1.0", // Plugin version
  41.     HPM_VERSION, // HPM Version (don't change, macro is automatically updated)
  42. };
  43.  
  44. /*
  45. *getalliance(<Guild ID>)
  46. This command will find all guilds in an alliance with the specified guild and
  47. returns their names and guild ids into an array of temporary global variables.
  48.  
  49. Upon executing this,
  50.  
  51. $@guildallyname$[]        is a global temporary string array which contains all the
  52.                           names of each allied guild.
  53.  
  54. $@guildoppositionname$[]  is a global temporary string array which contains all the
  55.                           names of each allied guild.
  56.  
  57. $@guildallygid[]          is a global temporary number array which contains the
  58.                           guild id of each allied guild.
  59.  
  60. $@guildoppositiongid[]    is a global temporary number array which contains the
  61.                           guild id of each opposition guild.
  62.  
  63. $@guildallycount          is the number of allied guilds found.
  64.  
  65. $@guildoppositioncount    is the number of opposition guilds found.
  66.  
  67. Note that the names come in no particular order.
  68.  
  69. Be sure to use $@guildallycount/$@guildoppositioncount to go through this array, and not
  70. getarraysize(), because it is not cleared between runs of getalliance().
  71.  
  72. For usage examples, see getpartymember().
  73. */
  74. BUILDIN(getalliance)
  75. {
  76.     struct guild *g = NULL;
  77.     int guild_id = script_getnum(st, 2);
  78.     int i = 0, j = 0, k = 0;
  79.  
  80.     if ((g = guild->search(guild_id)) == NULL)
  81.         return true;
  82.  
  83.     for (i = 0; i < MAX_GUILDALLIANCE; i++) {
  84.         struct guild_alliance *a = &g->alliance[i];
  85.         if (a->guild_id > 0) {
  86.             if (a->opposition == 0) {
  87.                 mapreg->setreg(reference_uid(script->add_str("$@guildallygid"), j), a->guild_id);
  88.                 mapreg->setregstr(reference_uid(script->add_str("$@guildallyname$"), j), a->name);
  89.                 j++;
  90.             }
  91.             else {
  92.                 mapreg->setreg(reference_uid(script->add_str("$@guildoppositiongid"), k), a->guild_id);
  93.                 mapreg->setregstr(reference_uid(script->add_str("$@guildoppositionname$"), k), a->name);
  94.                 k++;
  95.             }
  96.         }
  97.     }
  98.     mapreg->setreg(script->add_str("$@guildallycount"), j);
  99.     mapreg->setreg(script->add_str("$@guildoppositioncount"), k);
  100.  
  101.     return true;
  102. }
  103.  
  104. /* run when server starts */
  105. HPExport void plugin_init (void)
  106. {
  107.     // Atcommands only make sense on the map server
  108.     if (SERVER_TYPE == SERVER_TYPE_MAP) {
  109.         addScriptCommand("getalliance", "i", getalliance);
  110.     }
  111. }
Advertisement
RAW Paste Data Copied
Advertisement