-- 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 if g_foraged[ collect.name ] == nil then U.SetAmount( collect.name, 0, g_foraged ) end end end else U.SetList( g_foraged ) 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) U.ChangeAmount( collect.name, 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