Jump to content
  • 0
Like it~*

How to convert to a plugin?

Question

Could someone teach me how to convert to this diff plugin, please?
 
1 - Show shop.

 

/*=====================================================
* Créditos pelo código é para CrushTheMoonGuy e Holy. *
* Atualizado para revisão atual do brAthena por Tidus.* 
*----------------------------------------------------*/

diff --git a/src/map/clif.c b/src/map/clif.c
index 7ec7882..d57240f 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -4289,6 +4290,8 @@ void clif_getareachar_unit(struct map_session_data* sd,struct block_list *bl) {
 					clif->specialeffect_single(bl,423,sd->fd);
 				else if( nd->size == SZ_MEDIUM )
 					clif->specialeffect_single(bl,421,sd->fd);
+				if( nd->vend.vends == true )
+					clif->showvendingboard( &nd->bl, nd->vend.vending, sd->fd );
 			}
 			break;
 		case BL_MOB:
diff --git a/src/map/npc.h b/src/map/npc.h
index 34daf4c..af01866 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -125,6 +130,12 @@ struct npc_data {
 			char killer_name[NAME_LENGTH];
 		} tomb;
 	} u;
+
+		struct {
+		char vending[NAME_LENGTH+1]; //vending name
+		bool vends; //does he vend?
+		} vend;
+
 };
 
 
diff --git a/src/map/script.c b/src/map/script.c
index c983fa7..5f3cd94 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -17943,6 +17987,51 @@ int buildin_instance_warpall_sub(struct block_list *bl,va_list ap) {
 	return true;
 }
 
+BUILDIN(showvend)
+{
+	struct npc_data *nd;
+	const char * message;
+	const char * name;
+	unsigned char buf[NAME_LENGTH+1];
+	int flag;
+
+	name = script_getstr( st, 2 );
+	flag = script_getnum( st, 3 );
+
+	if( flag && !script_hasdata( st, 4 ) ) {
+	ShowError( "showvend: want to create vendingboard without name.\n" );
+	script_reportsrc( st );
+	st->state = END; //Script stops
+	return -1;
+	}
+	else if( flag )
+	message = script_getstr( st, 4 );
+
+	nd = npc->name2id( name );
+
+	if( nd == NULL ) {
+	ShowError( "showvend: no npc found!\n" );
+	script_pushint( st, 0 ); //Fail return 0
+	return 0;
+	}
+
+	switch( flag ) {
+	case 0:
+	clif->closevendingboard( &nd->bl, 0 );
+	nd->vend.vends = false;
+	break;
+	default:
+	memcpy( buf, message, NAME_LENGTH + 1 );
+	clif->showvendingboard( &nd->bl, buf, 0 );
+	nd->vend.vends = true;
+	memcpy( nd->vend.vending, message, NAME_LENGTH + 1 );
+	break;
+	}
+
+	script_pushint( st, 1 ); //Success return 1
+	return 0;
+}
+
 /*==========================================
  * Custom Fonts
  *------------------------------------------*/
@@ -21361,6 +21364,10 @@ void script_parse_builtin(void) {
 
 		BUILDIN_DEF(channelmes, "ss"),
 		BUILDIN_DEF(_,"s"),
+
+		/* brAthena - Modificações */
+		BUILDIN_DEF(showvend, "si?" ),
+		
 	};
 	int i, len = ARRAYLENGTH(BUILDIN);
 	RECREATE(script->buildin, char *, script->buildin_count + len); // Pre-alloc to speed up
diff --git a/src/map/vending.c b/src/map/vending.c
index e07d6bd..3740b9c 100644
--- a/src/map/vending.c
+++ b/src/map/vending.c
@@ -22,6 +22,7 @@
 #include "clif.h"
 #include "itemdb.h"
 #include "log.h"
+#include "npc.h"
 #include "map.h"
 #include "npc.h"
 #include "path.h"
