Jump to content
  • 0

Npc for Guild Master and Guild Members @gstorage


Kido

Question


  • Group:  Members
  • Topic Count:  127
  • Topics Per Day:  0.03
  • Content Count:  1445
  • Reputation:   163
  • Joined:  08/17/13
  • Last Seen:  

Hello, i would to request/knowHowToDo a npc that opens the guild storage only for the guild master and also, the guild master will have the option to select up to 10 members of its guild that can open the guild storage too. The npc will work for all guilds and all guild masters, it will be a public npc not a one inside the castle, also it won't be neccesary to the guild/guild master to have 1 castle conquered. Thank you in advance o:!

 

i was playing around with the npc inside the castles that opens the guild storage but i couldn't figure it out at all @_@ thanks again o:!

Link to comment
Share on other sites

17 answers to this question

Recommended Posts


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  135
  • Reputation:   41
  • Joined:  02/05/14
  • Last Seen:  

Here's my method, which uses dynamic global variables in place of an SQL table:

-	script	guildstorage	-1,{
	
	// Function: Return character name of sent ID
	function getcharname {
		query_sql("SELECT `name` FROM `char` WHERE `char_id` = '"+ getarg(0) +"'", .@query_name$);
		return .@query_name$;
	}
	
	
	OnInit:
		// Configuration
		bindatcmd "guildstorage", strnpcinfo(3) +"::OnAtcommand", 0, 0;
		bindatcmd "gstorage", strnpcinfo(3) +"::OnAtcommand", 0, 0;
		end;

		
	OnAtcommand:
		// Guild master access
		if (getguildmasterid(getcharid(2)) == getcharid(0)) {
			while (1) {
				switch (select("Open storage:Change permissions:End session")) {
					case 1:
						// Open storage
						message strcharinfo(0), "Guild storage opened.";
						guildopenstorage();
						close;
						
					case 2:
						// Clear looped data
						cleararray .@access_list$[0], "", getarraysize(.@access_list$);
						cleararray .@member_list$[0], "", getarraysize(.@member_list$);
						.@j = 0;
					
						// Build access list
						for (.@i = 0; .@i < getarraysize(getd("$GS_Auth_"+ getcharid(2))); .@i++) {
							.@access_list$[.@j++] = getcharname(getd("$GS_Auth_"+ getcharid(2) +"["+ .@i +"]"));
						}
						
						// Inject "Add new member" option
						.@access_list$[getarraysize(.@access_list$)] = "Add new member";
						
						// Inject "Go back" option
						.@access_list$[getarraysize(.@access_list$)] = "Go back";
						
						// Select member to modify
						menu implode(.@access_list$, ":"), -;
						.@access_choice = @menu - 1;
						
						// Check if last option selected
						if (@menu == getarraysize(.@access_list$)) {
							break;
						}
						
						// Check if second to last option selected
						if (@menu == getarraysize(.@access_list$) - 1) {
							// Build member list
							query_sql "SELECT `name` FROM `guild_member` WHERE `guild_id` = '"+ getcharid(2) +"'", .@member_list$;
						
							// Inject "Go back" option
							.@member_list$[getarraysize(.@member_list$)] = "Go back";
						
							// Add new member
							menu implode(.@member_list$, ":"), -;
							.@member_choice = @menu - 1;
							
							// Check if last option selected
							if (.@member_choice == getarraysize(.@member_list$)) {
								break;
							}
							
							// Add member's ID to array
							query_sql "SELECT `char_id` FROM `guild_member` WHERE `name` = '"+ .@member_list$[.@member_choice] +"'", .@member_id;
							message strcharinfo(0), "Granted guild storage access for '"+ .@member_list$[.@member_choice] +"'.";
							setd "$GS_Auth_"+ getcharid(2) +"["+ getarraysize(getd("$GS_Auth_"+ getcharid(2))) +"]", .@member_id;
							break;
						}
						
						// Revoke access
						switch (select("Revoke access:Go back")) {
							case 1:
								message strcharinfo(0), "Revoked guild storage access for '"+ getcharname(getd("$GS_Auth_"+ getcharid(2) +"["+ .@access_choice +"]")) +"'.";
								deletearray getd("$GS_Auth_"+ getcharid(2) +"["+ .@access_choice +"]"), 1;
								break;
						
							case 2:
								break;
						}
						
						break;
					
					case 3:
						close;
				}
			}
			
		// Guild member access
		} else if (getcharid(2)) {
			// Check permission
			for (.@i = 0; .@i < getarraysize(getd("$GS_Auth_"+ getcharid(2) +"["+ .@i +"]")); .@i++) {
				// Open storage
				if (getd("$GS_Auth_"+ getcharid(2) +"["+ .@i +"]") == getcharid(0)) {
					message strcharinfo(0), "Guild storage opened.";
					guildopenstorage();
					end;
				}
			}
				
			// Unauthorised access
			message strcharinfo(0), "You are not authorised to access guild storage.";
			
		// No guild
		} else {
			message strcharinfo(0), "You are not in a guild.";
		}
		
		message strcharinfo(0), .@atcmd_command$ +" failed.";
		end;

}

