Jump to content
Close
DouGlaS Mapper

Scripting [PEDIDO] DODGE NO LOOK

Recommended Posts

Galera to com um probleminha aki pra por meu dodge no look, tipo meu sistema de dodge é por item, ai queria que ele somasse o total de dodge que o player tem equipado e mostrasse no look, só que ele n tem storage, n faço ideia de como por ele no look, se alguém puder ajudar REP +.

OBS: Já olhei um outro tópico porém n funcionou só deu erro ;/

 

OTX 2.6

VERSAO 8.6

 

Meu Sistema de Dodge: 

Citar

 


function isHandItem(uid) -- NW based on Mock
         uid = uid or 0
        if isInArray({1,2,3,4,5,6}, getItemWeaponType(uid)) then
             return true
         end
         return false
end


function getItemDodgePercent(itemuid)
return getItemAttribute(itemuid, "dodgePercent") or 0
end


function setItemDodgePercent(uid, percent)
doItemSetAttribute(uid, "description", "[Dodge: "..percent.."%]")
doItemSetAttribute(uid, "dodgePercent", percent)
end








function onUse(cid, item, fromPosition, itemEx, toPosition) 
level = 0
local upgrade = {
[1] = {min = 1, max = 5, chance = 100},
[2] = {min = 5, max = 10, chance = 80},
[3] = {min = 10, max = 20, chance = 60},
[4] = {min = 20, max = 40, chance = 40},
[5] = {min = 40, max = 50, chance = 20}
}


function isWearing(uid) -- NW based on Mock
         uid = uid or 0
        if isInArray({uid}, getPlayerSlotItem(cid, 1).uid) or isInArray({uid}, getPlayerSlotItem(cid, 4).uid) or isInArray({uid}, getPlayerSlotItem(cid, 7).uid) or isInArray({uid}, getPlayerSlotItem(cid, 8).uid) then
             return true
         end
         return false
end




if isHandItem(itemEx.uid) or isWearing(itemEx.uid) then
local name = getItemName(itemEx.uid)
local atual = math.floor(getItemDodgePercent(itemEx.uid)*10)/10
for i = 1, #upgrade do
if string.find(tostring(name),"+".. i .."") then
level = i
end
end


if level >= #upgrade then
doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"Your item is already on max level, you can't upgrade it any further.")
return true
end




if math.random(0,100) <= upgrade[level + 1].chance then 
doRemoveItem(item.uid, 1)
doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"You leveled your "..getItemNameById(itemEx.itemid).." to ".. level+1 ..".")
setItemDodgePercent(itemEx.uid, atual + (math.random(upgrade[level+1].min,upgrade[level+1].max))/10)
doItemSetAttribute(itemEx.uid,'name', getItemNameById(itemEx.itemid)..' +'..(level+1))
doSendMagicEffect(toPosition, math.random(28,30))
else
doRemoveItem(itemEx.uid, 1)
doRemoveItem(item.uid, 1)
doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_BLUE,"Your "..getItemNameById(item.itemid).." has failed and destroyed your "..getItemNameById(itemEx.itemid).." in the process")
doSendMagicEffect(toPosition, 4)
end


else
doPlayerSendTextMessage(cid, 24,"You cant refine this item.")
end
return true
end 

 

Meu Sistema de LOOK:

Citar

function getPlayerFrags(cid)
	local time = os.time()
	local times = {today = (time - 86400), week = (time - (7 * 86400))}

	local contents, result = {day = {}, week = {}, month = {}}, db.getResult("SELECT `pd`.`date`, `pd`.`level`, `p`.`name` FROM `player_killers` pk LEFT JOIN `killers` k ON `pk`.`kill_id` = `k`.`id` LEFT JOIN `player_deaths` pd ON `k`.`death_id` = `pd`.`id` LEFT JOIN `players` p ON `pd`.`player_id` = `p`.`id` WHERE `pk`.`player_id` = " .. getPlayerGUID(cid) .. " AND `k`.`unjustified` = 1 AND `pd`.`date` >= " .. (time - (30 * 86400)) .. " ORDER BY `pd`.`date` DESC")
	if(result:getID() ~= -1) then
		repeat
			local content = {date = result:getDataInt("date")}
			if(content.date > times.today) then
				table.insert(contents.day, content)
			elseif(content.date > times.week) then
				table.insert(contents.week, content)
			else
				table.insert(contents.month, content)
			end
		until not result:next()
		result:free()
	end

	local size = {
		day = table.maxn(contents.day),
		week = table.maxn(contents.week),
		month = table.maxn(contents.month)
	}
	return size.day + size.week + size.month
end

function onLogin(cid)
	registerCreatureEvent(cid, "fraglook")
	return true
end

function onLook(cid, thing, position, lookDistance)
	if isPlayer(thing.uid) and thing.uid ~= cid then
		doPlayerSetSpecialDescription(thing.uid,' [Frags: ' .. getPlayerFrags(thing.uid) .. '], [Critical: '..math.max(0,(tonumber(getCreatureStorage(thing.uid,48903)) or 0))..'/100].')
		return true
	elseif thing.uid == cid then
		doPlayerSetSpecialDescription(cid,' [Frags: ' .. getPlayerFrags(thing.uid) .. '], [Critical: '..math.max(0,(tonumber(getCreatureStorage(cid,48903)) or 0))..'/100].')
		local string = 'You see yourself.'
		if getPlayerFlagValue(cid, PLAYERFLAG_SHOWGROUPINSTEADOFVOCATION) then
			string = string..' You are '.. getPlayerGroupName(cid) ..'.'
		elseif getPlayerVocation(cid) ~= 0 then
			string = string..' You are '.. getPlayerVocationName(cid) ..'.'
		else
			string = string..' You have no vocation.'
		end
		
		
		if getPlayerGuildId(cid) > 0 then
			string = string..' You are ' .. (getPlayerGuildRank(cid) == '' and 'a member' or getPlayerGuildRank(cid)) ..' of the '.. getPlayerGuildName(cid)
			string = getPlayerGuildNick(cid) ~= '' and string..' ('.. getPlayerGuildNick(cid) ..').' or string..'.'
		end

		if getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEECREATUREDETAILS) then
			string = string..'nHealth: ['.. getCreatureHealth(cid) ..' / '.. getCreatureMaxHealth(cid) ..'], Mana: ['.. getCreatureMana(cid) ..' / '.. getCreatureMaxMana(cid) ..'].'
			string = string..'nIP: '.. doConvertIntegerToIp(getPlayerIp(cid)) ..'.'
		end

		if getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEEPOSITION) then
			string = string..'nPosition: [X:'.. position.x..'] [Y:'.. position.y..'] [Z:'.. position.z..'].'
		end
		
		string = string..getPlayerSpecialDescription(cid)..''
		
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, string)  
		return false
	end
	return true
end

 

 

 


Share this post


Link to post
Share on other sites

Fiz por aqui mesmo, talvez funcione.

function getDodge(cid) then
	local total = 0
	for i = 1, 10 do
		local item = getPlayerSlotItem(cid, i)
		total = total + (getItemAttribute(item.uid, "dodgePercent") or 0)
	end
end

ai na parte do look você adiciona:

(para ver em seu look)

string = string..' [Dodge: ' ..getDodge(cid).. '%]'

(para ver em outros)

[Dodge: ' .. getDodge(thing.uid) .. '%]

 


Edited by Ramon RBN (see edit history)

Share this post


Link to post
Share on other sites
3 horas atrás, DouGlaS Mapper disse:

@Ramon RBN 

Ta dando o seguinte erro:

[Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:1: unexpected symbol near 'then'

 

Mude

function getDodge(cid) then

para

function getDodge(cid)

 


Share this post


Link to post
Share on other sites

@Ramon RBN 

doPlayerSetSpecialDescription(cid,' [Frags: ' .. getPlayerFrags(thing.uid) .. '], [Critical: '..math.max(0,(tonumber(getCreatureStorage(cid,48903)) or 0))..'/200],' string = string..' [Dodge: ' ..getDodge(cid).. '%]')


Share this post


Link to post
Share on other sites
3 horas atrás, DouGlaS Mapper disse:

@Ramon RBN 

doPlayerSetSpecialDescription(cid,' [Frags: ' .. getPlayerFrags(thing.uid) .. '], [Critical: '..math.max(0,(tonumber(getCreatureStorage(cid,48903)) or 0))..'/200],' string = string..' [Dodge: ' ..getDodge(cid).. '%]')

 

Tenta dessa forma 

Spoiler

function onLook(cid, thing, position, lookDistance)
    if isPlayer(thing.uid) and thing.uid ~= cid then
        doPlayerSetSpecialDescription(thing.uid,' [Frags: ' .. getPlayerFrags(thing.uid) .. '], [Critical: '..math.max(0,(tonumber(getCreatureStorage(thing.uid,48903)) or 0))..'/100], [Dodge: ' .. getDodge(thing.uid) .. '%].')
        return true
    elseif thing.uid == cid then
        doPlayerSetSpecialDescription(cid,' [Frags: ' .. getPlayerFrags(thing.uid) .. '], [Critical: '..math.max(0,(tonumber(getCreatureStorage(cid,48903)) or 0))..'/100].')
        local string = 'You see yourself.'
        
        string = string..' [Dodge: ' ..getDodge(cid).. '%]'
        
        if getPlayerFlagValue(cid, PLAYERFLAG_SHOWGROUPINSTEADOFVOCATION) then
            string = string..' You are '.. getPlayerGroupName(cid) ..'.'
        elseif getPlayerVocation(cid) ~= 0 then
            string = string..' You are '.. getPlayerVocationName(cid) ..'.'
        else
            string = string..' You have no vocation.'
        end
        
        
        if getPlayerGuildId(cid) > 0 then
            string = string..' You are ' .. (getPlayerGuildRank(cid) == '' and 'a member' or getPlayerGuildRank(cid)) ..' of the '.. getPlayerGuildName(cid)
            string = getPlayerGuildNick(cid) ~= '' and string..' ('.. getPlayerGuildNick(cid) ..').' or string..'.'
        end

        if getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEECREATUREDETAILS) then
            string = string..'nHealth: ['.. getCreatureHealth(cid) ..' / '.. getCreatureMaxHealth(cid) ..'], Mana: ['.. getCreatureMana(cid) ..' / '.. getCreatureMaxMana(cid) ..'].'
            string = string..'nIP: '.. doConvertIntegerToIp(getPlayerIp(cid)) ..'.'
        end

        if getPlayerFlagValue(cid, PLAYERCUSTOMFLAG_CANSEEPOSITION) then
            string = string..'nPosition: [X:'.. position.x..'] [Y:'.. position.y..'] [Z:'.. position.z..'].'
        end
        
        string = string..getPlayerSpecialDescription(cid)..''
        
        doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, string)  
        return false
    end
    return true
end

 


Share this post


Link to post
Share on other sites

@Ramon RBN 

agora deu esse erro:

 

>>> Loading creaturescripts... [Error - Event::checkScript] Event onLogin not found (data/creaturescripts/scripts/fraglook.lua)

 

e não aparecer nada quando do look no personagem e da esse erro na distro quando do look:

 

[Error - CreatureScript Interface] 
[4/12/2019 18:12:10] data/creaturescripts/scripts/fraglook.lua:onLook
[4/12/2019 18:12:10] Description: 
[4/12/2019 18:12:10] data/creaturescripts/scripts/fraglook.lua:6: attempt to call global 'getPlayerFrags' (a nil value)
[4/12/2019 18:12:10] stack traceback:
[4/12/2019 18:12:10]     data/creaturescripts/scripts/fraglook.lua:6: in function <data/creaturescripts/scripts/fraglook.lua:1>

 


Share this post


Link to post
Share on other sites
3 horas atrás, DouGlaS Mapper disse:

@Ramon RBN 

agora deu esse erro:

 

>>> Loading creaturescripts... [Error - Event::checkScript] Event onLogin not found (data/creaturescripts/scripts/fraglook.lua)

 

e não aparecer nada quando do look no personagem e da esse erro na distro quando do look:

 

[Error - CreatureScript Interface] 
[4/12/2019 18:12:10] data/creaturescripts/scripts/fraglook.lua:onLook
[4/12/2019 18:12:10] Description: 
[4/12/2019 18:12:10] data/creaturescripts/scripts/fraglook.lua:6: attempt to call global 'getPlayerFrags' (a nil value)
[4/12/2019 18:12:10] stack traceback:
[4/12/2019 18:12:10]     data/creaturescripts/scripts/fraglook.lua:6: in function <data/creaturescripts/scripts/fraglook.lua:1>

 

 

Esse erro é do seu sistema de frag

data/creaturescripts/scripts/fraglook.lua:6: attempt to call global 'getPlayerFrags' (a nil value)

data/creaturescripts/scripts/fraglook.lua:6: attempt to call global 'getPlayerFrags' (a nil value)

nessa linha 

doPlayerSetSpecialDescription(cid,' [Frags: ' .. getPlayerFrags(thing.uid) .. '], [Critical: '..math.max(0,(tonumber(getCreatureStorage(cid,48903)) or 0))..'/100].')

 

tente alterar

return size.day + size.week + size.month

para

return (size.day + size.week + size.month) or 0

 

 

Teve algum erro além desse?

Loading creaturescripts... [Error - Event::checkScript] Event onLogin not found (data/creaturescripts/scripts/fraglook.lua)

 


Edited by Ramon RBN (see edit history)

Share this post


Link to post
Share on other sites

@Ramon RBN 

2 horas atrás, Ramon RBN disse:

tente alterar


return size.day + size.week + size.month

 


return (size.day + size.week + size.month) or 0

não entendi esse parte '-'

 


Loading creaturescripts... [Error - Event::checkScript] Event onLogin not found (data/creaturescripts/scripts/fraglook.lua)

- Só deu esse erro

 

 


Share this post


Link to post
Share on other sites

@Ramon RBN 

Ta dando o mesmo erro ainda ;/

[4/12/2019 22:7:34] >>> Loading creaturescripts... [Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:46: ')' expected near 'string'
[4/12/2019 22:7:34] [Error - Event::checkScript] Cannot load script (data/creaturescripts/scripts/fraglook.lua)
[4/12/2019 22:7:34] data/creaturescripts/scripts/fraglook.lua:46: ')' expected near 'string'
[4/12/2019 22:7:34] [Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:46: ')' expected near 'string'
[4/12/2019 22:7:34] [Error - Event::checkScript] Cannot load script (data/creaturescripts/scripts/fraglook.lua)
[4/12/2019 22:7:34] data/creaturescripts/scripts/fraglook.lua:46: ')' expected near 'string'


Share this post


Link to post
Share on other sites
32 minutos atrás, DouGlaS Mapper disse:

@Ramon RBN 

Ta dando o mesmo erro ainda ;/

[4/12/2019 22:7:34] >>> Loading creaturescripts... [Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:46: ')' expected near 'string'
[4/12/2019 22:7:34] [Error - Event::checkScript] Cannot load script (data/creaturescripts/scripts/fraglook.lua)
[4/12/2019 22:7:34] data/creaturescripts/scripts/fraglook.lua:46: ')' expected near 'string'
[4/12/2019 22:7:34] [Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:46: ')' expected near 'string'
[4/12/2019 22:7:34] [Error - Event::checkScript] Cannot load script (data/creaturescripts/scripts/fraglook.lua)
[4/12/2019 22:7:34] data/creaturescripts/scripts/fraglook.lua:46: ')' expected near 'string'

 

function getDodge(cid)
	local total = 0
	for i = 1, 10 do
		local item = getPlayerSlotItem(cid, i)
		total = total + (getItemAttribute(item.uid, "dodgePercent") or 0)
	end
	return total
end

Esqueci do retorno, tenta novamente


Edited by Ramon RBN (see edit history)

Share this post


Link to post
Share on other sites

@Ramon RBN 

deu erro

/2019 10:47:7] >>> Loading creaturescripts... [Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near 'string'
[5/12/2019 10:47:7] [Error - Event::checkScript] Cannot load script (data/creaturescripts/scripts/fraglook.lua)
[5/12/2019 10:47:7] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near 'string'
[5/12/2019 10:47:8] [Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near 'string'
[5/12/2019 10:47:8] [Error - Event::checkScript] Cannot load script (data/creaturescripts/scripts/fraglook.lua)
[5/12/2019 10:47:8] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near 'string'

 

linha 47:

doPlayerSetSpecialDescription(cid,' [Frags: ' .. getPlayerFrags(thing.uid) .. '], [Critical: '..math.max(0,(tonumber(getCreatureStorage(cid,48903)) or 0))..'/200], 'string = string..' [Dodge: ' ..getDodge(cid).. '%].')

 


Share this post


Link to post
Share on other sites
1 minuto atrás, DouGlaS Mapper disse:

@Ramon RBN 

deu erro

/2019 10:47:7] >>> Loading creaturescripts... [Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near 'string'
[5/12/2019 10:47:7] [Error - Event::checkScript] Cannot load script (data/creaturescripts/scripts/fraglook.lua)
[5/12/2019 10:47:7] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near 'string'
[5/12/2019 10:47:8] [Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near 'string'
[5/12/2019 10:47:8] [Error - Event::checkScript] Cannot load script (data/creaturescripts/scripts/fraglook.lua)
[5/12/2019 10:47:8] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near 'string'

 

linha 47:


doPlayerSetSpecialDescription(cid,' [Frags: ' .. getPlayerFrags(thing.uid) .. '], [Critical: '..math.max(0,(tonumber(getCreatureStorage(cid,48903)) or 0))..'/200], 'string = string..' [Dodge: ' ..getDodge(cid).. '%].')

 

 

Você está alterando o que eu te mandei, pensei que o problema seria o código mas é a forma como você alterou.

 

 

No final tem essa parte

..'/200], 'string = string..' [Dodge: ' ..getDodge(cid).. '%].')

O erro é, você ao abrir uma função nos '' precisa preencher com dois pontos antes e depois dela, exemplo:

'..string..'

 

Porém a forma que você fez está errada pois o 

' ..getDodge(cid).. '

já retorna o número, não precisa usar

string = string..

a forma correta é 

..'/200], [Dodge: ' ..getDodge(cid).. '%].')

 

Na parte de baixo, é usado 

string = string..' [Dodge: ' ..getDodge(cid).. '%]'

por conta de ser uma mensagem, e ele completa ela com os dados, ela é iniciada sem nada e a cada 'if' é adicionado um novo dado na linha, exemplo:

local msg = ""
if (a == 1) 
	msg = "tem 1"

if (b == 2) 
	msg = msg..", 2"

ou seja, ao enviar a mensagem final pro jogador seria:

se não tiver nenhum 1 e 2:

""

se tiver apenas 1:

"tem 1"

se tiver apenas 2:

", 2"

e se tiver ambos os dois:

"tem 1, 2"

 


Share this post


Link to post
Share on other sites

@Ramon RBN 

 

[5/12/2019 11:4:49] >>> Loading creaturescripts... [Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near '['
[5/12/2019 11:4:49] [Error - Event::checkScript] Cannot load script (data/creaturescripts/scripts/fraglook.lua)
[5/12/2019 11:4:49] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near '['
[5/12/2019 11:4:49] [Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near '['
[5/12/2019 11:4:49] [Error - Event::checkScript] Cannot load script (data/creaturescripts/scripts/fraglook.lua)
[5/12/2019 11:4:49] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near '['


Share this post


Link to post
Share on other sites
2 minutos atrás, DouGlaS Mapper disse:

@Ramon RBN 

 

[5/12/2019 11:4:49] >>> Loading creaturescripts... [Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near '['
[5/12/2019 11:4:49] [Error - Event::checkScript] Cannot load script (data/creaturescripts/scripts/fraglook.lua)
[5/12/2019 11:4:49] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near '['
[5/12/2019 11:4:49] [Error - LuaInterface::loadFile] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near '['
[5/12/2019 11:4:49] [Error - Event::checkScript] Cannot load script (data/creaturescripts/scripts/fraglook.lua)
[5/12/2019 11:4:49] data/creaturescripts/scripts/fraglook.lua:47: ')' expected near '['

 

Me manda o código completo de toda a pasta.


Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


Open Tibia Server

Quer aprender a criar seu próprio servidor de Tibia? Então está no lugar certo, aqui você encontrará milhares de tutorias, scripts, códigos, mapas e utilitários para que você possa fazer o seu próprio servidor de Tibia começando do zero.

Redes Sociais

Anuncie no Tibia King

Precisa de mais visibilidade em seus projetos? Quer fazer um plano publicitário para o seu servidor? Anuncie no Tibia King e faça sua divulgação, possuímos centenas de acessos simultâneos e milhares diários, com certeza será a sua solução!

×
×
  • Create New...