Hey guys,
I'm returning to work on my game, and now I'm preparing a new map. I decided to include skillcheck for some actions (like stealing a tool from somewhere). Since i'm basic in programming, the code ended up huge, but with simple language, easy to edit.
Heres the code (attach to non static object):
function skillcheck1_init(e)
flag = 0
timer = {}
second = 0
g_test = 0
end
function skillcheck1_main(e)
if GetPlayerDistance(e) < 70 and g_test == 0 then
PromptLocal(e,"[E] Steal")
if g_KeyPressE == 1 then
second = 0
g_test = 1
StartTimer(e)
FreezePlayer()
end
end
if timer[1] == nil then
timer[1] = g_Time + 1000
elseif g_Time > timer[1] then
timer[1] = g_Time + 1000
second = second + 1
end
if g_test == 1 then
TextColor(50,40,5,"SKILL CHECK [ 0%]",252,255,51)
end
if g_test == 2 then
TextColor(50,40,5,"SKILL CHECK [25%]",252,255,51)
end
if g_test == 3 then
TextColor(50,40,5,"SKILL CHECK [47%]",252,255,51)
end
if g_test == 4 then
TextColor(50,40,5,"SKILL CHECK [68%]",252,255,51)
end
if g_test == 5 then
TextColor(50,40,5,"SKILL CHECK [82%]",252,255,51)
end
if g_test == 6 then
TextColor(50,40,5,"SKILL CHECK [94%]",252,255,51)
end
if g_test == 1 then
TextColor(50,50,5,"PRESS A",252,255,51)
end
if g_test == 2 and second >= 1 then
TextColor(50,50,5,"PRESS W",252,255,51)
end
if g_test == 3 and second >= 1 then
TextColor(50,50,5,"PRESS S",252,255,51)
end
if g_test == 4 and second >= 1 then
TextColor(50,50,5,"PRESS S",252,255,51)
end
if g_test == 5 and second >= 1 then
TextColor(50,50,5,"PRESS A",252,255,51)
end
if g_test == 6 and second >= 1 then
TextColor(50,50,5,"PRESS W",252,255,51)
end
------------------------------------------------------------------------------
if g_test == 1 and second <= 1 and g_KeyPressA == 1 then
g_test = 2
second = 0
g_KeyPressA = 0
PlaySound(e,0)
end
if g_test == 1 and second > 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 1 and g_KeyPressW == 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 1 and g_KeyPressS == 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 1 and g_KeyPressD == 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
------------------------------------------------------------------------------
if g_test == 2 and second <= 2 and g_KeyPressW == 1 and second >= 1 then
g_test = 3
second = 0
g_KeyPressW = 0
PlaySound(e,0)
end
if g_test == 2 and second > 2 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 2 and g_KeyPressA == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 2 and g_KeyPressS == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 2 and g_KeyPressD == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
------------------------------------------------------------------------------
if g_test == 3 and second <= 2 and g_KeyPressS == 1 and second >= 1 then
g_test = 4
second = 0
g_KeyPressS = 0
PlaySound(e,0)
end
if g_test == 3 and second > 2 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 3 and g_KeyPressA == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 3 and g_KeyPressW == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 3 and g_KeyPressD == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
------------------------------------------------------------------------------
if g_test == 4 and second <= 2 and g_KeyPressS == 1 and second >= 1 then
g_test = 5
second = 0
g_KeyPressS = 0
PlaySound(e,0)
end
if g_test == 4 and second > 2 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 4 and g_KeyPressA == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 4 and g_KeyPressW == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 4 and g_KeyPressD == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
------------------------------------------------------------------------------
if g_test == 5 and second <= 2 and g_KeyPressA == 1 and second >= 1 then
g_test = 6
second = 0
g_KeyPressA = 0
PlaySound(e,0)
end
if g_test == 5 and second > 2 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 5 and g_KeyPressW == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 5 and g_KeyPressS == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 5 and g_KeyPressD == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
------------------------------------------------------------------------------
if g_test == 6 and second <= 2 and g_KeyPressW == 1 and second >= 1 then
g_test = 7
second = 0
g_KeyPressW = 0
PlaySound(e,0)
end
if g_test == 6 and second > 2 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 6 and g_KeyPressA == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 6 and g_KeyPressS == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 6 and g_KeyPressD == 1 and second >= 1 then
g_test = 0
PromptDuration("Action failed, try again", 1500)
UnFreezePlayer()
PlaySound(e,1)
end
if g_test == 7 then
PromptDuration("Tool stolen with success!", 2000)
UnFreezePlayer()
Destroy(e)
PlaySound(e,0)
end
end
Sound 0 for correct keypress, Sound 1 for incorrect keypress.