--script by smallg local length = {} local letter = {} local state = {} local pressed = 0 local correct = {} local guess = {} local letter_number = 0 local x = 30 local y = 80 local finalguess = "" function password_init_name(e,name) weapon_name[e] = name length[e] = string.len(weapon_name[e]) require "scriptbank//door" correct[e] = 0 state[e] = "start" finalguess = "" end function password_main(e) --Text(10,10,3,weapon_name[e]) --Text(10,15,3,finalguess) --Text(30,10,3,string.len(weapon_name[e])) --Text(30,15,3,string.len(finalguess)) if GetPlayerDistance(e) <= 200 then if state[e] == "start" then TextCenterOnX(50,90,3,"This door requires a password (E)") if GetScancode() == 18 then state[e] = "input" FreezePlayer() finalguess = "" pressed = 1 end elseif state[e] == "input" then Prompt("Let's see... the password was...") if pressed == 0 then if GetInKey() ~= "" then letter_number = letter_number + 1 guess[letter_number] = GetInKey() pressed = 1 end end if letter_number > 0 then local lx = 55 for a = letter_number, 1, -1 do lx = lx - 1 TextCenterOnX(lx,85,3,guess[a]) end --[[ --just used to prompt password on screen for debug finalguess = guess[1] for a = 2, letter_number do finalguess = string.format("%s %q",finalguess,guess[a]) end finalguess = string.gsub( finalguess, '"', "" ) finalguess = string.gsub( finalguess, "%s+", "" ) weapon_name[e] = string.gsub(weapon_name[e],'"',"") weapon_name[e] = string.gsub(weapon_name[e],"%s+","") --]] end if letter_number >= length[e] then finalguess = guess[1] for a = 2, letter_number do finalguess = string.format("%s %q",finalguess,guess[a]) end finalguess = string.gsub( finalguess, '"', "" ) finalguess = string.gsub( finalguess, "%s+", "" ) weapon_name[e] = string.gsub(weapon_name[e],'"',"") weapon_name[e] = string.gsub(weapon_name[e],"%s+","") if weapon_name[e] == finalguess then state[e] = "correct" else for a = 1, length[e] do guess[a] = "" end correct[e] = 0 letter_number = 0 UnFreezePlayer() PromptDuration("No.. that wasn't it..",2000) state[e] = "start" end end elseif state[e] == "correct" then --insert any code here to determine what happens once password is correctly entered --open a door/ box etc PromptDuration("correct!",2000) letter_number = 0 for a = 1, length[e] do guess[a] = "" end UnFreezePlayer() SwitchScript(e,"door") state[e] = "" end end if GetScancode() == 0 then pressed = 0 end --Prompt(GetInKey()) end --main