Ir para conteúdo
  • Cadastre-se

Posts Recomendados

PET SYSTEM..

Comandos:

!pet summon

!pet buy Cat

!pet release

!pet move

!pet say

Começando:

Vá em Data>Talkactions.xml Adicione Isso:


<talkaction words="!pet" script="pet.lua"/>
[/codebox]

Agora em Data>Talkactions>Scripts crie uma pasta.lua chamada pet e coloque isso:

[codebox]
local PET =
-- CONFIG --
{ -- storages
name = 7700,
petuid = 7701,
online = 7702,
damage = 7703,
allowed = { -- allowed pets, costs & level required
["cat"] = {cost = 50, level = 1},
["dog"] = {cost = 50, level = 1},
["deer"] = {cost = 50, level = 1},
["pig"] = {cost = 50, level = 1},
["parrot"] = {cost = 50, level = 1},
["seagull"] = {cost = 50, level = 1},
["chicken"] = {cost = 50, level = 1},
["rabbit"] = {cost = 50, level = 1},
["squirrel"] = {cost = 50, level = 1},
["frog"] = {cost = 50, level = 1},
["rat"] = {cost = 50, level = 1},
["sheep"] = {cost = 100, level = 1},
["wolf"] = {cost = 300, level = 8},
["skeleton"] = {cost = 300, level = 15},
["war wolf"] = {cost = 1000, level = 20},
["demon skeleton"] = {cost = 3000, level = 25}
},
direction = {["up"] = NORTH, ["down"] = SOUTH, ["right"] = EAST, ["left"] = WEST}, -- used with !pet move
help = { -- used with !pet say
"Type '!pet summon' to summon your pet.",
"Type '!pet buy [petname]' to buy a pet. e.g. '!pet buy war_wolf'",
"Type '!pet move [direction]' to ask your pet to move.",
"Type '!pet say \"text' to ask your pet to say something.",
"Type '!pet release' to release your pet."
}
}
function petHelp(p)
doPlayerSendTextMessage(p.cid, 19, PET.help[p.i])
end
function onSay(cid, words, param)
local p = {""}
if param ~= "" then
p = string.explode(param, " ")
end
local petuid = getPlayerStorageValue(cid, PET.petuid)
local online = getPlayerStorageValue(cid, PET.online)
if p[1] == "help" then
for i = 1, #PET.help do
addEvent(petHelp, 1000*i - 1000, {i = i, cid = cid})
end
elseif p[1] == "summon" then
local name = getPlayerStorageString(cid, PET.name)
if isCreature(petuid) == FALSE then
if online == 1 then
local tile = getClosestFreeTile(cid, getThingPos(cid), FALSE, FALSE)
if getTilePzInfo(getThingPos(cid)) ~= 1 and getTilePzInfo(tile) ~= 1 then
if name ~= "" then
if getMonsterInfo(name) ~= nil then
petuid = doSummonCreature(name, tile)
doConvinceCreature(cid, petuid)
doCreatureSay(petuid, 'hey, sup', TALKTYPE_ORANGE_1)
doChangeSpeed(petuid, getCreatureBaseSpeed(cid) - getCreatureBaseSpeed(petuid))
setPlayerStorageValue(cid, PET.online, 2)
setPlayerStorageValue(cid, PET.petuid, petuid)
doPlayerSendCancel(cid, 'Summoning '..name..'.')
if getPlayerStorageValue(cid, PET.damage) > 0 then
if getPlayerStorageValue(cid, PET.damage) < getCreatureMaxHealth(petuid) then
doCreatureAddHealth(petuid, getPlayerStorageValue(cid, PET.damage)*-1)
end
end
else
doPlayerSendCancel(cid, 'Invalid pet name.')
end
else
doPlayerSendCancel(cid, 'Invalid pet name.')
end
else
doPlayerSendCancel(cid, 'You may not summon your pet here.')
end
else
doPlayerSendCancel(cid, 'You do not have a pet. Type !pet <pet name> to get one.')
end
else
setPlayerStorageValue(cid, PET.damage, getCreatureMaxHealth(petuid) - getCreatureHealth(petuid))
doCreatureSay(petuid, 'gtg, cya', TALKTYPE_ORANGE_1)
doSendMagicEffect(getThingPos(petuid),CONST_ME_POFF)
doRemoveCreature(petuid)
doPlayerSendCancel(cid, 'Retrieving '..name..'.')
setPlayerStorageValue(cid, 7702, 1)
end
elseif p[1] == "buy" then
local text
if p[2] ~= nil then
name = string.gsub(p[2], "_", " ")
if (isCreature(petuid) ~= TRUE and online == 2) or online <= 0 then
if PET.allowed[name] ~= nil then
if getPlayerLevel(cid) >= PET.allowed[name].level then
if getPlayerMoney(cid) >= PET.allowed[name].cost then
doPlayerRemoveMoney(cid, PET.allowed[name].cost)
setPlayerStorageValue(cid, PET.online, 1)
setPlayerStorageValue(cid, PET.damage, 0)
setPlayerStorageString(cid, PET.name, name)
text = "You have bought a pet \""..name.."\" for "..PET.allowed[name].cost.." gold coins."
else
text = "You do not have enough money. It costs "..PET.allowed[name].cost.." gold coins to buy a "..name.."."
end
else
text = "You need level "..PET.allowed[name].level.." to buy this pet."
end
else
text = "You may not buy that pet."
end
else
text = "You already have a pet."
end
else
text = "!pet buy [petname]"
end
if text ~= nil then
doPlayerSendTextMessage(cid, 19, text)
end
elseif p[1] == "move" then
if isCreature(petuid) == TRUE then
if p[2] ~= nil then
if PET.direction[p[2]] ~= nil then
if doTileQueryAdd(petuid, getPosByDir(getThingPos(petuid), PET.direction[p[2]], 1)) == 1 then
doMoveCreature(petuid, PET.direction[p[2]])
else
doPlayerSendCancel(cid, 'Tile is blocked.')
end
else
doPlayerSendCancel(cid, '!pet move [up/down/left/right]')
end
else
doPlayerSendCancel(cid, '!pet move [up/down/left/right]')
end
else
doPlayerSendCancel(cid, 'Summon a pet first.')
end
elseif p[1] == "say" then
text = string.explode(param, "\"")
if isCreature(petuid) == TRUE then
if text[2] ~= nil then
if string.len(text[2]) < 39 then
doCreatureSay(petuid, text[2], TALKTYPE_ORANGE_1)
else
doPlayerSendCancel(cid, 'Too long text.')
end
else
doPlayerSendCancel(cid, '!pet say "I am '..getCreatureName(cid)..'\'s pet.')
end
else
doPlayerSendCancel(cid, 'Summon a pet first.')
end
elseif p[1] == "release" then
if isCreature(petuid) == TRUE and getPlayerStorageValue(cid, PET.online) == 2 then
doCreatureSay(petuid, ':\'(', TALKTYPE_ORANGE_1)
doSendMagicEffect(getThingPos(petuid),CONST_ME_POFF)
doRemoveCreature(petuid)
doPlayerSendCancel(cid, 'Releasing '..name..'.')
setPlayerStorageValue(cid, 7702, 1)
end
setPlayerStorageValue(cid, PET.online, 2)
setPlayerStorageValue(cid, PET.damage, 0)
doPlayerSendTextMessage(cid, 19, "You have released your pet \""..name.."\".")
setPlayerStorageString(cid, PET.name, "")
else
doPlayerSendTextMessage(cid, 19, "!pet [help/summon/buy/move/say/release]")
end
return TRUE
end