This supports guildmaster changes and up to 128 members (not sure if rA has limitless arrays), though the typical maximum number of guild members is 76. A guild master can access the control panel and either grant or revoke member access.

 

 

Edit: Removed debug code.

Edited by Missingno
  • Upvote 1
Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  28
  • Topics Per Day:  0.01
  • Content Count:  135
  • Reputation:   4
  • Joined:  11/23/12
  • Last Seen:  

How to solve this problem

Quote

[Warning]: Incorrect use of 'close' command!

[Debug]: Source <npc>: guildstorage <invisible/not on a map>

Nothing shows even it tells "Guild storage opened".

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

I made something like this awhile ago.

 

http://code.google.com/p/ea-addicts/downloads/detail?name=guildwarehousesql.txt&can=2&q=#makechanges

 

This is a video tutorial of how to use the script.

 

  • Upvote 2
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  127
  • Topics Per Day:  0.03
  • Content Count:  1445
  • Reputation:   163
  • Joined:  08/17/13
  • Last Seen:  

woa amazing o:!!!!

 

may i ask for the name of the song, it was sooooooo cooooooooool !!! 

 

lol huh i was going to edit the topic to made it more simple

 

guildstorage opesn to any members but it will have password setted by the gm

 

thanks for sharing o:!

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  127
  • Topics Per Day:  0.03
  • Content Count:  1445
  • Reputation:   163
  • Joined:  08/17/13
  • Last Seen:  

wa it's so short DDDDDDDD:! still amazing

huh come to thinking, it's perfect for my website server, because it is short it won't take a lot of memory usage o:!

huh the link to the script on the video is broken D:!

Thank you so much for the share o:!

Woa i can't understand 99% of it !!! because i just don't know lol

thank you so much, going to use it

huh where do i place the npc, map or cords D:?

just amazing /fsh

 

Edit:

every time i open the guild storage or end the session this error appears ?

rvkp.png

well it doesnt matter it works perfectly :D!

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  135
  • Reputation:   41
  • Joined:  02/05/14
  • Last Seen:  

Load it directly into your server. It's a floating script without a location (hence the hyphen - instead of a map and coordinates) and without a sprite (-1). It binds the script with the atcommand @gstorage, and even creates a new one (@guildstorage) if you want to use that instead. Try using it on non-GM characters, since some GM restrictions prevent storage access in general.

I left a bunch of comments for the sake of learning purposes; I write my code in sections, so you should have a pretty easy time going over each feature. Read through the documentation and the Wiki for things you don't understand, but a lot of the code is self-explanatory when you get the hang of it. d:

  • Upvote 1
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  127
  • Topics Per Day:  0.03
  • Content Count:  1445
  • Reputation:   163
  • Joined:  08/17/13
  • Last Seen:  

yeah i could see them o:!

 

thant you so much for the explanation and comments, it refils me to also learn so in the future i may help others :DD!

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

Here's my method, which uses dynamic global variables in place of an SQL table:

This supports guildmaster changes and up to 128 members (not sure if rA has limitless arrays), though the typical maximum number of guild members is 76. A guild master can access the control panel and either grant or revoke member access.

 

 

Edit: Removed debug code.

 

You should avoid using global variables for things like this... Especially if it isn't bitwise or compact string... Reason being it's updated very frequently as opposed to a new sql table which is only used when the script requires it. Soon you'll have a very large set of strings or numbers being constantly updated.

 

You've effectively created an array of many global variables. x_x;;

 

I also recommend you add some kind of clear command to your script. If a GM ever decides to remove your script all your unused variables will litter their server.

 

Ideally you'd save all information into its own sql scheme and load it to the script via temporary global variables when the server starts.

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  127
  • Topics Per Day:  0.03
  • Content Count:  1445
  • Reputation:   163
  • Joined:  08/17/13
  • Last Seen:  

Huh that means lag D:? well i can always empty those variables? huh i was wondering if it's possible then, to create a special table to store those variables, so when needed clear them or something o:!

 

lol still eharing the song, for hours ~

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  135
  • Reputation:   41
  • Joined:  02/05/14
  • Last Seen:  

 

Here's my method, which uses dynamic global variables in place of an SQL table:

This supports guildmaster changes and up to 128 members (not sure if rA has limitless arrays), though the typical maximum number of guild members is 76. A guild master can access the control panel and either grant or revoke member access.

 

 

Edit: Removed debug code.

 

