Advertisement
Skorm

Guild Warehouse v2.1

Jul 30th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.93 KB | None | 0 0
  1. /*/ make sure you run this query.
  2. CREATE TABLE IF NOT EXISTS `guild_password` (
  3.   `guild_id` int(11) unsigned NOT NULL default '0',
  4.   `operator` varchar(30) NOT NULL default '>=',
  5.   `position_condition` int(11) unsigned NOT NULL default '0',
  6.   `storage_password` varchar(30) NOT NULL default '',
  7.   PRIMARY KEY  (`guild_id`)
  8. ) ENGINE=MyISAM;
  9. /*/
  10. //SQL Version 2.1
  11. prontera,166,188,4  script  Guild Warehouse#v2  112,{
  12. //NPC file here!
  13.     cutin "kafra_06",2;
  14.     set .@a,getcharid(0);   set .@b,getcharid(2);   set .@z,getguildmasterid(.@b);
  15.     query_sql( "SELECT `storage_password` FROM `guild_password` WHERE `guild_id`='"+.@b+"' LIMIT 1",.@storage_pass$);
  16.  
  17.     mes "[Guild Warehouse Coupler]";
  18.     mes "This is the guild warehouse coupler service.";
  19.     next;
  20.     menu "Access Guild Warehouse", GS_OPEN, "Set Guild Warehouse Password", GS_PASS, "Exit", GS_EXIT3;
  21.  
  22. GS_OPEN:
  23.     if(query_sql( "SELECT `operator`,`position_condition` FROM `guild_password` WHERE `guild_id`="+.@b+" LIMIT 1;",.@opr$,.@pos_cnd)){
  24.         query_sql("SELECT `char_id` FROM `guild_member` WHERE `position` "+.@opr$+" "+escape_sql(.@pos_cnd)+" AND `guild_id` = "+.@b+" AND `char_id` = "+.@a+";",.@h);
  25.         if(.@a!=.@h) {
  26.             mes "Guild storage is restricted by guild position.";
  27.             mes "Contact your guild master for information regarding the guild positions.";
  28.             goto GS_EXIT4;
  29.         }
  30.     }
  31.     if(.@storage_pass$!=""){
  32.         mes "Please input your guilds password."; input(.@gspass$);
  33.         if(.@gspass$==.@storage_pass$)
  34.             mes "Welcome!";
  35.         else {
  36.             mes "I'm sorry but that's incorrect, please try again later.";
  37.             goto GS_EXIT4;
  38.         }
  39.     }
  40.     set @flag,guildopenstorage;
  41.     if(@flag == 1) goto GS_EXIT1;
  42.     if(@flag == 2) goto GS_EXIT2;
  43.     goto GS_EXIT4;
  44.  
  45. GS_PASS:
  46.     if(!.@b) { mes "I'm sorry but you don't have a guild."; goto GS_EXIT4; }
  47.     if(.@z!=.@a){ mes "I'm sorry but you're not the leader of "+strcharinfo(2)+"."; goto GS_EXIT4; }
  48.     if(.@storage_pass$!=""){ mes "Did you forget, your guild password is "+.@storage_pass$+". Do you still want to change it?"; if(select("Yes:No")-1) goto GS_EXIT4; }
  49.     mes "Please Input your new guild password.";
  50.     input(.@pass$);
  51.     while(.@pass$!=.@gspass2$){
  52.         mes "Again.";   input(.@gspass2$);  set .@p,.@p+1;
  53.         if(.@p>1){
  54.             mes "I'm sorry, but your passwords didn't match, please try again."; goto GS_PASS;
  55.         }
  56.     }
  57.     if(query_sql("SELECT `guild_id` FROM `guild_password` WHERE `guild_id`="+.@b+";",.@gid))
  58.         query_sql("UPDATE `guild_password` SET `storage_password`='"+.@pass$+"' WHERE `guild_id`="+.@b+";");
  59.     else
  60.         query_sql("INSERT INTO `guild_password` (`guild_id`,`storage_password`) VALUES ("+.@b+",'"+.@pass$+"');");
  61.     mes .@pass$+", has been set as your password.";
  62.     goto GS_EXIT4;
  63.    
  64. GS_EXIT1:
  65.     mes "[Guild Warehouse]";
  66.     mes "The guild warehouse is being used right now.";
  67.     mes "Please wait a while, then come back.";
  68.     goto GS_EXIT4;
  69.  
  70. GS_EXIT2:
  71.     mes "[Guild Warehouse]";
  72.     mes "You can't use this service if you're not in a guild!";
  73.     goto GS_EXIT4;
  74.  
  75. GS_EXIT3:
  76.     mes "[Guild Warehouser]";
  77.     mes "Come back whenever you want.";
  78.  
  79. GS_EXIT4:
  80.     cutin "kafra_06",255;
  81.     close;
  82.  
  83. //Add to other guildstorage npcs.
  84. //donpcevent "Guild Warehouse::GS_OPEN";
  85.  
  86. //@command part starts here!
  87. //SQL Version 2
  88. OnInit:
  89.     bindatcmd "gspw",strnpcinfo(3)+"::OnPassword";
  90.     bindatcmd "gscurb",strnpcinfo(3)+"::OnRestriction";
  91.     bindatcmd "guildstorage",strnpcinfo(3)+"::OnStorage";
  92.     end;
  93.  
  94. OnPassword:
  95.     set .@a,getcharid(0);   set .@b,getcharid(2);
  96.     set .@pass$,(.@atcmd_parameters$[0]!="")?
  97.         "'"+escape_sql(.@atcmd_parameters$[0])+"'":"DEFAULT";
  98.  
  99.     if(getguildmasterid(.@b)!=.@a) dispbottom "Only a guild leader may use this command.";
  100.     else {
  101.         if(query_sql("SELECT `guild_id` FROM `guild_password` WHERE `guild_id`="+.@b+";",.@gid))
  102.             .@message$=!query_sql("UPDATE `guild_password` SET `storage_password`="+.@pass$+" WHERE `guild_id`="+.@b+" LIMIT 1;")?
  103.                 "Updated Guild Storage Password: "+.@atcmd_parameters$[0]+"!":"";
  104.         else
  105.             .@message$=!query_sql("INSERT INTO `guild_password` (`guild_id`,`storage_password`) VALUES ("+.@b+","+.@pass$+");")?
  106.                 "Guild Storage Password Created: "+.@atcmd_parameters$[0]+"!":"";
  107.         .@message$=(.@atcmd_parameters$[0]=="")?
  108.             "Guild password has been reset!":.@message$;
  109.         dispbottom(.@message$);
  110.     }
  111.     end;
  112.  
  113. OnRestriction:
  114.     set .@a,getcharid(0);   set .@b,getcharid(2);
  115.     setarray .@p$[0],">","=","<",">=","<=","";
  116.     setarray .@g$[0],"greater than","equal to",
  117.         "less than","greater than or equal to",
  118.         "less than or equal to","";
  119.     set .@d$,(.@atcmd_parameters$[0]!="")?
  120.         "'"+.@atcmd_parameters$[0]+"'":"DEFAULT";
  121.     set .@q$,.@atcmd_parameters$[1]?
  122.         .@atcmd_parameters$[1]:"DEFAULT";
  123.  
  124.     if(getguildmasterid(.@b)!=.@a) dispbottom "Only a guild leader may use this command.";
  125.     else {
  126.         query_sql("SELECT `name` FROM `guild_position` WHERE `position` = '"+ .@atcmd_parameters$[1] +"' AND `guild_id` = '"+ .@b +"';",.@b$);
  127.         while(.@atcmd_parameters$[0]!=.@p$[.@i]) {
  128.             if(.@i==getarraysize(.@p$)){
  129.                 dispbottom .@atcmd_parameters$[0]+" isn't a valid parameter, try: >, =, <, >=, <=";
  130.                 dispbottom "Try: @gscurb <operator> <position#>";
  131.                 end;
  132.             }
  133.             set .@i,.@i+1;
  134.         }
  135.         query_sql("SELECT `guild_id` FROM `guild_password` WHERE `guild_id`='"+.@b+"' LIMIT 1;",.@gid);
  136.         if(.@gid){
  137.             query_sql("UPDATE `guild_password` SET `operator`="+.@d$+",`position_condition`="+escape_sql(.@q$)+" WHERE `guild_id`='"+.@b+"' LIMIT 1;");
  138.             .@message$=(.@atcmd_parameters$[1]!=""&&.@atcmd_parameters$[0]!="")?
  139.                 "Members "+.@g$[.@i]+" ["+.@b$+"] have access to guild storage.":"Guild storage restriction has been lifted! Try: @gscurb <operator> <position#>";
  140.             dispbottom(.@message$);
  141.         } else {
  142.             query_sql("INSERT INTO `guild_password` (`guild_id`,`operator`,`position_condition`) VALUES ("+getcharid(2)+","+escape_sql(.@d$)+","+escape_sql(.@q$)+");");
  143.             dispbottom("Members "+.@g$[.@i]+" ["+.@b$+"] have access to guild storage.");
  144.         }
  145.     }
  146.     end;
  147.  
  148. OnStorage:
  149.     set .@a,getcharid(0);   set .@b,getcharid(2);
  150.  
  151.     if(!.@b) { dispbottom "You need a guild to use this command."; end; }
  152.     if(query_sql( "SELECT `operator`,`position_condition` FROM `guild_password` WHERE `guild_id`="+.@b+" LIMIT 1;",.@opr$,.@pos_cnd)){
  153.         query_sql("SELECT `char_id` FROM `guild_member` WHERE `position` "+.@opr$+" "+escape_sql(.@pos_cnd)+" AND `guild_id` = "+.@b+" AND `char_id` = "+.@a+";",.@h);
  154.         if(.@a!=.@h) {
  155.             dispbottom "Guild storage is restricted by guild position. Contact your guild master for information regarding guild positions.";
  156.             end;
  157.         }
  158.     }
  159.     query_sql( "SELECT `storage_password` FROM `guild_password` WHERE `guild_id`="+.@b+";",.@storage_pass$);
  160.     if(.@storage_pass$!=""){
  161.         if(.@atcmd_parameters$[0]==.@storage_pass$ ) {
  162.             set .@z, guildopenstorage();
  163.         } else {
  164.             dispbottom "Wrong password contact your guild master for information!";
  165.         }
  166.     } else {
  167.         set .@z, guildopenstorage();
  168.     }
  169.     if(.@z) {
  170.         set .@message$, (.@z&2)?
  171.             "The guild warehouse is in use right now!":"You can't use this service if you're not in a guild!";
  172.         dispbottom(.@message$);
  173.     }
  174.     end;
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement