Jump to content
  • 0

Help with npc and table


nelax

Question


  • Group:  Members
  • Topic Count:  30
  • Topics Per Day:  0.01
  • Content Count:  41
  • Reputation:   0
  • Joined:  08/16/13
  • Last Seen:  


Could someone help me with an npc?
It would work as follows.
Guild leader 1 talks to the npc.
the npc checks the guild name and asks if the leader wants to open a guild vault
The leader confirming that he wants to open it, a table is generated for this guild
This table would have 3 fields: Zeny, Black Fragment (ID 45000) and Metal Reforged (ID 45001).
When a member or even the leader of that guild 1 spoke to the npc, it would show 2 options: Donate Material and Total Material donated
In the option to donate players from this guild, 1 could donate a maximum of a certain amount of each material mentioned above (Zeny, Black Fragment and Reforged Metal)
In the Total Materials option, the name of the members and the total amount of material donated by each one would appear.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

  • Group:  Members
  • Topic Count:  1
  • Topics Per Day:  0.00
  • Content Count:  234
  • Reputation:   87
  • Joined:  06/30/18
  • Last Seen:  

prontera, 155, 180, 4	script	Guild Donation Manager	4_F_AGENTKAFRA,{
	function listAcceptedItems {
		for(.@i = 0; .@i < getarraysize(.accepted_items); .@i++)
			mes getitemname(.accepted_items[.@i]);
	}

	function saveDonation {
		.@guild_id = getcharid(2);
		.@character_id = getcharid(0);
		.@zeny = getarg(0);
			
		for(.@i = 0; .@i < getarraysize(.accepted_items); .@i++) {
			.@item_row$ = "item" + (.@i + 1);

			.@item_rows$ += ", " + .@item_row$;
			.@item_insert$ += ", " + getelementofarray(getarg(1), .@i));
			.@insert_update$ += ", " + .@item_row$ + " = " + .@item_row$ + " + " + getelementofarray(getarg(1), .@i));
		}

		query_sql("INSERT INTO guild_donations (guild_id, character_id, zeny" + .@item_rows$ + ") VALUES (" + .@guild_id + ", " + .@character_id + ", " + .@zeny + .@item_insert$ + ") ON DUPLICATE KEY UPDATE zeny = zeny + " + .@zeny + .@insert_update$);
	}

	function showHistory {
		.@guild_id = getcharid(2);

		for(.@i = 0; .@i < getarraysize(.accepted_items); .@i++)
			.@item_rows$ += ", item" + (.@i + 1);

		query_sql("SELECT character_id, zeny" + .@item_rows$ + " FROM guild_donations WHERE guild_id = " + .@guild_id, .@character_id, .@zeny, .@item1, .@item2);

		for(.@i = 0; .@i < getarraysize(.@guild_id); .@i++)
			mes "Character: " + strcharinfo(0, .@character_id[.@i]) + " Zeny: " + .@zeny[.@i] + " " + getitemname(.accepted_items[0]) + ": " + .@item1[.@i] + " " + getitemname(.accepted_items[1]) + ": " + .@item2[.@i];
	}

	if((.@guild_id = getcharid(2)) == 0) {
		mes "[" + .npc_name$ + "]";
		mes "Sadly i can't help you, since you are not in a guild.";
		close;
	}

	mes "[" + .npc_name$ + "]";
	mes "Hello Guild " + ((is_guild_leader(.@guild_id)) ? "Master" : "Member") + "!";
	mes "How may i help you today?";
	next;
	switch(select("I want to donate.:Show me the donation history.")) {
		case 1:
			mes "[" + .npc_name$ + "]";
			mes "What do you want to donate?";
			next;
			if(select("Zeny:Items") == 1) {
				mes "[" + .npc_name$ + "]";
				mes "How many zeny do you want to donate?";
				next;
				input(.@donation);
				if (Zeny < .@donation) {
					mes "[" + .npc_name$ + "]";
					mes "You don't have enough zeny.";
					close;
				}
				Zeny -= .@donation;
				saveDonation(.@donation, .@items);
				mes "[" + .npc_name$ + "]";
				mes "Alright, i registered your donation!";
				close;
			} else {
				mes "[" + .npc_name$ + "]";
				mes "Remember i can only take the following items: ";
				listAcceptedItems();
				close2;
				callshop("guild_donation_dummy_shop", 2);
				npcshopattach("guild_donation_dummy_shop");
				end;
			}
			break;
		case 2:
			mes "[" + .npc_name$ + "]";
			showHistory();
			close;
			break;
	}

	OnSellItem:
		for(.@i = 0; .@i < getarraysize(@sold_nameid); .@i++) {
			if((.@index = inarray(.accepted_items[0], @sold_nameid[.@i])) == -1) {
				mes "[" + .npc_name$ + "]";
				mes "There are items i can't accept.";
				mes "I only take the following items: ";
				listAcceptedItems();
				close;
			}

			.@items[.@index] = @sold_quantity[.@i];
		}

		for(.@i = 0; .@i < getarraysize(@sold_nameid); .@i++)
			delitem(@sold_nameid[.@i], @sold_quantity[.@i]);

		saveDonation(0, .@items);
		end;

	OnInit:
		.npc_name$ = strnpcinfo(1);
		setarray(.accepted_items[0], 45000, 45001);
}

-	shop	guild_donation_dummy_shop	-1,501:50.
CREATE TABLE IF NOT EXISTS `guild_donations` (
  `guild_id` int(11) NOT NULL,
  `character_id` int(11) NOT NULL,
  `character_name` varchar(32) NOT NULL,
  `zeny` int(11) NOT NULL,
  `item1` int(11) NOT NULL,
  `item2` int(11) NOT NULL,
  PRIMARY KEY (`guild_id`,`character_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;

 

  • MVP 1
Link to comment
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.   Paste as plain text instead

  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.

×
×
  • Create New...