You should avoid using global variables for things like this... Especially if it isn't bitwise or compact string... Reason being it's updated very frequently as opposed to a new sql table which is only used when the script requires it. Soon you'll have a very large set of strings or numbers being constantly updated.

 

You've effectively created an array of many global variables. x_x;;

 

I also recommend you add some kind of clear command to your script. If a GM ever decides to remove your script all your unused variables will litter their server.

 

Ideally you'd save all information into its own sql scheme and load it to the script via temporary global variables when the server starts.

 

 

In hindsight, using temporary global variables with an SQL table would be more ideal; I guess I overlooked that with the primary objective of replacing the need for an SQL table. I rewrote the script to accommodate this:

/*=========================================================
SQL table:
CREATE TABLE IF NOT EXISTS `guild_storage_access` (
	`guild_id` int(11) NOT NULL,
	`char_id` int(11) NOT NULL,
	PRIMARY KEY  (`char_id`)
) ENGINE=MyISAM;
==========================================================*/

-	script	guildstorage	-1,{
	
	// Function: Return character name of sent ID
	function getcharname {
		query_sql "SELECT `name` FROM `char` WHERE `char_id` = '"+ getarg(0) +"'", .@query_name$;
		return .@query_name$;
	}
	
	
	OnInit:
		// Store values from SQL table in temporary global array
		query_sql "SELECT `guild_id`,`char_id` FROM `guild_storage_access`", $@GS_Guild, $@GS_Member;
	
		// Configuration
		bindatcmd "guildstorage", strnpcinfo(3) +"::OnAtcommand", 0, 0;
		bindatcmd "gstorage", strnpcinfo(3) +"::OnAtcommand", 0, 0;
		end;

		
	OnAtcommand:
		// Check if player is in town
		if (!getmapflag(strcharinfo(3), mf_town)) {
			message strcharinfo(0), "You may only use guild storage in towns.";
		
		// Guild master access
		} else if (getguildmasterid(getcharid(2)) == getcharid(0)) {
			while (1) {
				switch (select("Open storage:Change permissions:End session")) {
					case 1:
						// Open storage
						message strcharinfo(0), "Guild storage opened.";
						guildopenstorage();
						close;
						
					case 2:
						// Clear looped data
						cleararray .@access_list$[0], "", getarraysize(.@access_list$);
						cleararray .@member_list$[0], "", getarraysize(.@member_list$);
						.@j = 0;
					
						// Build access list
						for (.@i = 0; .@i < getarraysize($@GS_Guild); .@i++) {
							if ($@GS_Guild[.@i] == getcharid(2)) {
								.@access_list$[.@j++] = getcharname($@GS_Member[.@i]);
							}
						}
						
						// Inject "Add new member" option
						.@access_list$[getarraysize(.@access_list$)] = "Add new member";
						
						// Inject "Go back" option
						.@access_list$[getarraysize(.@access_list$)] = "Go back";
						
						// Select member to modify
						menu implode(.@access_list$, ":"), -;
						.@access_choice = @menu - 1;
						
						// Check if last option selected
						if (@menu == getarraysize(.@access_list$)) {
							break;
						}
						
						// Check if second to last option selected
						if (@menu == getarraysize(.@access_list$) - 1) {
							// Build member list
							query_sql "SELECT `name` FROM `guild_member` WHERE `guild_id` = '"+ getcharid(2) +"'", .@member_list$;
						
							// Inject "Go back" option
							.@member_list$[getarraysize(.@member_list$)] = "Go back";
						
							// Add new member
							menu implode(.@member_list$, ":"), -;
							.@member_choice = @menu - 1;
							
							// Check if last option selected
							if (.@member_choice == getarraysize(.@member_list$)) {
								break;
							}
							
							// Add member's ID to SQL table
							message strcharinfo(0), "Granted guild storage access for '"+ .@member_list$[.@member_choice] +"'.";
							query_sql "SELECT `char_id` FROM `guild_member` WHERE `name` = '"+ .@member_list$[.@member_choice] +"'", .@member_id;
							query_sql "INSERT INTO `guild_storage_access` (`guild_id`, `char_id`) VALUES ('"+ getcharid(2) +"', '"+ .@member_id +"') ON DUPLICATE KEY UPDATE `guild_id` = '"+ getcharid(2) +"'";
							
							// Update existing ID in temporary global array
							for (.@i = 0; .@i < getarraysize($@GS_Member); .@i++) {
								if ($@GS_Member[.@i] == .@member_id) {
									$@GS_Guild[.@i] = getcharid(2);
									.@updated = 1;
									break;
								}
							}
							
							// Add new value in temporary global array
							if (!.@updated) {
								$@GS_Guild[getarraysize($@GS_Guild)] = getcharid(2);
								$@GS_Member[getarraysize($@GS_Member)] = .@member_id;
							}
							
							break;
						}
						
						// Revoke access
						switch (select("Revoke access:Go back")) {
							case 1:
								message strcharinfo(0), "Revoked guild storage access for '"+ .@access_list$[.@access_choice] +"'.";
								query_sql "SELECT `char_id` FROM `guild_member` WHERE `name` = '"+ .@access_list$[.@access_choice] +"'", .@member_id;
								query_sql "DELETE FROM `guild_storage_access` WHERE `char_id` = '"+ .@member_id +"'";
								
								// Clear entries in temporary global array
								for (.@i = 0; .@i < getarraysize($@GS_Member); .@i++) {
									if ($@GS_Member[.@i] == .@member_id) {
										deletearray $@GS_Guild[.@i], 1;
										deletearray $@GS_Member[.@i], 1;
									}
								}
								
								break;
						
							case 2:
								break;
						}
						
						break;
					
					case 3:
						close;
				}
			}
			
		// Guild member access
		} else if (getcharid(2)) {
			// Check permission
			for (.@i = 0; .@i < getarraysize($@GS_Member); .@i++) {
				// Open storage
				if ($@GS_Member[.@i] == getcharid(0) && $@GS_Guild[.@i] == getcharid(2)) {
					message strcharinfo(0), "Guild storage opened.";
					guildopenstorage();
					end;
				}
			}
				
			// Unauthorised access
			message strcharinfo(0), "You are not authorised to access guild storage.";
			
		// No guild
		} else {
			message strcharinfo(0), "You are not in a guild.";
		}
		
		// Fail message
		message strcharinfo(0), .@atcmd_command$ +" failed.";
		end;

}

