--DESCRIPTION: spawns a random entity whenever the player enters the zone --DESCRIPTION: can be triggered [USES=0] times (0 = infinite.. or you will run out of items) --DESCRIPTION: [ENTITYNAME$=""] the name of the entities to spawn g_random_item_zone = {} function random_item_zone_properties(e, uses, entityname) local griz = g_random_item_zone[e] griz.uses = uses griz.entityname = entityname if griz.uses == 0 then griz.uses = -1 end end function random_item_zone_init(e) g_random_item_zone[e] = {} local griz = g_random_item_zone[e] griz.inzone = -1 random_item_zone_properties(e,0,"") end function random_item_zone_main(e) local function SpawnRandomItem(e) local griz = g_random_item_zone[e] local id = 0 local tries = 0 repeat id = math.random(1,#griz.itemlist) if g_Entity[griz.itemlist.id] == nil then tries = tries + 1 end until (g_Entity[griz.itemlist[id]] ~= nil and g_Entity[griz.itemlist[id]].activated == 0) or tries > 99 if g_Entity[griz.itemlist[id]].activated ~= 0 then PromptDuration("Error - No entity left to spawn",2000) else PlaySound(e,0) SetActivated(griz.itemlist[id],1) Show(griz.itemlist[id]) CollisionOn(griz.itemlist[id]) end if griz.uses > 0 then griz.uses = griz.uses - 1 if griz.uses == 0 then Destroy(e) end end end local griz = g_random_item_zone[e] if griz.inzone == -2 then PromptLocal(e,"Error - No entitys found with the desired name") elseif griz.inzone == -1 then if griz.entityname == "" then PromptLocal(e,"Error - No entity name set") return end griz.itemlist = {} for a = 1, g_EntityElementMax do if a ~= nil then if g_Entity[a] ~= nil then if GetEntityName(a) == griz.entityname then griz.itemlist[#griz.itemlist+1] = a Hide(a) CollisionOff(a) SetActivated(a,0) end end end end if griz.items == 0 then griz.inzone = -2 else griz.inzone = 0 end elseif griz.inzone == 0 then if g_Entity[e].plrinzone == 1 then SpawnRandomItem(e) griz.inzone = 1 end elseif g_Entity[e].plrinzone == 0 then griz.inzone = 0 end end