#include <define.h>

//#define NAME                    SCRIPT_

#include <command.h>
//#include <ModReact.h>



procedure start;
#include <push.h>
procedure Traps;
procedure Sciences;
procedure Picklocks;
procedure Using_Door;

variable Shocked;


procedure start
begin
	if (global_var(GVAR_WEAPON_LOCKER) == 2) then begin
		set_local_var(1, 1);
	end
	if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
		script_overrides;
		display_msg(message_str(SCRIPT_GLO4WEAP, 100));
	end
	else begin
		if (script_action == use_proc) then begin
			if (global_var(GVAR_WEAPON_LOCKER) != 2) then begin
				set_global_var(GVAR_WEAPON_LOCKER, 1);
			end
			call Using_Door;
		end
		else begin
			if (script_action == use_skill_on_proc) then begin
				if (global_var(GVAR_WEAPON_LOCKER) != 2) then begin
					set_global_var(GVAR_WEAPON_LOCKER, 1);
				end
				if (action_being_used == 9) then begin
					call Picklocks;
				end
				else begin
					if (action_being_used == 11) then begin
						call Traps;
					end
					else begin
						if (action_being_used == 12) then begin
							call Sciences;
						end
						else begin
							display_msg(message_str(SCRIPT_GLO4WEAP, 101));
						end
					end
				end
			end
			else begin
				if (script_action == use_obj_on_proc) then begin
					if (global_var(GVAR_WEAPON_LOCKER) != 2) then begin
						set_global_var(GVAR_WEAPON_LOCKER, 1);
					end
					if (obj_pid(obj_being_used_with) == 96) then begin
						if (local_var(1) == 0) then begin
							script_overrides;
							Shocked := random(3, 7);
							critter_dmg(dude_obj, Shocked, 0);
							display_msg(message_str(SCRIPT_GLO4WEAP, 102) + Shocked + message_str(SCRIPT_GLO4WEAP, 103));
							set_local_var(0, local_var(0) + 1);
						end
						else begin
							if (local_var(2) == 0) then begin
								script_overrides;
								set_local_var(2, 1);
								display_msg(message_str(SCRIPT_GLO4WEAP, 104));
							end
						end
					end
					else begin
						display_msg(message_str(SCRIPT_GLO4WEAP, 105));
					end
				end
			end
		end
	end
end

procedure Traps
begin
	if (local_var(1) == 0) then begin
		if (is_success(roll_vs_skill(dude_obj, 11, 0))) then begin
			set_local_var(1, 1);
			display_msg(message_str(SCRIPT_GLO4WEAP, 113));
		end
		else begin
			set_local_var(0, 5);
			Shocked := random(2, local_var(0));
			critter_dmg(dude_obj, Shocked, 0);
			display_msg(message_str(SCRIPT_GLO4WEAP, 114) + Shocked + message_str(SCRIPT_GLO4WEAP, 115));
			set_local_var(0, local_var(0) + 1);
		end
	end
	else begin
		display_msg(message_str(SCRIPT_GLO4WEAP, 116));
	end
end

procedure Sciences
begin
	if (local_var(1) == 0) then begin
		if (is_success(roll_vs_skill(dude_obj, 12, 0))) then begin
			set_local_var(1, 1);
			display_msg(message_str(SCRIPT_GLO4WEAP, 117));
		end
		else begin
			set_local_var(0, 5);
			Shocked := random(2, local_var(0));
			critter_dmg(dude_obj, Shocked, 0);
			display_msg(message_str(SCRIPT_GLO4WEAP, 118) + Shocked + message_str(SCRIPT_GLO4WEAP, 119));
			set_local_var(0, local_var(0) + 1);
		end
	end
	else begin
		display_msg(message_str(SCRIPT_GLO4WEAP, 120));
	end
end

procedure Picklocks
begin
	if (local_var(1) == 0) then begin
		if (local_var(0) > 2) then begin
			Shocked := random(2, local_var(0));
			critter_dmg(dude_obj, Shocked, 0);
			display_msg(message_str(SCRIPT_GLO4WEAP, 121) + Shocked + message_str(SCRIPT_GLO4WEAP, 122));
			set_local_var(0, local_var(0) + 1);
		end
		else begin
			set_local_var(0, local_var(0) + 1);
			display_msg(message_str(SCRIPT_GLO4WEAP, 123));
		end
	end
	else begin
		if (is_success(roll_vs_skill(dude_obj, 9, 0))) then begin
			set_local_var(2, 1);
			display_msg(message_str(SCRIPT_GLO4WEAP, 124));
		end
		else begin
			display_msg(message_str(SCRIPT_GLO4WEAP, 125));
		end
	end
end

procedure Using_Door
begin
	if (local_var(1) == 0) then begin
		script_overrides;
		if (local_var(0) > 2) then begin
			Shocked := random(2, local_var(0));
			critter_dmg(dude_obj, Shocked, 0);
			display_msg(message_str(SCRIPT_GLO4WEAP, 106) + Shocked + message_str(SCRIPT_GLO4WEAP, 107));
			set_local_var(0, local_var(0) + 1);
		end
		else begin
			set_local_var(0, local_var(0) + 1);
			display_msg(message_str(SCRIPT_GLO4WEAP, 108));
		end
	end
	else begin
		if (local_var(2) == 0) then begin
			script_overrides;
			display_msg(message_str(SCRIPT_GLO4WEAP, 109));
			if (is_success(do_check(dude_obj, 1, 0))) then begin
				display_msg(message_str(SCRIPT_GLO4WEAP, 110));
			end
			else begin
				if (is_success(roll_vs_skill(dude_obj, 11, 0))) then begin
					display_msg(message_str(SCRIPT_GLO4WEAP, 111));
				end
				else begin
					display_msg(message_str(SCRIPT_GLO4WEAP, 112));
				end
			end
		end
	end
end