@@ -73,8 +74,25 @@ void vending_closevending(struct map_session_data* sd) {
  *------------------------------------------*/
 void vending_vendinglistreq(struct map_session_data* sd, unsigned int id) {
 	struct map_session_data* vsd;
+	struct npc_data *nd_sd;
 	nullpo_retv(sd);
 
+	if( nd_sd = (TBL_NPC*) map->id2bl( id ) ) { //It's an NPC
+	if( nd_sd->vend.vends == true ) {
+		char event_name[64 + 23 + 1];
+	if( nd_sd->subtype == CASHSHOP ) //Act as if it was clicked
+		npc->click( sd, nd_sd );
+	if( nd_sd->subtype == SHOP ) //Open Buy-Windows directly
+		npc->buysellsel( sd, nd_sd->bl.id, 0 );
+	if( nd_sd->subtype == SCRIPT ) { //Trigger OnVendingClick event
+		sprintf( event_name, "%s::OnVendingClick", &nd_sd->name );
+		npc->event( sd, event_name, 0 );
+		return;
+		}
+	}
+	return; //WARP will just return
+}
+
 	if( (vsd = map->id2sd(id)) == NULL )
 		return;
 	if( !vsd->state.vending )

 

 

 

8 -

 

 

//Limite Job Guild
Index: conf/map/battle/guild.conf
===================================================================
--- conf/map/battle/guild.conf	(revision 18428)
+++ conf/map/battle/guild.conf	(working copy)
@@ -71,3 +71,7 @@
 // default: false
 guild_castle_invite: false
 guild_castle_expulsion: false
+
+// Limite de classes repetidas no clã
+// max_guild_class = 0 para desativar, quantidade máxima é 999
+max_guild_class: 1
\ No newline at end of file
Index: src/map/battle.c
===================================================================
--- src/map/battle.c	(revision 18428)
+++ src/map/battle.c	(working copy)
@@ -7333,6 +7333,7 @@
 	{ "max_summoner_parameter",             &battle_config.max_summoner_parameter,          120,    10,     10000,          },
 	{ "mvp_exp_reward_message",             &battle_config.mvp_exp_reward_message,          0,      0,      1,              },
 	{ "monster_eye_range_bonus",            &battle_config.mob_eye_range_bonus,             0,      0,      10,             },
+	{ "max_guild_class",					&battle_config.max_guild_class,		 	 	    0,	    0,		999,			},
 };
 #ifndef STATS_OPT_OUT
 /**
Index: src/map/battle.h
===================================================================
--- src/map/battle.h	(revision 18428)
+++ src/map/battle.h	(working copy)
@@ -552,6 +552,8 @@
 	int mvp_exp_reward_message;
 
 	int mob_eye_range_bonus; //Vulture's Eye and Snake's Eye range bonus
+	
+	int max_guild_class;
 };
 
 /* criteria for battle_config.idletime_critera */
Index: src/map/guild.c
===================================================================
--- src/map/guild.c	(revision 18428)
+++ src/map/guild.c	(working copy)
@@ -626,6 +626,29 @@
 }
 
 /*=============================================
+ * Desenvolvedor: Gilmar B. Freitas(@Kyomai)
+ * Conta a quantidade de jogadores de uma determinada classe
+ *--------------------------------------------*/
+int guild_class_count( int guild_id, int16 class ) {
+	
+	struct guild* g = guild->search(guild_id);
+	
+	if (g == NULL) return 0;
+	int i, quantidade = 0;
+	for (i = 0; i < g->max_member; ++i) {
+		
+		// Caso o jogador esteja online verifica a classe do personagem diretamente.
+		if (g->member[i].online) {
+			if (g->member[i].sd->status.class == class)++quantidade;
+		} else {
+			if (g->member[i].class == class)++quantidade;
+		}
+		
+	}
+	return quantidade;
+}
+
+/*=============================================
  * Player sd send a guild invatation to player tsd to join his guild
  *--------------------------------------------*/
 int guild_invite(struct map_session_data *sd, struct map_session_data *tsd) {
@@ -672,7 +695,7 @@
 		clif->guild_inviteack(sd,3);
 		return 0;
 	}
-
+	
 	tsd->guild_invite=sd->status.guild_id;
 	tsd->guild_invite_account=sd->status.account_id;
 
@@ -745,7 +761,24 @@
 			sd->guild_invite_account = 0;
 			return 0;
 		}
+		
+		// Verifica se está habilitado o recurso de limitação de classes repetidas
+		if ( battle_config.max_guild_class > 0 ) {
 
+			int quantidade = guild_class_count(g->guild_id,sd->status.class);
+
+			// Se a quantidade de membros da mesma classe for igual ou maior que a quantidade limite definida no arquivo guild.conf o jogador convidadonão será convidado
+			if ( quantidade >= battle_config.max_guild_class ) {
+				char mensagem[128];
+				sprintf( mensagem, "Você não pode se tornar membro do clã, porque o clã já possui %d %s.", quantidade, pc->job_name(sd->status.class) );
+				clif->messagecolor_self(sd->fd, COLOR_RED, mensagem);
+				sd->guild_invite = 0; // Apaga o convite ser membro do clã.
+				sd->guild_invite_account = 0;
+				return 0;
+			}
+		}
+		// Fim da verificação
+		
 		ARR_FIND( 0, g->max_member, i, g->member[i].account_id == 0 );
 		if( i == g->max_member )
 		{
@@ -2359,6 +2399,7 @@
 	guild->recv_noinfo = guild_recv_noinfo;
 	guild->recv_info = guild_recv_info;
 	guild->npc_request_info = guild_npc_request_info;
+	guild->class_count = guild_class_count;
 	guild->invite = guild_invite;
 	guild->reply_invite = guild_reply_invite;
 	guild->member_joined = guild_member_joined;
Index: src/map/guild.h
===================================================================
--- src/map/guild.h	(revision 18428)
+++ src/map/guild.h	(working copy)
@@ -109,6 +109,7 @@
 	int (*recv_noinfo) (int guild_id);
 	int (*recv_info) (const struct guild *sg);
 	int (*npc_request_info) (int guild_id,const char *ev);
+	int (*class_count) ( int guild_id, int16 class);
 	int (*invite) (struct map_session_data *sd,struct map_session_data *tsd);
 	int (*reply_invite) (struct map_session_data *sd,int guild_id,int flag);
 	void (*member_joined) (struct map_session_data *sd);
Index: src/map/pc.c
===================================================================
--- src/map/pc.c	(revision 18428)
+++ src/map/pc.c	(working copy)
@@ -8747,7 +8747,47 @@
 			break;
 		}
 	}
