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

function onAttack(cid, target)(?) + tibiando functions

tatanxx

New Member
Joined
Jan 5, 2009
Messages
61
Reaction score
1
Location
Chile
Ok.. im new and im just learning about scripts :c..
used to play tibia YEARS ago, when only XML servers were around.. so theres a bunch of new stuff i dont understand..

since i started my OT with MySQL in 9.1, they have removed the animated text (kinda..)
so i got forced to replace it with creature say (orange text) function.. and finally managed to create an script for a "x skill LvUp!"
plus with magic effects AND a sound effect for each skill up effect (Thanks Mock for the Tibiando API)..


now that i managed to do this sucessfully, i wanted to step a little farther, i tried.. but oh well i just can't get it :/ .. and i have to admit that im a noob at scripting >_<..

so yeah here was my first attemp
LUA:
function onAttack(cid, target)
if isPlayer(cid) and isMonster(target) then
local sock = getSocket(cid)
          if sock then
               sock:send('EF=lup.mp3\n')
          end
end
return TRUE
end

in fact, i want to add sound fxs to each attack.. but still i wanna reach something more specific (sounds for swords, arrows and magic..)
tried many ways but i just cant get it
LUA:
function onCombat(cid, target)
if isPlayer(cid) and isMonster(target) then
local sock = getSocket(cid)
          if sock then
               sock:send('EF=lup.mp3\n')
          end
end
return TRUE
end

if anyone can help me i would really appreciate it, i feel very outdated with Tibia and all this is really neew,
i could share the script i made for level ups + sounds oor something dunno >_< thankius
 
Last edited:
LUA:
local t = {
	{'EF=lup1.mp3\n'}, --SWORD
	{'EF=lup2.mp3\n'}, --CLUB
	{'EF=lup3.mp3\n'}, --AXE
	{'EF=lup4.mp3\n'}, --DIST
	{'EF=lup5.mp3\n'}, --SHIELD
	{'EF=lup6.mp3\n'}, --FIST
	{'EF=lup7.mp3\n'}, --WAND
	{'EF=lup8.mp3\n'} --AMMO
	}

function onCombat(cid, target)
local k = t[getPlayerWeapon(cid)]
	if isPlayer(cid) and isMonster(target) then
		local sock = getSocket(cid)
		if sock then
			sock:send(k)
		end
	end
return TRUE
end
 
-EDIT-:
(silly me forgot to add the creatureEvent in my logina lua)
after i gave it a try i got this problem
problem.jpg

i did this:
so Bogart's script (named it atts.lua)
LUA:
local t = {
	{'EF=att1.mp3\n'}, --SWORD
	{'EF=att2.mp3\n'}, --CLUB
	{'EF=att3.mp3\n'}, --AXE
	{'EF=att4.mp3\n'}, --DIST
	{'EF=att5.mp3\n'}, --SHIELD
	{'EF=att6.mp3\n'}, --FIST
	{'EF=att7.mp3\n'}, --WAND
	{'EF=att8.mp3\n'} --AMMO
	}
 
function onCombat(cid, target)
local k = t[getPlayerWeapon(cid)]
	if isPlayer(cid) and isMonster(target) then
		local sock = getSocket(cid)
		if sock then
			sock:send(k)
		end
	end
return TRUE
end
Then i added this in my creaturescripts.xml
LUA:
<event type="combat" name="Combat" event="script" value="atts.lua"/>
and add this to the login.lua
LUA:
registerCreatureEvent(cid, "Combat")


anyway...

