Hey guys, I made one really easy script, but if someone need this, copy it. If you have 2 not same name key, use this code.
(Code do the door)
-- LUA Script - precede every function and global member with lowercase name of script + '_main'
-- Door Prompts 'Closed' can be opened with entity collected specified by 'USE KEY'
-- state to ensure user must release E key before can open/close again
door_pressed = 0
function door2key_init(e)
end
key=0
function door2key_main(e)
PlayerDist = GetPlayerDistance(e)
if (PlayerDist < 100 ) and g_PlayerHealth > 0 then
GetEntityPlayerVisibility(e)
if 1 then
if g_Entity[e]['activated'] == 0 then
if g_Entity[e]['haskey'] == -1 then
SetActivated(e,1)
else
if g_Entity[e]['plrvisible'] == 1 then
if g_Entity[e]['haskey'] == 0 and key==2 then
Prompt("The door is locked. Press E key to unlock door")
if g_KeyPressE == 1 then
SetActivated(e,1)
end
elseif g_Entity[e]['haskey'] == 0 and key==1 then
Prompt ("You need 1 key more to unlock door.")
else
Prompt("The door is locked. Find a key to unlock door.")
end
end
end
else
if g_Entity[e]['activated'] == 1 then
-- door is unlocked and closed
if g_Entity[e]['plrvisible'] == 1 then
Prompt("Press E to open door")
if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and door_pressed == 0 then
SetAnimation(0)
PlayAnimation(e)
g_Entity[e]['animating'] = 1
SetActivated(e,2)
ActivateIfUsed(e)
PlaySound(e,0)
StartTimer(e)
door_pressed = 1
end
end
else
if g_Entity[e]['activated'] == 2 then
-- door is open
if g_Entity[e]['plrvisible'] == 1 then
if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and door_pressed == 0 then
SetAnimation(1)
PlayAnimation(e)
g_Entity[e]['animating'] = 1
SetActivated(e,1)
PlaySound(e,1)
CollisionOn(e)
door_pressed = 1
end
end
end
end
end
end
end
if g_Entity[e]['activated'] == 2 then
-- door collision off after 1 second
if GetTimer(e)>1000 then
CollisionOff(e)
end
end
if g_KeyPressE == 0 then
door_pressed = 0
end
PromptLocal ( e, "key=" ..key.. "activated=" .. g_Entity[e]['activated'] .. "PlayerDist=" .. PlayerDist .. " plrvisible=" .. g_Entity[e]['plrvisible'] .. " haskey=" .. g_Entity[e]['haskey'] )
end
Also you need extension to key.
if g_KeyPressE == 1 then
PromptDuration("Collected key",3000)
PlaySound(e,0)
Collected(e)
Destroy(e)
ActivateIfUsed(e)
end
and change to
if g_KeyPressE == 1 then
PromptDuration("Collected key",3000)
PlaySound(e,0)
Collected(e)
Destroy(e)
ActivateIfUsed(e)
key = key + 1
end
I need myself this script, and i quess other need to.