• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

CreatureEvent [Tibiando]Send music if monster on screen

Ksisio

New Member
Joined
Feb 21, 2008
Messages
54
Reaction score
0
Location
Stalowa Wola
There is my script to send music if monster on screen. Sorry for my bad english.

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:
one question, and if have the demon,tiger and dragon in the same place?! what sound will play? :D
 
really nice work!
I was trying to do this, you give me a big help!

Thanks.
 
A certain names of monsters are written in small letters and sound can't be played, so i fixed it.
New version in first post.
 
Last edited:
you should always compare lowcased monster name with lowcased config name so it will work w/o problems

quite nice idea for bosses, different music when boss raids in the same place, cool
 
[13/03/2011 23:30:14] [Error - CreatureScript Interface]
[13/03/2011 23:30:14] In a timer event called from:
[13/03/2011 23:30:14] data/creaturescripts/scripts/sounds/monster appear.lua
[13/03/2011 23:30:14] Description:
[13/03/2011 23:30:14] (luaAddEvent) Callback parameter should be a function.
[13/03/2011 23:30:14] MUSIC OK

say, what? I don't quite get what this error is about.
 
for some odd reason, it makes my whole tibiando stop working at all :/ ..
makes my tibiando only play the main song but it stops all other functions @_@...´´
 
not sure if has anything to do with that..
tested in a 9.10 server, there's a problem with a callback function and event.. so i guess that this code need to be updated u_u'
 
Q1: Does tibiando make so they players need to downlaod my custom client?
Q2: Can I still have my server left without changing it?
 
-No players wont need to download it
-yes you can, players can choose to play with or without it
 
In the first question I want to add; "Do they have to download the sounds? (custom client)"?
 
Where r the sounds?

The tiger/dog/dragon etc.. sounds?
 
Last edited:
Back
Top