here's my working script for skill advance i modified a bit to make it work for 9.1 (since they removed animated texts) and working with Mock's Tibiando
u can simply search some nice sound u want to play when players level up/skill up
working in my 9.1 Server
(Modified ver of tibiablog's script)
Named it "Advance.lua"
LUA:
function onAdvance(cid, skill, oldlevel, newlevel)
local pos = getPlayerPosition(cid)
local effectPositions = {
{x = pos.x, y = pos.y - 3, z = pos.z},
{x = pos.x, y = pos.y + 3, z = pos.z},
{x = pos.x - 3, y = pos.y, z = pos.z},
{x = pos.x + 3, y = pos.y, z = pos.z},
{x = pos.x - 2, y = pos.y - 2, z = pos.z},
{x = pos.x + 2, y = pos.y - 2, z = pos.z},
{x = pos.x + 2, y = pos.y + 2, z = pos.z},
{x = pos.x - 2, y = pos.y + 2, z = pos.z}
}
for _, ePos in ipairs(effectPositions) do
doSendDistanceShoot(pos, ePos, CONST_ANI_PIERCINGBOLT)
doSendMagicEffect(ePos, CONST_ME_STUN)
end
if skill == 0 then
doCreatureSay(cid, "Fist skill UP", TALKTYPE_ORANGE_1, cid)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
local sock = getSocket(cid)
          if sock then
               sock:send('EF=levelup.mp3\n')
          end
end
if skill == 1 then
doCreatureSay(cid, "Club skill UP", TALKTYPE_ORANGE_1, cid)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
local sock = getSocket(cid)
          if sock then
               sock:send('EF=levelup.mp3\n')
          end
end
if skill == 2 then
doCreatureSay(cid, "Sword skill UP", TALKTYPE_ORANGE_1, cid)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
local sock = getSocket(cid)
          if sock then
               sock:send('EF=levelup.mp3\n')
          end
end
if skill == 3 then
doCreatureSay(cid, "Axe skill UP", TALKTYPE_ORANGE_1, cid)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
local sock = getSocket(cid)
          if sock then
               sock:send('EF=levelup.mp3\n')
          end
end
if skill == 4 then
doCreatureSay(cid, "Distance skill UP", TALKTYPE_ORANGE_1, cid)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
local sock = getSocket(cid)
          if sock then
               sock:send('EF=levelup.mp3\n')
          end
end
if skill == 5 then
doCreatureSay(cid, "Shield skill UP", TALKTYPE_ORANGE_1, cid)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
local sock = getSocket(cid)
          if sock then
               sock:send('EF=levelup.mp3\n')
          end
end
if skill == 6 then
doCreatureSay(cid, "Fishing skill UP", TALKTYPE_ORANGE_1, cid)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
local sock = getSocket(cid)
          if sock then
               sock:send('EF=levelup.mp3\n')
          end
end
if skill == 7 then
doCreatureSay(cid, "Magic level UP", TALKTYPE_ORANGE_1, cid)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
local sock = getSocket(cid)
          if sock then
               sock:send('EF=levelup.mp3\n')
          end
end
if skill == 8 then
doCreatureSay(cid, "CONGRATZ~LEVEL UP!", TALKTYPE_ORANGE_1, cid)
doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
doCreatureAddMana(cid, getCreatureMaxMana(cid))
local sock = getSocket(cid)
          if sock then
               sock:send('EF=levelup.mp3\n')
          end
end
return TRUE
end

Added this in my creaturescripts.xml
LUA:
<event type="advance" name="Advance" event="script" value="Advance.lua"/>
Added this in my login.lua
LUA:
registerCreatureEvent(cid, "Advance")
 
Last edited:
LUA:
local t = {
	{'Fist skill UP!', 'Club skill UP!', 'Sword skill UP!', 'Axe skill UP!', 'Distance skill UP!', 'Fishing skill UP!', 'Magic level UP!', 'CONGRATZ~LEVEL UP'}
	}
 
function onCombat(cid, target)
	local pos = getPlayerPosition(cid)
	local effectPositions = {
		{x = pos.x, y = pos.y - 3, z = pos.z},
		{x = pos.x, y = pos.y + 3, z = pos.z},
		{x = pos.x - 3, y = pos.y, z = pos.z},
		{x = pos.x + 3, y = pos.y, z = pos.z},
		{x = pos.x - 2, y = pos.y - 2, z = pos.z},
		{x = pos.x + 2, y = pos.y - 2, z = pos.z},
		{x = pos.x + 2, y = pos.y + 2, z = pos.z},
		{x = pos.x - 2, y = pos.y + 2, z = pos.z}
	}
	for _, ePos in ipairs(effectPositions) do
		doSendDistanceShoot(pos, ePos, CONST_ANI_PIERCINGBOLT)
		doSendMagicEffect(ePos, CONST_ME_STUN)
	end
	local k = t[skill+1]
	doCreatureSay(cid, k..' skill UP', TALKTYPE_ORANGE_1, cid)
	doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
	doCreatureAddMana(cid, getCreatureMaxMana(cid))
	local sock = getSocket(cid)
	if sock then
		sock:send('EF=levelup.mp3\n')
	end
return TRUE
end
shorter D:
 
Then:
LUA:
local t = {
	{'Fist skill UP!', 'EF=levelup1.mp3\n'}, 
	{'Club skill UP!', 'EF=levelup2.mp3\n'}, 
	{'Sword skill UP!', 'EF=levelup.2mp3\n'}, 
	{'Axe skill UP!', 'EF=levelup3.mp3\n'}, 
	{'Distance skill UP!', 'EF=levelup4.mp3\n'}, 
	{'Fishing skill UP!', 'EF=levelup5.mp3\n'}, 
	{'Magic level UP!', 'EF=levelup6.mp3\n'}, 
	{'CONGRATZ~LEVEL UP', 'EF=levelup7.mp3\n'}
	}
 
function onCombat(cid, target)
	local pos = getPlayerPosition(cid)
	local effectPositions = {
		{x = pos.x, y = pos.y - 3, z = pos.z},
		{x = pos.x, y = pos.y + 3, z = pos.z},
		{x = pos.x - 3, y = pos.y, z = pos.z},
		{x = pos.x + 3, y = pos.y, z = pos.z},
		{x = pos.x - 2, y = pos.y - 2, z = pos.z},
		{x = pos.x + 2, y = pos.y - 2, z = pos.z},
		{x = pos.x + 2, y = pos.y + 2, z = pos.z},
		{x = pos.x - 2, y = pos.y + 2, z = pos.z}
	}
	for _, ePos in ipairs(effectPositions) do
		doSendDistanceShoot(pos, ePos, CONST_ANI_PIERCINGBOLT)
		doSendMagicEffect(ePos, CONST_ME_STUN)
	end
	local k = t[skill+1]
	doCreatureSay(cid, k[1]..' skill UP', TALKTYPE_ORANGE_1, cid)
	doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
	doCreatureAddMana(cid, getCreatureMaxMana(cid))
	local sock = getSocket(cid)
	if sock then
		sock:send(k[2])
	end
return TRUE
end
 
Fixed ur simplified version of my skill up fx+sound script

u had to set it on advance function
and the skill +1 wasn't necessary, so here is a working (tested) version of it
LUA:
local t = {
	{'Fist skill UP!', 'EF=levelup1.mp3\n'}, 
	{'Club skill UP!', 'EF=levelup2.mp3\n'}, 
	{'Sword skill UP!', 'EF=levelup.2mp3\n'}, 
	{'Axe skill UP!', 'EF=levelup3.mp3\n'}, 
	{'Distance skill UP!', 'EF=levelup4.mp3\n'}, 
	{'Fishing skill UP!', 'EF=levelup5.mp3\n'}, 
	{'Magic level UP!', 'EF=levelup6.mp3\n'}, 
	{'CONGRATZ~LEVEL UP', 'EF=levelup7.mp3\n'}
	}
 
function onAdvance(cid, skill, oldlevel, newlevel)
	local pos = getPlayerPosition(cid)
	local effectPositions = {
		{x = pos.x, y = pos.y - 3, z = pos.z},
		{x = pos.x, y = pos.y + 3, z = pos.z},
		{x = pos.x - 3, y = pos.y, z = pos.z},
		{x = pos.x + 3, y = pos.y, z = pos.z},
		{x = pos.x - 2, y = pos.y - 2, z = pos.z},
		{x = pos.x + 2, y = pos.y - 2, z = pos.z},
		{x = pos.x + 2, y = pos.y + 2, z = pos.z},
		{x = pos.x - 2, y = pos.y + 2, z = pos.z}
	}
	for _, ePos in ipairs(effectPositions) do
		doSendDistanceShoot(pos, ePos, CONST_ANI_PIERCINGBOLT)
		doSendMagicEffect(ePos, CONST_ME_STUN)
	end
	local k = t[skill]
	doCreatureSay(cid, k[1], TALKTYPE_ORANGE_1, cid)
	doCreatureAddHealth(cid, getCreatureMaxHealth(cid))
	doCreatureAddMana(cid, getCreatureMaxMana(cid))
	local sock = getSocket(cid)
	if sock then
		sock:send(k[2])
	end
return TRUE
end

now if anybody out there could help me with this one would be awesome T_T
LUA:
local t = {
	{'EF=att1.mp3\n'}, --SWORD
	{'EF=att2.mp3\n'}, --CLUB
	{'EF=att3.mp3\n'}, --AXE
	{'EF=att4.mp3\n'}, --DIST
	{'EF=att5.mp3\n'}, --SHIELD
	{'EF=att6.mp3\n'}, --FIST
	{'EF=att7.mp3\n'}, --WAND
	{'EF=att8.mp3\n'} --AMMO
	}
 
function onCombat(cid, target)
local k = t[getPlayerWeapon(cid)]
	if isPlayer(cid) and isMonster(target) then
		local sock = getSocket(cid)
		if sock then
			sock:send(k)
		end
	end
return TRUE
end

bad argument it says, as the pictures i show before
 

Similar threads

Back
Top