Here: is a working script. lenght is variable in the password array. If some problems exist or you have some questions, feel free to ask (PM)
Use it as you want, delete the debug code(PromptDuration).
numberpad_pressed = 0
local one_key = "1"
local two_key = "2"
local three_key = "3"
local four_key = "4"
local five_key = "5"
local six_key = "6"
local seven_key = "7"
local eight_key = "8"
local nine_key = "9"
local zero_key = "0"
local star_key = "*"
local hashtag_key = "#"
local password = {2,3,4,5}
local numberpadPressQuantity = 1
local whichKeyIsPressed =""
function keypad_init(e)
end
function keypad_main(e)
PlayerDist = GetPlayerDistance(e);
if PlayerDist < 150 and GetInKey() == one_key and numberpad_pressed==0 then
whichKeyIsPressed= one_key
numberpad_pressed=1
if password[numberpadPressQuantity] == 1 then
numberpadPressQuantity = numberpadPressQuantity + 1
PromptDuration("Right",1000)
else
--wrong number reset it, maybe a sound here would be cool
numberpadPressQuantity = 1
PromptDuration("Wrong",1000)
end
SetAnimation(0);
PlayAnimation(e);
end
if PlayerDist < 150 and GetInKey() == two_key and numberpad_pressed==0 then
numberpad_pressed=1
whichKeyIsPressed= two_key
if password[numberpadPressQuantity] == 2 then
numberpadPressQuantity = numberpadPressQuantity + 1
PromptDuration("Right",1000)
else
numberpadPressQuantity = 1
PromptDuration("Wrong",1000)
end
SetAnimation(1);
PlayAnimation(e);
end
if PlayerDist < 150 and GetInKey() == three_key and numberpad_pressed==0 then
numberpad_pressed=1
whichKeyIsPressed= three_key
if password[numberpadPressQuantity] == 3 then
numberpadPressQuantity = numberpadPressQuantity + 1
PromptDuration("Right",1000)
else
numberpadPressQuantity = 1
PromptDuration("Wrong",1000)
end
SetAnimation(2);
PlayAnimation(e);
end
if PlayerDist < 150 and GetInKey() == four_key and numberpad_pressed==0 then
numberpad_pressed=1
whichKeyIsPressed= four_key
if password[numberpadPressQuantity] == 4 then
numberpadPressQuantity = numberpadPressQuantity + 1
PromptDuration("Right",1000)
else
numberpadPressQuantity = 1
PromptDuration("Wrong",1000)
end
SetAnimation(3);
PlayAnimation(e);
end
if PlayerDist < 150 and GetInKey() == five_key and numberpad_pressed==0 then
numberpad_pressed=1
whichKeyIsPressed= five_key
if password[numberpadPressQuantity] == 5 then
numberpadPressQuantity = numberpadPressQuantity + 1
PromptDuration("Right",1000)
else
numberpadPressQuantity = 1
PromptDuration("Wrong",1000)
end
SetAnimation(4);
PlayAnimation(e);
end
if PlayerDist < 150 and GetInKey() == six_key and numberpad_pressed==0 then
numberpad_pressed=1
whichKeyIsPressed= six_key
if password[numberpadPressQuantity] == 6 then
numberpadPressQuantity = numberpadPressQuantity + 1
PromptDuration("Right",1000)
else
numberpadPressQuantity = 1
PromptDuration("Wrong",1000)
end
SetAnimation(5);
PlayAnimation(e);
end
if PlayerDist < 150 and GetInKey() == seven_key and numberpad_pressed==0 then
numberpad_pressed=1
whichKeyIsPressed= seven_key
if password[numberpadPressQuantity] == 7 then
numberpadPressQuantity = numberpadPressQuantity + 1
PromptDuration("Right",1000)
else
numberpadPressQuantity = 1
PromptDuration("Wrong",1000)
end
SetAnimation(6);
PlayAnimation(e);
end
if PlayerDist < 150 and GetInKey() == eight_key and numberpad_pressed==0 then
numberpad_pressed=1
whichKeyIsPressed= eight_key
if password[numberpadPressQuantity] == 8 then
numberpadPressQuantity = numberpadPressQuantity + 1
PromptDuration("Right",1000)
else
numberpadPressQuantity = 1
PromptDuration("Wrong",1000)
end
SetAnimation(7);
PlayAnimation(e);
end
if PlayerDist < 150 and GetInKey() == nine_key and numberpad_pressed==0 then
numberpad_pressed=1
whichKeyIsPressed= nine_key
if password[numberpadPressQuantity] == 9 then
numberpadPressQuantity = numberpadPressQuantity + 1
PromptDuration("Right",1000)
else
numberpadPressQuantity = 1
PromptDuration("Wrong",1000)
end
SetAnimation(8);
PlayAnimation(e);
end
if PlayerDist < 150 and GetInKey() == zero_key and numberpad_pressed==0 then
numberpad_pressed=1
whichKeyIsPressed= zero_key
if password[numberpadPressQuantity] == 0 then
numberpadPressQuantity = numberpadPressQuantity + 1
else
numberpadPressQuantity = 1
end
SetAnimation(10);
PlayAnimation(e);
end
if PlayerDist < 150 and GetInKey() == star_key then
whichKeyIsPressed= star_key
SetAnimation(9);
PlayAnimation(e);
end
if PlayerDist < 150 and GetInKey() == hashtag_key then
whichKeyIsPressed= hashtag_key
SetAnimation(11);
PlayAnimation(e);
end
if numberpadPressQuantity == 5 then
--Open door for example
ActivateIfUsed(e)
end
if GetInKey() ~= whichKeyIsPressed then
numberpad_pressed=0
end
end
sorry it is not optimized and commented, but I did not have much time. I hope this helps.
Exited what you will do with my script. I need switches, so when do you release them?
Corno_1
My dream is to develope games, which makes fun when I create it and fun when other people play it.