Ok Acabamos com as Talkactions agora vá em Data>CreatureEvents.xml e Adicione Isso:

Obs: ( Caso Ja Ouver a Pasta Logout.lua Delete Tudu dela e Coloque a Nova )


<event type="logout" name="logout" event="script" value="logout.lua"/>
[/codebox]

Agora vá em Data>CreatureEvents>Scripts crie uma pasta.lua chamada logout e coloque isso:

[codebox]
local petuidstor = 7701 -- storages, have to be same as your other script.
local onlinestor = 7702
local damagestor = 7703
function onLogout(cid)
if isCreature(getPlayerStorageValue(cid, petuidstor)) == 1 then
if getPlayerStorageValue(cid, onlinestor) == 2 then
local petuid = getPlayerStorageValue(cid, petuidstor)
setPlayerStorageValue(cid, damagestor, getCreatureMaxHealth(petuid) - getCreatureHealth(petuid))
doSendMagicEffect(getThingPos(petuid),CONST_ME_POFF)
setPlayerStorageValue(cid, onlinestor, 1)
end
end
return TRUE
end

Abra a pata login.lua que se localiza em Data>CreatureEvents>Scripts abra ela e coloque isso:


registerCreatureEvent(cid, "logout")
[/codebox]

Agora para Finalizar vá em Data>Lib>Function.lua e Acresente Isso:

