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

Lua Point Npc

3li Xiber

Active Member
Joined
Dec 29, 2014
Messages
395
Reaction score
31
Hello Otlanders ,
I need make npc to take 2 items for 5 points
in my script he take only 1 item
i tried to make it 2 items but failed at end
so i hope someone edit it for me
Rep++
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t = {}

local item = 6527 -- item id
local count = 150 -- count of itemID
local points = 5 -- amount of premium points

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
elseif msgcontains(msg, 'change') then
selfSay('are you sure you want to change '.. count ..' of '.. getItemNameById(item) ..' for '.. points ..' premium points?', cid)
t[cid] = 1
elseif t[cid] == 1 then
npcHandler:releaseFocus(cid)
t[cid] = nil
if msgcontains(msg, 'yes') then
if doPlayerRemoveItem(cid, item, count) then
local p = "UPDATE `accounts` SET `premium_points` = `premium_points` + "..points.." where id="..getPlayerAccountId(cid)
db.executeQuery(p)
selfSay('you have recieved '.. points ..' premium points', cid)
else
selfSay('you don\'t have enough coins you need '.. count ..' of '.. getItemNameById(item) ..' to recieve '.. points ..' premium points', cid)
end
end
end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Try out this one.

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t = {}

{local item = 6527 -- item id , local count = 150
local item = item id , local count = number
}
local points = 5 -- amount of premium points

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
elseif msgcontains(msg, 'change') then
selfSay('are you sure you want to change '.. count ..' of '.. getItemNameById(item) ..' for '.. points ..' premium points?', cid)
t[cid] = 1
elseif t[cid] == 1 then
npcHandler:releaseFocus(cid)
t[cid] = nil
if msgcontains(msg, 'yes') then
if doPlayerRemoveItem(cid, item, count) then
local p = "UPDATE `accounts` SET `premium_points` = `premium_points` + "..points.." where id="..getPlayerAccountId(cid)
db.executeQuery(p)
selfSay('you have recieved '.. points ..' premium points', cid)
else
selfSay('you don\'t have enough coins you need '.. count ..' of '.. getItemNameById(item) ..' to recieve '.. points ..' premium points', cid)
end
end
end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Try out this one.

Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t = {}

{local item = 6527 -- item id , local count = 150
local item = item id , local count = number
}
local points = 5 -- amount of premium points

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
elseif msgcontains(msg, 'change') then
selfSay('are you sure you want to change '.. count ..' of '.. getItemNameById(item) ..' for '.. points ..' premium points?', cid)
t[cid] = 1
elseif t[cid] == 1 then
npcHandler:releaseFocus(cid)
t[cid] = nil
if msgcontains(msg, 'yes') then
if doPlayerRemoveItem(cid, item, count) then
local p = "UPDATE `accounts` SET `premium_points` = `premium_points` + "..points.." where id="..getPlayerAccountId(cid)
db.executeQuery(p)
selfSay('you have recieved '.. points ..' premium points', cid)
else
selfSay('you don\'t have enough coins you need '.. count ..' of '.. getItemNameById(item) ..' to recieve '.. points ..' premium points', cid)
end
end
end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())


[22/02/2015 01:35:32] [Error - LuaScriptInterface::loadFile] data/npc/scripts/points1.lua:7: unexpected symbol near '{'
[22/02/2015 01:35:32] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/points1.lua
[22/02/2015 01:35:32] data/npc/scripts/points1.lua:7: unexpected symbol near '{'
 
Updated, I originally didn't account for npc telling how many items or their names
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t = {}
-- this will allow you to use 1 item or 100 or more items, its good to have flexible code :)
local item = {
    {id = 6527, count = 150}, -- 1st item
    {id = 6527, count = 150} -- 2nd item
}


local points = 5 -- amount of premium points

function removeItems(item)
    if type(item) == "table" then -- make sure item is a table
        for index = 1, #item do
            if getPlayerItemCount(cid, item[index].id) == item[index].count then
            -- do nothing, we want to make sure the player has all the items needed before we remove them
            else
                return false -- if they don't have the required amount then return false
            end
        end
        for i = 1, #item do -- now remove them
            doPlayerRemoveItem(cid, item[i].id, item[i].count)
        end
        return true -- return true if all the items have been removed
    end
end

function getItemsCountAndNames(item)
    local names = {}
    for i = 1, #item do
        names[i] = item[i].count.." of ".. getItemNameById(item[i].id).." "
    end
    return table.concat(names)
end

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
    elseif msgcontains(msg, 'change') then
   
        selfSay('are you sure you want to change '..getItemsCountAndNames(item) ..'for '.. points ..' premium points?', cid)
        t[cid] = 1
    elseif t[cid] == 1 then
        npcHandler:releaseFocus(cid)
        t[cid] = nil
        if msgcontains(msg, 'yes') then
            if removeItems(item) then
                local p = "UPDATE `accounts` SET `premium_points` = `premium_points` + "..points.." where id="..getPlayerAccountId(cid)
                db.executeQuery(p)
                selfSay('you have recieved '.. points ..' premium points', cid)
            else
                selfSay('you don\'t have enough coins you need '.. getItemsCountAndNames(item) ..'to recieve '.. points ..' premium points', cid)
            end
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Code:
[22/02/2015 22:51:16] [Error - Npc interface]
[22/02/2015 22:51:16] data/npc/scripts/points1.lua:onCreatureSay
[22/02/2015 22:51:16] Description:
[22/02/2015 22:51:16] (luaGetPlayerItemCount) Player not found
 
Yeah I forgot cid
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local t = {}
-- this will allow you to use 1 item or 100 or more items, its good to have flexible code :)
local item = {
    {id = 6527, count = 150}, -- 1st item
    {id = 6527, count = 150} -- 2nd item
}


local points = 5 -- amount of premium points

function removeItems(cid, item)
    if type(item) == "table" then -- make sure item is a table
        for index = 1, #item do
            if getPlayerItemCount(cid, item[index].id) == item[index].count then
            -- do nothing, we want to make sure the player has all the items needed before we remove them
            else
                return false -- if they don't have the required amount then return false
            end
        end
        for i = 1, #item do -- now remove them
            doPlayerRemoveItem(cid, item[i].id, item[i].count)
        end
        return true -- return true if all the items have been removed
    end
end

function getItemsCountAndNames(item)
    local names = {}
    for i = 1, #item do
        names[i] = item[i].count.." of ".. getItemNameById(item[i].id).." "
    end
    return table.concat(names)
end

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
    elseif msgcontains(msg, 'change') then

        selfSay('are you sure you want to change '..getItemsCountAndNames(item) ..'for '.. points ..' premium points?', cid)
        t[cid] = 1
    elseif t[cid] == 1 then
        npcHandler:releaseFocus(cid)
        t[cid] = nil
        if msgcontains(msg, 'yes') then
            if removeItems(cid, item) then
                local p = "UPDATE `accounts` SET `premium_points` = `premium_points` + "..points.." where id="..getPlayerAccountId(cid)
                db.executeQuery(p)
                selfSay('you have recieved '.. points ..' premium points', cid)
            else
                selfSay('you don\'t have enough coins you need '.. getItemsCountAndNames(item) ..'to recieve '.. points ..' premium points', cid)
            end
        end
    end
    return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
thx alot Jotran u are really a nice girl :)

1 more request in the same script hope u do it for me :)
i need only 4 change per account
i mean only 4 Changes Can Player make per 1 account
 
Back
Top