// @unloadnpc abuse
// @loadnpc npc/thor/abuse.txt

-	script	give	-1,{
    OnInit:
    	bindatcmd "give","give::OnReward", 1, 99;
    	end;


OnReward:
	set .@gm_id,getcharid(3);
    	mes " Hello GM ^00CC00"+strcharinfo(0)+"^000000!";
	mes "Player Name:";
	input .@chrnm$;
	query_sql "SELECT `char_id`, `account_id` FROM `char` WHERE `name` = '" + .@chrnm$ + "'",.@char_id,.@account_id;
	if (!.@char_id) { 
		mes " I'm Sorry but I couldn't find that character or account.";
		mes " Please verify if you dind't make a typo.";
		close;
	}
	next;
	mes "[ ^0000FFReward Info^000000 ]";
	mes "Player: ^00CC00"+.@chrnm$+"^000000";
	mes " Event:";
	input .@event$;
	next;
	mes "[ ^0000FFReward Info^000000 ]";
	mes "Player: ^00CC00"+.@chrnm$+"^000000";
	mes " Event: ^00CC00"+.@event$+"^000000";
	next;
	// Display Category List
	set .@Menu$,"";	
	set .@reward,query_sql(" SELECT `nameid`,`qty` FROM item_reward",.@nameid, .@qty);
	for( set .@i,0; .@i < .@reward; set .@i,.@i + 1 )
		set .@Menu$,.@Menu$ + "^FF0000[ "+( .@i+1 )+". ]^0000FF "+.@qty[.@i]+"x "+getitemname(.@nameid[.@i])+":";
	set .@Select,select( .@Menu$ ) - 1;
	set .@rnameid,.@nameid[.@Select];
	set .@rqty,.@qty[.@Select];
	mes "[ ^0000FFReward Info^000000 ]";
	mes "Player: ^00CC00"+.@chrnm$+"^000000";
	mes " Event: ^00CC00"+.@event$+"^000000";
	mes "Reward: ^00CC00"+getitemname(.@rnameid)+" x "+.@rqty+"^000000";
	mes "Is this correct?";
	next;
	switch(select("No:Yes, Proceed with the reward.")) {
		case 1:
			close();
		case 2:
			//query_sql "INSERT INTO rules_log (`account_id`,`char_id`, `name`,`rcat_id`,`vdate`,`count`, `status`, `ban_type`,`ban_until`, `ref`) VALUES ("+.@account_id+","+.@char_id+",'"+escape_sql(.@chrnm$)+"',"+.@rcat_id[.@Select]+",'"+gettimestr("%Y-%m-%d %H:%M:%S",21)+"',"+(.@count+1)+",1,1,'0000-00-00 00:00:00','"+escape_sql(.@ref$)+"'"")";
			close();
		defualt:
			close();
		
	}
	end;
}