And here's a quick script that'll clean any existing uses of the previous version:

-	script	clean_gs_access	-1,{

	OnInit:
		query_sql "SELECT `guild_id` FROM `guild`", .@guild_id;

		for (.@i = 0; .@i < getarraysize(.@guild_id); .@i++) {
			for (.@j = 0; .@j < getarraysize(getd("$GS_Auth_"+ .@i)); .@j++) {
				setd "$GS_Auth_"+ .@i +"["+ .@j +"]", 0;
			}
		}
		
		end;
	
}
Edited by Missingno
Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  127
  • Topics Per Day:  0.03
  • Content Count:  1445
  • Reputation:   163
  • Joined:  08/17/13
  • Last Seen:  

allright so i first install the second script, then the table and then the new script right o:?!

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  135
  • Reputation:   41
  • Joined:  02/05/14
  • Last Seen:  

Your original script wasn't void of SQL either... It actually runs a query for each member and subsequent conditions. >_< Honestly I'm not sure your attempt to "replacing the need for an SQL table" was even justified. Script looks nice though. :)

 

I suppose I had meant to say that I intended to replace the need for an SQL table to store access data; the queries in the previous version were to return a specific player's name or ID, for lack of an alternative method. Thanks for the feedback though; I concede that the revised version turned out much better, after some consideration.

Link to comment
Share on other sites


  • Group:  Forum Moderator
  • Topic Count:  33
  • Topics Per Day:  0.01
  • Content Count:  1268
  • Reputation:   382
  • Joined:  02/03/12
  • Last Seen:  

 

Your original script wasn't void of SQL either... It actually runs a query for each member and subsequent conditions. >_< Honestly I'm not sure your attempt to "replacing the need for an SQL table" was even justified. Script looks nice though. :)

 

I suppose I had meant to say that I intended to replace the need for an SQL table to store access data; the queries in the previous version were to return a specific player's name or ID, for lack of an alternative method. Thanks for the feedback though; I concede that the revised version turned out much better, after some consideration.

 

 

I agree :)

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  127
  • Topics Per Day:  0.03
  • Content Count:  1445
  • Reputation:   163
  • Joined:  08/17/13
  • Last Seen:  

mes "one day i will understand the whole topic here and will enter into a proactive debate like you two guys, thanks again o:!!";

 

mes "sorry for the last question, i just want to be sure,huh thanks again again o:!";

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  7
  • Topics Per Day:  0.00
  • Content Count:  135
  • Reputation:   41
  • Joined:  02/05/14
  • Last Seen:  

mes "one day i will understand the whole topic here and will enter into a proactive debate like you two guys, thanks again o:!!";

 

mes "sorry for the last question, i just want to be sure,huh thanks again again o:!";

 

Updated the script in my previous post (fixed an error with the SQL update for duplicate keys).

Link to comment
Share on other sites


  • Group:  Members
  • Topic Count:  127
  • Topics Per Day:  0.03
  • Content Count:  1445
  • Reputation:   163
  • Joined:  08/17/13
  • Last Seen:  

allright o:!

 

PS: ty so much both, my few players love this system o:!

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...