-- LUA Script - precede every function and global member with lowercase name of script + '_main' g_collected = g_collected or {} g_foraged = g_foraged or {} local U = require "scriptbank\\utillib" math.randomseed(os.time()) math.random(); math.random(); math.random() local czone = {} function collect_init_name( e, name ) Include( "utillib.lua" ) g_collected[e] = { name = name, randMax = g_Entity[e].health } end function collect_main(e) local inZone = czone[e] local collect = g_collected[e] if inZone == nil then if ZonePointIn ~= nil then local Ent = g_Entity[e] local zName = ZonePointIn( Ent.x, Ent.z ) if zName ~= 'None' then czone[e] = zName end end else if g_foraged[collect.name] == nil then g_foraged[collect.name] = {amount = 0} end if not PlayerIsInZone( inZone ) then return end if not U.PlayerLookingNear( e, 100, 90 ) then return end Prompt("Press E to collect " .. collect.name) if g_KeyPressE == 1 then PlaySound(e, 0) local c = g_foraged[collect.name] c.amount = c.amount + math.random( 1, collect.randMax) -- get new position for this entity local otherZone = 'Zone2' if inZone == 'Zone2' then otherZone = 'Zone1' end local x, z = RandomPointInZone(otherZone) if x ~= 0 and z ~= 0then CollisionOff(e) local y = GetTerrainHeight( x, z ) SetPosition( e, x, y, z ) ResetPosition( e, x, y, z) CollisionOn(e) czone[e] = otherZone else Destroy(e) end end end end