Ksisio
New Member
There is my script to send music if monster on screen. Sorry for my bad english.
monster-sound.lua:
creaturescripts.xml:
login.lua:
monster-sound.lua:
Code:
local monsters = {
{name = 'Dragon',sound = {"dragon00.wav","dragon01.wav"}},
{name = 'Demon',sound = {"demon00.wav"}},
{name = 'Tiger',sound = {"tiger.mp3"}},
{name = 'dog',sound = {"dog00.wav","dog01.wav","dog02.mp3"}}
}
local storage = 33301
local delay = 5
function onThink(cid, interval)
local creatures = {}
local sounds = {}
local playerPos = getCreaturePos(cid)
local area = getArea(playerPos, 7, 5)
local creaturePos = {}
for k,v in pairs(area) do
creaturePos = {x=v.x,y=v.y,z=v.z}
local creature = getTopCreature(creaturePos)
if (creature.type ~= 0 and creature.uid ~= cid) then
local name = string.lower(getCreatureName(creature.uid))
if (name) then
table.insert(creatures, name)
end
end
end
if #creatures > 0 then
for i=1, #creatures do
for k,v in pairs(monsters) do
if creatures[i] == string.lower(v.name) then
table.insert(sounds, v.sound[math.random(1,#v.sound)])
end
end
end
end
if #sounds > 0 then
local playerStorage = getPlayerStorageValue(cid, storage)
if (playerStorage <= (os.time()-delay)) or (playerStorage < 0) then
local sock = getSocket(cid)
if sock then
sock:send('EF='..sounds[math.random(1,#sounds)]..'\n')
setPlayerStorageValue(cid,storage,os.time())
end
end
end
return true
end
creaturescripts.xml:
Code:
<event type="think" name="MonstersSounds" event="script" value="monster-sound.lua"/>
login.lua:
Code:
registerCreatureEvent(cid, "MonstersSounds")
Last edited: