Ir para conteúdo
  • Cadastre-se

(Resolvido)Npc Points Event e Item Points


Ir para solução Resolvido por Dwarfer,

Posts Recomendados

Um npc que venda itens determinados a partir de X quantidade de um sistema de points eventos.

 

Um action que possa ser usado em um item para ganhar points, pontos de eventos, e que a quantidade seja aleatória, Podendo ganhar entre. (o item some com um efeito no char)

15, 30, 50, 75 e 100 pontos.

 

(Eu não tenho um sistema de pontos de eventos, então se puder fazer uma coisa básica), até porque esse item só sera dado aos vencedores dos eventos

Editado por JcA (veja o histórico de edições)
Link para o post
Compartilhar em outros sites
  • Solução

Action:

 

Spoiler

local points = {15, 30, 50, 75, 100}

function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerStorageValue(cid, 92431) == -1 then
setPlayerStorageValue(cid, 92431, 0)
end
doPlayerAddEventPoints(cid, points[math.random(1, #points)])
doRemoveItem(item.uid)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_STUN)
return true
end

function doPlayerAddEventPoints(cid, amount)
local current = getPlayerStorageValue(cid, 92431)
setPlayerStorageValue(cid, 92431, current + amount)
return true
end

 

 

Em actions.xml: <action itemid="ID_DO_ITEM" event="script" value="NOMEDOARQUIVO.lua"/>

 

NPC:

 

Spoiler

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid

local shopWindow = {}

local t = {
[1111] = {buyprice = 1},
[2222] = {buyprice = 10},
[3333] = {buyprice = 3}
}

function doPlayerRemoveEventPoints(cid, amount)
local current = getPlayerStorageValue(cid, 92431)
if current - amount < 0 then
        return false
    else
        setPlayerStorageValue(cid, 92431, current - amount)
    end
return true
end

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
    if t[item] and doPlayerRemoveEventPoints(cid, t[item].buyprice) then
        doPlayerAddItem(cid, item)
        selfSay("Here you go.", cid)
    else
        selfSay("Você não tem "..t[item].buyprice.." points.", cid)
    end
    return true
end

if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
    for var, ret in pairs(t) do
        table.insert(shopWindow, {id = var, subType = 0, buy = ret.buyprice, sell = 0, name = getItemNameById(var)})
    end
    openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

 

Contato:

 

Link para o post
Compartilhar em outros sites
11 horas atrás, Dwarfer disse:

Action:

 

  Ocultar conteúdo


local points = {15, 30, 50, 75, 100}

function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerStorageValue(cid, 92431) == -1 then
setPlayerStorageValue(cid, 92431, 0)
end
doPlayerAddEventPoints(cid, points[math.random(1, #points)])
doRemoveItem(item.uid)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_STUN)
return true
end

function doPlayerAddEventPoints(cid, amount)
local current = getPlayerStorageValue(cid, 92431)
setPlayerStorageValue(cid, 92431, current + amount)
return true
end

 

 

Em actions.xml: <action itemid="ID_DO_ITEM" event="script" value="NOMEDOARQUIVO.lua"/>

 

NPC:

 

  Ocultar conteúdo


local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid

local shopWindow = {}

local t = {
[1111] = {buyprice = 1},
[2222] = {buyprice = 10},
[3333] = {buyprice = 3}
}

function doPlayerRemoveEventPoints(cid, amount)
local current = getPlayerStorageValue(cid, 92431)
if current - amount < 0 then
        return false
    else
        setPlayerStorageValue(cid, 92431, current - amount)
    end
return true
end

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
    if t[item] and doPlayerRemoveEventPoints(cid, t[item].buyprice) then
        doPlayerAddItem(cid, item)
        selfSay("Here you go.", cid)
    else
        selfSay("Você não tem "..t[item].buyprice.." points.", cid)
    end
    return true
end

if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
    for var, ret in pairs(t) do
        table.insert(shopWindow, {id = var, subType = 0, buy = ret.buyprice, sell = 0, name = getItemNameById(var)})
    end
    openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

 

 

@Dwarfer Funcionou, mas você poderia dar uma olhada? Eu esqueci de citar uma função, então incrementei uma linha que mostra uma mensagem exibindo a quantidade de pontos que ganha, porém só mostra que ganhou "5 pontos", sendo que não tem essa quantidade kkkkk

 

local points = {15, 30, 50, 75, 100}

function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerStorageValue(cid, 92431) == -1 then
setPlayerStorageValue(cid, 92431, 0)
end
doPlayerAddEventPoints(cid, points[math.random(1, #points)])
doCreatureSay(cid, "Parabéns! Você recebeu ".. #points .." Event Points!", TALKTYPE_ORANGE_1)
doRemoveItem(item.uid)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_STUN)
return true
end

function doPlayerAddEventPoints(cid, amount)
local current = getPlayerStorageValue(cid, 92431)
setPlayerStorageValue(cid, 92431, current + amount)
return true
end

 

 

 

Link para o post
Compartilhar em outros sites
local points = {15, 30, 50, 75, 100}

function onUse(cid, item, fromPosition, itemEx, toPosition)
if getPlayerStorageValue(cid, 92431) == -1 then
setPlayerStorageValue(cid, 92431, 0)
end
rand = points[math.random(1, #points)]
doPlayerAddEventPoints(cid, rand)
doCreatureSay(cid, "Parabéns! Você recebeu " .. rand .. " Event Points!", TALKTYPE_ORANGE_1)
doRemoveItem(item.uid)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_STUN)
return true
end

function doPlayerAddEventPoints(cid, amount)
local current = getPlayerStorageValue(cid, 92431)
setPlayerStorageValue(cid, 92431, current + amount)
return true
end

 

Contato:

 

Link para o post
Compartilhar em outros sites

@Dwarfer pode criar um comando /eventpoints para mostrar quantos pontos possuo?

 

E um sistema que converte os pontos em item agrupado, que seria tipo o ID: 6527 que é agrupavel.

 

!converteventpoints

 

Então se eu tiver 15 pontos, vai virar 15 itens, e o mesmo serve pra comprar no npc?

Editado por mistermie (veja o histórico de edições)
Link para o post
Compartilhar em outros sites

Talkaction:

 

Spoiler

local id = 6527

function onSay(cid, words, param, channel)
local points = getPlayerStorageValue(cid, 92431)
if points <= 0 then return true end
doPlayerRemoveEventPoints(cid, points)
doPlayerAddItem(cid, id, points)
return true
end

function doPlayerRemoveEventPoints(cid, amount)
local current = getPlayerStorageValue(cid, 92431)
if current - amount < 0 then
        return false
    else
        setPlayerStorageValue(cid, 92431, current - amount)
    end
return true
end

 

 

Tag no talkactions.xml: <talkaction words="!converteventpoints" event="script" value="NOMEDOARQUIVO.lua"/>

 

Você já me pediu isso e o NPC em outro tópico: 

 

 

Além disso, criou outro tópico com a mesma questão.

 

 

 

Editado por Dwarfer (veja o histórico de edições)

Contato:

 

Link para o post
Compartilhar em outros sites
16 horas atrás, Dwarfer disse:

Talkaction:

 

  Mostrar conteúdo oculto


local id = 6527

function onSay(cid, words, param, channel)
local points = getPlayerStorageValue(cid, 92431)
doPlayerRemoveEventPoints(cid, points)
doPlayerAddItem(cid, id, points)
return true
end

function doPlayerRemoveEventPoints(cid, amount)
local current = getPlayerStorageValue(cid, 92431)
if current - amount < 0 then
        return false
    else
        setPlayerStorageValue(cid, 92431, current - amount)
    end
return true
end

 

 

Tag no talkactions.xml: <talkaction words="!converteventpoints" event="script" value="NOMEDOARQUIVO.lua"/>

 

Você já me pediu isso e o NPC em outro tópico: 

 

 

Além disso, criou outro tópico com a mesma questão.

 

 

 

 

Fui testar pra ver isso ae, deu crash no server, congela tudo

Link para o post
Compartilhar em outros sites
32 minutos atrás, Dwarfer disse:

Bom, aqui não crashou não, mas faltava uma verificação lá. Já editei.

 

Funcionou, mas,  vai faltar 1 scripts e 1 correçao, pra esse sistema de event points fica certo eu acho. Porque? O NPC não vende o item pelos coins 6527 que foi convertido. E um action que quando clica no coin, ele ganha 1 ponto equivalente a quantidade que ele tem, se você tem 50 pontos, converte em 50 coins, ai clica no 50 coins, ganha 50 pontos.

 

Só dor de cabeça pra vc kkkkkkkkkkk, se não quiser fazer tudo bem, dps dou um jeito ai no forum, obg

 

 

Link para o post
Compartilhar em outros sites

Qual a ideia de adicionar os pontos ao player ele ter que converter para ir ao Npc que aceita o item convertido a partir dos pontos se o Npc já aceita os pontos? >:(

Contato:

 

Link para o post
Compartilhar em outros sites
6 minutos atrás, Dwarfer disse:

Qual a ideia de adicionar os pontos ao player ele ter que converter para ir ao Npc que aceita o item convertido a partir dos pontos se o Npc já aceita os pontos? >:(

 

Os players podem vender os coins entre si, era esse o objetivo. 

Link para o post
Compartilhar em outros sites
9 minutos atrás, Dwarfer disse:

Os players podem vender o item que compram do Npc. 

 

Mais se o cara tiver dificuldades para achar o item que ele deseja vendendo? E mais facil os coins kkkkkkk

rlx, obrigado

Link para o post
Compartilhar em outros sites

Não, tranquilo,  é só que sempre ficam pedindo as mesmas coisas. Apesar de achar desnecessário (rsrs), pega aí:

 

NPC

 

Spoiler

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local money = 6527 -- ID_da_moeda
local t = {
[2154] = {price = 15}, -- [ID_DO_ITEM_QUE_SERÁ_VENDIDO] = {price = preço}
[2158] = {price = 25},
[2155] = {price = 70},
[2156] = {price = 100}
}
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if t[item] and not doPlayerRemoveItem(cid, money, t[item].price) then
selfSay("You need "..t[item].price.." "..getItemNameById(money)..".", cid)
else
doPlayerAddItem(cid, item)
selfSay("Here you go.", cid)
end
return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
for var, ret in pairs(t) do
table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})
end
openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

 

ACTION

 

function onUse(cid, item, fromPosition, itemEx, toPosition) 
doPlayerAddEventPoints(cid, item.type)
doRemoveItem(item.uid)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_STUN)
return true
end

function doPlayerAddEventPoints(cid, amount)
local current = getPlayerStorageValue(cid, 92431)
setPlayerStorageValue(cid, 92431, current + amount)
return true
end

 

<action itemid="ID_DO_ITEM" script="NOMEDOARQUIVO.lua" />

 

 

 

 

Contato:

 

Link para o post
Compartilhar em outros sites
1 hora atrás, Dwarfer disse:

Não, tranquilo,  é só que sempre ficam pedindo as mesmas coisas. Apesar de achar desnecessário (rsrs), pega aí:

 

NPC

 

  Ocultar conteúdo


local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVbehavior == CONVERSATION_DEFAULT and 0 or cid
local shopWindow = {}
local money = 6527 -- ID_da_moeda
local t = {
[2154] = {price = 15}, -- [ID_DO_ITEM_QUE_SERÁ_VENDIDO] = {price = preço}
[2158] = {price = 25},
[2155] = {price = 70},
[2156] = {price = 100}
}
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if t[item] and not doPlayerRemoveItem(cid, money, t[item].price) then
selfSay("You need "..t[item].price.." "..getItemNameById(money)..".", cid)
else
doPlayerAddItem(cid, item)
selfSay("Here you go.", cid)
end
return true
end
if (msgcontains(msg, 'trade') or msgcontains(msg, 'TRADE'))then
for var, ret in pairs(t) do
table.insert(shopWindow, {id = var, subType = 0, buy = ret.price, sell = 0, name = getItemNameById(var)})
end
openShopWindow(cid, shopWindow, onBuy, onSell)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

 

ACTION

 


function onUse(cid, item, fromPosition, itemEx, toPosition) 
doPlayerAddEventPoints(cid, item.type)
doRemoveItem(item.uid)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_STUN)
return true
end

function doPlayerAddEventPoints(cid, amount)
local current = getPlayerStorageValue(cid, 92431)
setPlayerStorageValue(cid, 92431, current + amount)
return true
end

 

<action itemid="ID_DO_ITEM" script="NOMEDOARQUIVO.lua" />

 

 

 

 

 

Você é um cara fora de série, sem mais, funcional!

 

<3

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