I have this script inside A van entity, it should at first prompt the player, and then when the player presses the e key a medkit will spawn around the van. When i run this nothing happens I tried to set always on and off, and the van is a dynamic entity. I get a "Attempt to try to compare a value with a nil error? The variable that I think is throwing errors is my looted variable that has either a 1 or a 0... I was trying to check to see what the variable was. If looted == 1 then the entity has been looted and if the looted == 0 the van hasn't been looted. I hope this is enough info on what i'm trying to do.
--This Will give a Random amount of money, health, or what ever you
--want from entities with this script.
function loot_init(e)
local looted = 0
local lootRange = math.random(0,5)
end
function loot_main(e)
pDist = GetPlayerDistance(e)
--if your close to the entity prompt to search it
if pDist < 80 then -- start2
Prompt("Press E to loot")
end
--if you press e and your close enough
if g_KeyPressedE == 1 and pDist < 50 then
if lootRange == 3 then
SpawnIfUsed(e)
looted = 1
else
PromptDuration("You didn't find anything.",3000)
end
end
end
Markchapman10 is my Skype let's have some dev talk.