Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //===== Hercules Plugin ======================================
- //= BUILDIN(getguildid)
- //===== By ===================================================
- //= Wolfie of BlackoutRO (http://blackout-ro.net)
- //===== Description ==========================================
- //= Gives your server the 'getalliance' script command.
- // Sample Script:
- /**************************************
- getalliance(getcharid(CHAR_ID_GUILD));
- dispbottom(sprintf("Alliances found: %d", $@guildallycount), 0x00FFFF);
- for (.@i = 0; .@i < $@guildallycount; .@i++)
- dispbottom(sprintf("%d. %s (GID - %d)", (.@i + 1), $@guildallyname$[.@i], $@guildallygid[.@i]), 0x00FFFF);
- dispbottom(sprintf("Opposition found: %d", $@guildoppositioncount), 0x00FFFF);
- for (.@i = 0; .@i < $@guildoppositioncount; .@i++)
- dispbottom(sprintf("%d. %s (GID - %d)", (.@i + 1), $@guildoppositionname$[.@i], $@guildoppositiongid[.@i]), 0x00FFFF);
- end;
- **************************************/
- // This sample script will send a message to the invoked
- // player's chat informing them of how many allies and
- // oppositions they have, as well as their name(s) and GID(s).
- //===== Comments =============================================
- //= Read below to find the 'documentation' of the script
- // command which explains it better.
- //============================================================
- #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) */
- #include "common/mmo.h"
- #include "map/guild.h"
- #include "map/mapreg.h"
- #include "map/script.h"
- #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) */
- HPExport struct hplugin_info pinfo = {
- "BUILDIN(getalliance)", // Plugin name
- SERVER_TYPE_MAP, // Which server types this plugin works with?
- "1.0", // Plugin version
- HPM_VERSION, // HPM Version (don't change, macro is automatically updated)
- };
- /*
- *getalliance(<Guild ID>)
- This command will find all guilds in an alliance with the specified guild and
- returns their names and guild ids into an array of temporary global variables.
- Upon executing this,
- $@guildallyname$[] is a global temporary string array which contains all the
- names of each allied guild.
- $@guildoppositionname$[] is a global temporary string array which contains all the
- names of each allied guild.
- $@guildallygid[] is a global temporary number array which contains the
- guild id of each allied guild.
- $@guildoppositiongid[] is a global temporary number array which contains the
- guild id of each opposition guild.
- $@guildallycount is the number of allied guilds found.
- $@guildoppositioncount is the number of opposition guilds found.
- Note that the names come in no particular order.
- Be sure to use $@guildallycount/$@guildoppositioncount to go through this array, and not
- getarraysize(), because it is not cleared between runs of getalliance().
- For usage examples, see getpartymember().
- */
- BUILDIN(getalliance)
- {
- struct guild *g = NULL;
- int guild_id = script_getnum(st, 2);
- int i = 0, j = 0, k = 0;
- if ((g = guild->search(guild_id)) == NULL)
- return true;
- for (i = 0; i < MAX_GUILDALLIANCE; i++) {
- struct guild_alliance *a = &g->alliance[i];
- if (a->guild_id > 0) {
- if (a->opposition == 0) {
- mapreg->setreg(reference_uid(script->add_str("$@guildallygid"), j), a->guild_id);
- mapreg->setregstr(reference_uid(script->add_str("$@guildallyname$"), j), a->name);
- j++;
- }
- else {
- mapreg->setreg(reference_uid(script->add_str("$@guildoppositiongid"), k), a->guild_id);
- mapreg->setregstr(reference_uid(script->add_str("$@guildoppositionname$"), k), a->name);
- k++;
- }
- }
- }
- mapreg->setreg(script->add_str("$@guildallycount"), j);
- mapreg->setreg(script->add_str("$@guildoppositioncount"), k);
- return true;
- }
- /* run when server starts */
- HPExport void plugin_init (void)
- {
- // Atcommands only make sense on the map server
- if (SERVER_TYPE == SERVER_TYPE_MAP) {
- addScriptCommand("getalliance", "i", getalliance);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement