• 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!

[Script] Bird Cage Help

Wifixs

New Member
Joined
Jul 20, 2009
Messages
18
Reaction score
1
What I want that does he is that you use when it sends different effects, which to be in the table of effects of the Script, but what does it is that it sends another type of effects and what I want is that sends those that to be in the table.

Lua:
effects =
{
CONST_ME_SOUND_BLUE,
CONST_ME_SOUND_RED,
CONST_ME_SOUND_YELLOW,
CONST_ME_SOUND_PURPLE,
CONST_ME_SOUND_BLUE,
CONST_ME_SOUND_WHITE
}

function onUse(cid, item, frompos, item2, topos )
for i, pos in pairs(effects) do
doSendMagicEffect(frompos,math.random(1,table.getn(effects)))
delay10 = delay10+400
end
	return 1
end
 
Don't use table.getn(table)! It's so unnecessary!

Use "#table", is that hard? :S

+ You don't use ipairs(t) for that table. Only if the table contains other tables.

Lua:
local effects = {
	CONST_ME_SOUND_BLUE,
	CONST_ME_SOUND_RED,
	CONST_ME_SOUND_YELLOW,
	CONST_ME_SOUND_PURPLE,
	CONST_ME_SOUND_BLUE,
	CONST_ME_SOUND_WHITE
}

function onUse(cid, item, frompos, item2, topos )
	doSendMagicEffect(frompos, effects[math.random(1, #effects)])
	return true
end

See?
 
Last edited:
Don't use table.getn(table)! It's so unnecessary!

Use "#table", is that hard? :S

+ You don't use ipairs(t) for that table. Only if the table contains other tables.

Lua:
effects = {
	CONST_ME_SOUND_BLUE,
	CONST_ME_SOUND_RED,
	CONST_ME_SOUND_YELLOW,
	CONST_ME_SOUND_PURPLE,
	CONST_ME_SOUND_BLUE,
	CONST_ME_SOUND_WHITE
}

function onUse(cid, item, frompos, item2, topos )
	doSendMagicEffect(frompos, effects[math.random(1, #effects)])
	return true
end

See?

I think you should declare table as local, and why not table.maxn()? It works properly and same like #, so i don't see any problem in using this.
 
Ok Ty.

Thanks for the advice of the table. But what I want it is that it sends the sound effects and the effects that command they are /z 1.2.3.4.5, and I want that it sends the effects /z 8,19,21,22,23,24
 
I think you should declare table as local, and why not table.maxn()? It works properly and same like #, so i don't see any problem in using this.

It takes less space. It'll mater when you start scripting something more advanced, you'll find it unnecessary to use a function when you can just use #.
 
Back
Top