dont give up, just keep practising and you will get there, we all had to learn once
your script should look like this
--time to destroy the character.
function destroy_init(e)
end
function destroy_main(e)
if GetPlayerDistance(e) < 250 then
Destroy(e)
end
end
killquest is an advanced script to be editing as a new user, you don't really need it to be that complicated for your requirement
i have created and commented the scripts for you, tested and working so hopefully they will set you on the right track
you need 1 script that will control the door but also check the 3 items are collected like so
door_with_requirement.lua
--store a starting state for the door (in this case we need to collect items so that's what we'll call it)
state = "collect items"
--number of items player has already collected at level load
currently_collected = 0
--number of items to collect to activate the door/object
required_to_collect = 3
function door_with_requirement_init(e)
end
function door_with_requirement_main(e)
--first check the state of the door is still the original state
if state == "collect items" then
--check the player is near the door
if GetPlayerDistance(e) < 150 then
--now check if the player has collected enough items or not
--checking if not collected enough first
if currently_collected < required_to_collect then
--if not enough collected then show a prompt
--NOTE*
--the .. allows you to put variables inbetween strings
--use a second set of .. only if you need to continue the string
-- i.e. Prompt("hello "..name_of_character) or Prompt("hello "..name_of_character..", how are you?") <- where 'name_of_character' would be stored previously
--END NOTE*
Prompt("You still need to collect "..(required_to_collect-currently_collected).." more item(s) to unlock this door")
--else in this case means we have collected more than enough items
else
--remove items from player possesion maybe?
currently_collected = currently_collected - required_to_collect
--add any code from the external script's init(e) or variables
--i.e. any code inside door_init(e) or above (don't include the actual function door_init(e))
door_pressed = 0
--change the state to reflect that the items have been collected
state = "door is active"
--finished checking item requirements
end
--finished checking player distance
end
--if state is no longer "collect items" check if it is our 2nd state (you can set as many states as you like)
elseif state == "door is active" then
--now we will just copy and paste the entire door_main(e) from door.lua for speed
--again remember we don't need the 'function door_main(e)', just the code inside it
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'] == 1 then
Prompt("The door is locked. Press E key to unlock door")
if g_KeyPressE == 1 then
SetActivated(e,1)
end
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)
g_Entity[e]['timer'] = g_Time
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
--finished checking our states
end
--end of main(e)
end
and then a script to apply to the 3 (or more) objects that will be collected to unlock/activate the door
door_requirement_item.lua
--set a toggle variable for player input
pressed = 0
function door_requirement_item_init(e)
end
function door_requirement_item_main(e)
--check player is near object
if GetPlayerDistance(e) < 150 then
--Prompt to ask player if he wants to pick it up
Prompt("Collect the item?")
--check for key press from player
if g_KeyPressE == 1 then
--a toggle to make sure only 1 item is collected at a time if multiple objects are nearby
if pressed == 0 then
pressed = 1
--play a sound to signify picking up the item maybe?
PlaySound(e,0)
--update the variable set in the door_with_requirement.lua
currently_collected = currently_collected + 1
--destroy the entity to stop it getting collected again
Destroy(e)
--finished the input toggle
end
--finished checking player input
end
--code here to reset the toggle if the player is no longer pressing the 'e' key
if g_KeyPressE == 0 then
pressed = 0
end
--finished checking player is nearby
end
--end of the main(e)
end