// @unloadnpc at_guildpack
// @loadnpc npc/thor/guildpack/at_guildpack.txt

-	script	at_guildpack	-1,{
end;
    OnInit:
    	bindatcmd "gp","at_guildpack::OnAdd", 99, 99;
    	end;


OnAdd:
	set .@gm_id,getcharid(3);
	mes " Hello GM ^00CC00"+strcharinfo(0)+"^000000!";
	mes "Input Player Name to register:";
	next;
	input .@chrnm$;
	query_sql "SELECT `char_id`, `account_id`, `class`, `base_level`, `job_level` FROM `char` WHERE `name` = '" + .@chrnm$ + "'",.@char_id,.@account_id, .@class, .@blvl, .@jlvl;
	if (!.@char_id) { 
		mes " I'm sorry GM ^00CC00"+strcharinfo(0)+"^000000 but I could not find that character or account.";
		mes " Please verify if you dind't make a typo.";
		close();
	}
	query_sql "SELECT `last_unique_id` FROM login WHERE account_id = "+.@account_id,.@unique$;
	mes "Character Information";
	mes "- - - - - - - - - -";
	mes "Name: ^83cfe9"+.@chrnm$+"^000000";
	mes "Acct#: ^83cfe9"+.@account_id+"^000000";
	mes "Char#: ^83cfe9"+.@char_id+"^000000";
	mes "Job: ^83cfe9"+jobname(.@class)+"^000000 - Lvl: ^83cfe9"+.@blvl+"^000000/^ff0000"+.@jlvl+"^000000";
	mes "UniqueID:  ^83cfe9"+.@unique$+"^000000";
	mes "Please verify information.  Do you wish to proceed?";
	next;
	if (select("No - Let me try again.", "Yes, That's correct.") == 2) {
		if (query_sql("SELECT `last_unique_id`, `name` FROM guildpack WHERE `last_unique_id`="+.@unique$,.@dummy$,.@dummy2$) == 0) {
			query_sql "INSERT INTO `guildpack` (`timestamp`,`account_id`,`char_id`,`name`,`isclaimed`,`claimdate`,`last_unique_id`) VALUES ('"+gettimestr("%Y-%m-%d %H:%M:%S",21)+"',"+.@account_id+","+.@char_id+",'"+escape_sql(.@chrnm$)+"',0,'0000-00-00 00:00:00',"+escape_sql(.@unique$)+")";
			dispbottom "Transaction completed.";
		} else {
			dispbottom "Sorry, machineID: "+.@dummy$+" has been used to claim guild pack by "+.@dummy2$;
		}
	}
	close();
}
