local assigned_object = {} local played_recently = {} --name must match the name given in randomsoundinzoneobject.lua object --sounds are applied to above object (not the zone as it only has 1 slot) function randomsoundinzonezone_init_name(e,name) weapon_name[e] = name played_recently[e] = 0 end function randomsoundinzonezone_main(e) --first run through is simply to make sure the assigned object has been spawned too if assigned_object[e] == nil then assigned_object[e] = -1 return --stops code going any further this sync --2nd run through is to find and commit other object to variable to use later (so we don't need to keep finding it or manually assign it's e) elseif assigned_object[e] == -1 then for a = 1, 9999 do if g_Entity[a] ~= nil then if weapon_name[a] ~= nil then --we know it has same name as this zone but isn't this zone so if we match then this must be it if a ~= e and weapon_name[a] == weapon_name[e] then assigned_object[e] = a return end end end end else --if player is inside zone if g_Entity[e]['plrinzone'] == 1 then --as there's no engine-side method to get sound playing or not we're just going to use a basic delay if played_recently[e] > 0 then --keeps the count a bit slower if GetTimer(e) > 1 then StartTimer(e) played_recently[e] = played_recently[e] - 1 end --if we no longer need to delay then we can get a new sound to play else --randomly decide if we should play a sound based on the other objects HP (higher HP = less chance to play) if math.random(0,g_Entity[assigned_object[e]]['health']) == 1 then played_recently[e] = g_Entity[assigned_object[e]]['health']*100 --picks a random sound from the 5 slots PlaySoundIfSilent(assigned_object[e],math.random(0,4)) end end end end end