/*
	// Check Counts & Penalty
	query_sql "SELECT count(rcat_id) FROM rules_log WHERE `rcat_id` = "+.@rcat_id+" AND `account_id` = "+.@account_id,.@count;
	sleep2 100;
	query_sql "SELECT `penalty1`,`penalty2`,`penalty3` FROM rules_cat WHERE `rcat_id` = "+.@rcat_id,.@penalty1,.@penalty2,.@penalty3;
	if(!.@count) 		{ 	set .@penalty, .@penalty1; set .@countxt$,"1st";
	} else if (.@count==1) 	{	set .@penalty, .@penalty2; set .@countxt$,"2nd";
	} else 			{ 	set .@penalty, .@penalty3; set .@countxt$,"3rd";
	}

	if(.@penalty==3) { set .@penalty$,"PERMA JAIL"; set .@penalty1,0;
	} else if(.@penalty >= 100 && .@penalty <=199) 	{ set .@penalty$,"H JAIL"; set .@penalty1,.@penalty-100;
	} else if(.@penalty >= 200 && .@penalty <=299) 	{ set .@penalty$,"D BAN"; set .@penalty1,.@penalty-200;
	} else { set .@penalty$,"BLOCK"; set .@penalty1,.@penalty-300;
	}
	
	mes "^FF0000BAD POINTS TRANSACTION^000000";
	mes "^FF0000Player^000000 : "+.@chrnm$;
	mes "^FF0000Remarks:^000000 : "+.@rcat_desc$;
	mes "^FF0000Count:^000000 : "+.@countxt$+" Offense";
	mes "^FF0000Penalty:^000000 : "+.@penalty1+" "+.@penalty$;
	mes "Do you wish to continue?";
	next;
	switch(select("No:Yes, Proceed with the badpoints.")) {
	case 1:
		mes "^FF0000BAD POINTS TRANSACTION^000000";
		mes "Okay, come back when you are ready!!!";
		close;
	case 2:
		if(.@penalty==3) { 
			atcommand "@kick "+.@chrnm$;
			query_sql "INSERT INTO rules_log (`account_id`,`char_id`, `name`,`rcat_id`,`vdate`,`count`, `status`, `ban_type`,`ban_until`, `ref`) VALUES ("+.@account_id+","+.@char_id+",'"+escape_sql(.@chrnm$)+"',"+.@rcat_id[.@Select]+",'"+gettimestr("%Y-%m-%d %H:%M:%S",21)+"',"+(.@count+1)+",1,1,'0000-00-00 00:00:00','"+escape_sql(.@ref$)+"'"")";
			query_sql "UPDATE `char` SET `last_map`='"+escape_sql(.jailmap$)+"', `last_x`="+.jailx+", `last_y`="+.jaily+" WHERE `char_id`="+.@char_id;
			query_sql "UPDATE `char` SET `save_map`='"+escape_sql(.jailmap$)+"', `save_x`="+.jailx+", `save_y`="+.jaily+" WHERE `char_id`="+.@char_id;
			next;
			mes "^FF0000BAD POINTS TRANSACTION^000000";
			mes "^FF0000Status:^000000 : Completed"; 
			close;
		}

		if(.@penalty >= 100 && .@penalty <=199) { 
			atcommand "@kick "+.@chrnm$;
			query_sql "INSERT INTO rules_log (`account_id`,`char_id`, `name`,`rcat_id`,`vdate`,`count`, `status`, `ban_type`,`ban_until`, `ref`) VALUES ("+.@account_id+","+.@char_id+",'"+escape_sql(.@chrnm$)+"',"+.@rcat_id[.@Select]+",'"+gettimestr("%Y-%m-%d %H:%M:%S",21)+"',"+(.@count+1)+",1,1,'0000-00-00 00:00:00','"+escape_sql(.@ref$)+"'"")";
			next;
			mes "^FF0000BAD POINTS TRANSACTION^000000";
			mes "^FF0000Status:^000000 : Completed"; 
			close;
		}
		if(.@penalty >= 200 && .@penalty <=299) { 
			set .@penalty,.@penalty-200; 	
			atcommand "@ban +"+.@penalty+"d "+.@chrnm$;
			query_sql "INSERT INTO rules_log (`account_id`,`char_id`,`name`,`rcat_id`,`vdate`,`count`, `status`, `ban_type`,`ban_until`, `ref`) VALUES ("+.@account_id+","+.@char_id+",'"+escape_sql(.@chrnm$)+"',"+.@rcat_id[.@Select]+",'"+gettimestr("%Y-%m-%d %H:%M:%S",21)+"',"+(.@count+1)+",1,2,'"+gettimestr("%Y-%m-%d %H:%M:%S",21)+"','"+escape_sql(.@ref$)+"'"")";
			sleep2 100;
			query_sql ("UPDATE rules_log SET status = 0, ban_until = DATE_ADD(vdate, INTERVAL "+.@penalty+" DAY) WHERE rcat_id = "+.@rcat_id+" AND status = 1 AND account_id= "+.@account_id+";");
		}
	
		if(.@penalty == 300 ) { 
			atcommand "@block "+.@chrnm$;
			query_sql "INSERT INTO rules_log (`account_id`,`char_id`,`name`,`rcat_id`,`vdate`,`count`, `status`, `ban_type`,`ban_until`, `ref`) VALUES ("+.@account_id+","+.@char_id+",'"+escape_sql(.@chrnm$)+"',"+.@rcat_id[.@Select]+",'"+gettimestr("%Y-%m-%d %H:%M:%S",21)+"',"+(.@count+1)+",0,3,'0000-00-00 00:00:00','"+escape_sql(.@ref$)+"'"")";
		}
		next;
		mes "^FF0000BAD POINTS TRANSACTION^000000";
		mes "^FF0000Status:^000000 : Completed";
	}
	close;

OnPCLoginEvent:
	//Bad Points
	query_sql "SELECT `rcat_id` FROM rules_log WHERE `status` = 1 AND `rcat_id`= 1 AND `char_id` = "+getcharid(0),.@rcat_id;
	if (.@rcat_id) { 
		savepoint "office",83,65;	
		warp "office",83,65;
		sleep2 100;
		query_sql ("UPDATE rules_log SET status = 0, ban_until = DATE_ADD(vdate, INTERVAL 3 YEAR) WHERE rcat_id = "+.@rcat_id+" AND status = 1 AND char_id= "+getcharid(0)+";");
		end;
	}
	query_sql "SELECT `rcat_id` FROM rules_log WHERE `status` = 1 AND `account_id` = "+getcharid(3),.@rcat_id;
	if (.@rcat_id) { 
		query_sql "SELECT count(rcat_id) FROM rules_log WHERE `rcat_id` = "+.@rcat_id+" AND `account_id` = "+getcharid(3),.@count;
		query_sql "SELECT `penalty1`,`penalty2`,`penalty3` FROM rules_cat WHERE `rcat_id` = "+.@rcat_id,.@penalty1,.@penalty2,.@penalty3;
		if(.@count==1) { set .@penalty, .@penalty1; } if(.@count==2) { set .@penalty, .@penalty2; } if(.@count==3) { set .@penalty, .@penalty3; }
		if(.@penalty >= 100 && .@penalty <=199) { set .@penalty,.@penalty-100;
			savepoint "office",83,65;	
			warp "office",83,65;
	 	}
		sleep2 100;
		query_sql ("UPDATE rules_log SET status = 0, ban_until = DATE_ADD(vdate, INTERVAL "+.@penalty+" HOUR) WHERE rcat_id = "+.@rcat_id+" AND status = 1 AND account_id= "+getcharid(3)+";");
	}
	end;


}
*/