-
+	
+	// Verificação, caso o sistema de limitação de classe esteja ativo.
+	if ( battle_config.max_guild_class > 0 ) {
+		
+		struct guild *g = sd->guild;
+		// Verifica a exitência do clã para determinado jogador.
+		if (g) {
+			
+			// Verifica a quantidade de jogadores da mesma classe que estão na guild incluindo o próprio jogador.
+			int quantidade = guild->class_count(g->guild_id,sd->status.class);
+			
+			// Caso contando com ele seja maior do que o limite, ele será expulso.
+			if (quantidade > battle_config.max_guild_class) {
+				
+				/*
+				 * Verifica se o jogador é o líder do clã, caso positivo ele terá de escolher outro membro da
+				 * mesma classe para ser removido.
+				*/
+				if (sd->state.gmaster_flag) {
+					
+					// Percorre os membros do clã.
+					int indice;
+					for (indice = 0; indice < g->max_member; ++indice) {
+						
+						// Porcura um membro da mesma classe para ser removido.
+						if ((g->member[indice].class == sd->status.class) && (g->member[indice].char_id != sd->status.char_id)) {
+							// Remove membro do clã
+							intif->guild_leave(g->guild_id,g->member[indice].account_id,g->member[indice].char_id,1,"Excesso de contigente");
+							// Finaliza o laço de repetição.
+							indice = g->max_member;					
+						}
+					}				
+				} else {
+					// Remove o membro do clã.
+					intif->guild_leave(g->guild_id,sd->status.account_id,sd->status.char_id,1,"Excesso de contigente");
+				}					
+			}			
+		}
+	}
+	// Fim da verificação.
+	
 	return 0;
 } 

 

 

 

NOTE: The main topic has been cleared to leave only the most important ones and the following diffs have been removed due to the difficulty of finding collaborators, if someone is interested please contact me and I will provide the files.

 

2 - Fakename, 5 - Annouce item. Note: from rathena, 7 - MAC. , 9 - Get stuff item - [PVP]/[GVG]/[bTG], 

 

Diffs already converted.

 
Some diffs have already been converted thanks to the incredible @Dastgir work. All credits and thanks should be directed to it, I just supplied the diffs files with the codes. Every community is very happy and thanks for this contribution, thank you very much!
 

3) deadon/deadoff: Force Players into Trick Dead.

4) mapsit: Contains various commands like mapsit, mapstand, sit, stand, to.

forcefully make player sit or stand.

6) guildjoin: Invites player offline into guild.

 

Edited by Like it~*

Share this post


Link to post
Share on other sites

16 answers to this question

Recommended Posts

  • 0
Seems interesting.

I would be interested in doing some of these, though not promising if I would do it.

1) May be possible

2) I won't be touching it, it seems possible only with workarounds.

3) Possible

4) Possible

5) Wont be touching it, possible with workaround/ function overload.

6) Possible.

7) I Insist keeping that part as source.

 

But I insist try and learn and do it with Trial and error method

Share this post


Link to post
Share on other sites
  • 0

 

Seems interesting.
I would be interested in doing some of these, though not promising if I would do it.
1) May be possible
2) I won't be touching it, it seems possible only with workarounds.
3) Possible
4) Possible
5) Wont be touching it, possible with workaround/ function overload.
6) Possible.
7) I Insist keeping that part as source.
 
But I insist try and learn and do it with Trial and error method

 

Hello, Dastgir, thank you so much for helping. I can not deny that I was a bit sad, because the most important codes can not be converted. But on the other hand I'm happy, because I know that these codes in your hands will be of great benefit to the Hercules community :)
 
As for the learning issue, I love learning new things that are going to be really useful, but as you know, you can not learn programming in just a few days, this will take years and a lot of time dedicated. But in the future I intend to, I already started with the scripts, and I can do basic things ... But when it involves source, it is impossible for those who have not studied.

Share this post


Link to post
Share on other sites
  • 0

 

Wow, thank you very much, Sir. Your work is awesome!
Please keep converting the other diffs, even though I have to wait longer. I will be eternally grateful to you.
 
Note: I added 2 more diffs for you at a glance (8 and 9), and also cleaned the first post with thanks and credits.
 
Once again I would like to thank you, I am very happy with that.

Share this post


Link to post
Share on other sites
  • 0

Happy can convert Source mod to Plugin.

 

Check his paid services here.

 

 
Hello, EasyCore. Thank you for trying to help, but I would like this contribution to go to the community and not, personally.
I just cleaned the topic and left only the most important plugins due to the difficulty of finding collaborators.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Restore formatting

  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.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.