[codebox]
string.explode = function (str, sep)
local pos, t = 1, {}
if #sep == 0 or #str == 0 then
return
end

for s, e in function() return str:find(sep, pos) end do
table.insert(t, str:sub(pos, s - 1):trim())
pos = e + 1
end

table.insert(t, str:sub(pos):trim())
return t
end

_warpzone = 2147483648 -- start storing strings here (THIS IS THE ABSOLUTE MAXIMUM VALUE FOR THIS)
_maxlength = 1024 -- multiply by 3 to get the true length.

setPlayerStorageInteger = setPlayerStorageValue
getPlayerStorageInteger = getPlayerStorageValue

function setPlayerStorageString(cid, key, value)
if #value > (_maxlength-1) * 3 - 1 then -- Last word is reserved for 0 termination of the string.
error("Storage string is too long")
end
if key > _warpzone / _maxlength then
error("Storage string key is too large (" .. key .. ")")
end
key = _warpzone + key * _maxlength

local word = 0
local wordwrap = 0
local wordcount = 0
local i = 1
while i <= #value do
local byte = string.byte(string.sub(value, i, i))
word = bit.bor(word, bit.lshift(byte, wordwrap))
wordwrap = wordwrap + 8
if wordwrap == 24 then
--[[
In the ideal world we would be able to store 4 characters per word,
however, as the default return value for getPlayerStorageValue is
-1, we can't use the last bit.
]]--
setPlayerStorageInteger(cid, key + wordcount, word)
word = 0
wordwrap = 0
wordcount = wordcount + 1
end
i = i + 1
end
-- store the last word
setPlayerStorageInteger(cid, key + wordcount, word)
end

function getPlayerStorageString(cid, key)
if key > _warpzone / _maxlength then
error("Storage string key is too large (" .. key .. ")")
end
key = _warpzone + key * _maxlength

local wordcount = 0
local str = ""
while true do
if wordcount >= _maxlength then
break
end
local word = getPlayerStorageInteger(cid, key + wordcount)
if word == -1 then
-- end of string
break
else
-- Extract the 3 characters from the value
byte = bit.band(word, 255)
if byte == 0 then break else str = str .. string.char(byte) end
byte = bit.rshift(bit.band(word, 65280), 8)
if byte == 0 then break else str = str .. string.char(byte) end
byte = bit.rshift(bit.band(word, 16711680), 16)
if byte == 0 then break else str = str .. string.char(byte) end
end
wordcount = wordcount + 1
end
return str
end

Obs²: Delete Todos Arquivos de Pets System Velhos para nao Causar nem um Bug!!

Creditos:

jordanhenry.

Sugestoes, Duvidas Somente neste Topico!!

Abraços..

cachorro_magro.jpg      

Link para o post
Compartilhar em outros sites
  • 9 months later...

Amigo como é seu 1º post peço q leia as regras pq vc acabou de reviver um topico de mais de 60 dias inativo, e sobre o erro poste na seção Suporte OTServ


Regras Gerais 

 

"Califórnia Brasileira :cool: "

Link para o post
Compartilhar em outros sites

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo