looks fine except you don't have any way to reset the "pressed" input so i assume that is why it only works once.
as for the animations, not sure what frames they are but you change the animation frames within the input part to the desired animation?
i.e. SetAnimationFrames(5090,5099)
to SetAnimationFrames(?,?)
i think you also want to wrap the prompt in only the injured state so it only shows before you heal the character
injured = {}
local pressed = 0
local input_key = "e"
function ai_injured_init(e)
SetAnimation(0)
injured[e] = 0
end
function ai_injured_main(e)
if injured[e] == 0 then
SetAnimationFrames(5061,5090)
PlayAnimation(e)
injured[e] = 1
end
if injured[e] == 1 then
if GetPlayerDistance(e) < 160 then
PromptLocal(e,"heal?")
end
if g_InKey == input_key and pressed == 0 then
pressed = 1
SetAnimationFrames(5090,5099)
PlayAnimation(e)
injured[e] = 2
end
end
--check player no longer pressing the input key to reset the toggle
if g_InKey ~= input_Key then
pressed = 0
end
end
for checking a stored medkit, yes that is a bit more complicated but still only really 1 more variable depending on how you have the medkits stored on the player in the other script..
so if you had a variable that counts up as you collect medkits (say g_Medkits) your script could look something like this
injured = {}
local pressed = 0
local input_key = "e"
function ai_injured_init(e)
SetAnimation(0)
injured[e] = 0
end
function ai_injured_main(e)
if injured[e] == 0 then
SetAnimationFrames(5061,5090)
PlayAnimation(e)
injured[e] = 1
end
if injured[e] == 1 then
if GetPlayerDistance(e) < 160 then
PromptLocal(e,"heal?")
end
if g_InKey == input_key and pressed == 0 then
pressed = 1
if g_Medkits > 0 then
g_Medkits = g_Medkits - 1
SetAnimationFrames(5090,5099)
PlayAnimation(e)
injured[e] = 2
end
end
end
--check player no longer pressing the input key to reset the toggle
if g_InKey ~= input_Key then
pressed = 0
end
end
then you need a script on the medkit collectable that has a line like
if GetPlayerDistance(e) < 100 then
g_Medkits = g_Medkits + 1
Destroy(e)
end
note: untested and written entirely in the reply box so might be mistakes but looks ok to me