• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

[Request] NPC

tanii

Empire-war.com
Joined
Jan 16, 2015
Messages
383
Solutions
1
Reaction score
12
Hello Otlanders today i am searching for 1 NPC

i am requesting npc do 3 next things.

-I can change 100 soul orbs for 1kk experience

-100 soul orbs for 20 premium points.

-I can give you promotion for 1500 crystal coins

i request this all in same npc any body can help me!

version 0.3.6
 
Idk what a 'premium point' is.
I made it give 20 days of premium instead.

Completely untested, but 99% sure there are no bugs.
Lua file only. Create the npc.xml, and link the lua file like normal.
Code:
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 greet(cid)   talkState[cid] = 0   return true end
function getNpcName() return getCreatureName(getNpcId()) 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 player_gold  = getPlayerItemCount(cid,2148)
   local player_plat  = getPlayerItemCount(cid,2152)*100
   local player_crys  = getPlayerItemCount(cid,2160)*10000
   local player_money  = player_gold + player_plat + player_crys
   
   if msgcontains(msg, "name") then
     selfSay("My name is " .. getNpcName() .. ".", cid)
   elseif msgcontains(msg, "help") then
     selfSay("Keywords available: name, help, promotion, premium, experience.", cid)
     
   -- Promotion
   elseif msgcontains(msg, "promotion") and getPlayerPromotionLevel(cid) < 1 then
     selfSay("I can promote you for 15 million gold peices. Would you like to receive your promotion?", cid)
     talkState[talkUser] = 1
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 and player_money >= 15000000 then
     doPlayerRemoveMoney(cid, 15000000)
     doPlayerSetPromotionLevel(cid, getPlayerPromotionLevel(cid) + 1)
     selfSay("Congratulations! You have been promoted to ".. getPlayerVocationName(cid) .."!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 and player_money < 15000000 then
     selfSay("You do not have enough gold to complete this transaction.", cid)
     talkState[talkUser] = 0
     
   -- Premium
   elseif msgcontains(msg, "premium") then
     selfSay("I will trade 100 soul orbs for 20 days of premium. Would you like to do that?", cid)
     talkState[talkUser] = 2
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 and getPlayerItemCount(cid, 5944) >= 100 then
     doPlayerRemoveItem(cid, 5944, 100)
     doPlayerAddPremiumDays(cid, 20)
     selfSay("Congratulations! You have received 20 days of premium!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 and getPlayerItemCount(cid, 5944) < 100 then
     selfSay("You do not have enough soul orbs to complete this transaction.", cid)
     talkState[talkUser] = 0
     
   -- Experience
   elseif msgcontains(msg, "experience") then
     selfSay("I will trade 100 soul orbs for 1 million experience. Would you like to do that?", cid)
     talkState[talkUser] = 3
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 3 and getPlayerItemCount(cid, 5944) >= 100 then
     doPlayerRemoveItem(cid, 5944, 100)
     doPlayerAddExperience(cid, 1000000)
     selfSay("Congratulations! You have received 1 million experience!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 3 and getPlayerItemCount(cid, 5944) < 100 then
     selfSay("You do not have enough soul orbs to complete this transaction.", cid)
     talkState[talkUser] = 0
   
   -- If they say something other then yes
   elseif msgcontains(msg, "") and talkState[talkUser] >= 1
     selfSay("No then.", cid)
     talkState[talkUser] = 0
     
   end
   return true   
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Idk what a 'premium point' is.
I made it give 20 days of premium instead.

Completely untested, but 99% sure there are no bugs.
Lua file only. Create the npc.xml, and link the lua file like normal.
Code:
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 greet(cid)   talkState[cid] = 0   return true end
function getNpcName() return getCreatureName(getNpcId()) 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 player_gold  = getPlayerItemCount(cid,2148)
   local player_plat  = getPlayerItemCount(cid,2152)*100
   local player_crys  = getPlayerItemCount(cid,2160)*10000
   local player_money  = player_gold + player_plat + player_crys
  
   if msgcontains(msg, "name") then
     selfSay("My name is " .. getNpcName() .. ".", cid)
   elseif msgcontains(msg, "help") then
     selfSay("Keywords available: name, help, promotion, premium, experience.", cid)
    
   -- Promotion
   elseif msgcontains(msg, "promotion") and getPlayerPromotionLevel(cid) < 1 then
     selfSay("I can promote you for 15 million gold peices. Would you like to receive your promotion?", cid)
     talkState[talkUser] = 1
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 and player_money >= 15000000 then
     doPlayerRemoveMoney(cid, 15000000)
     doPlayerSetPromotionLevel(cid, getPlayerPromotionLevel(cid) + 1)
     selfSay("Congratulations! You have been promoted to ".. getPlayerVocationName(cid) .."!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 and player_money < 15000000 then
     selfSay("You do not have enough gold to complete this transaction.", cid)
     talkState[talkUser] = 0
    
   -- Premium
   elseif msgcontains(msg, "premium") then
     selfSay("I will trade 100 soul orbs for 20 days of premium. Would you like to do that?", cid)
     talkState[talkUser] = 2
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 and getPlayerItemCount(cid, 5944) >= 100 then
     doPlayerRemoveItem(cid, 5944, 100)
     doPlayerAddPremiumDays(cid, 20)
     selfSay("Congratulations! You have received 20 days of premium!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 and getPlayerItemCount(cid, 5944) < 100 then
     selfSay("You do not have enough soul orbs to complete this transaction.", cid)
     talkState[talkUser] = 0
    
   -- Experience
   elseif msgcontains(msg, "experience") then
     selfSay("I will trade 100 soul orbs for 1 million experience. Would you like to do that?", cid)
     talkState[talkUser] = 3
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 3 and getPlayerItemCount(cid, 5944) >= 100 then
     doPlayerRemoveItem(cid, 5944, 100)
     doPlayerAddExperience(cid, 1000000)
     selfSay("Congratulations! You have received 1 million experience!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 3 and getPlayerItemCount(cid, 5944) < 100 then
     selfSay("You do not have enough soul orbs to complete this transaction.", cid)
     talkState[talkUser] = 0
  
   -- If they say something other then yes
   elseif msgcontains(msg, "") and talkState[talkUser] >= 1
     selfSay("No then.", cid)
     talkState[talkUser] = 0
    
   end
   return true  
end

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

hello sir, first of all thank you so much.

and second the script not worked i founded error at run server.

[27/08/2015 10:06:22] [Error - LuaScriptInterface::loadFile] data/npc/scripts/mission.lua:71: 'then' expected near 'selfSay'
[27/08/2015 10:06:22] [Warning - NpcScript::NpcScript] Cannot load script: data/npc/scripts/mission.lua
[27/08/2015 10:06:22] data/npc/scripts/mission.lua:71: 'then' expected near 'selfSay'

this is error can you fix that?
 
Find this
Code:
elseif msgcontains(msg, "") and talkState[talkUser] >= 1
Replace with this
Code:
elseif msgcontains(msg, "") and talkState[talkUser] >= 1 then
My bad :oops:
 
local player_gold = getPlayerItemCount(cid,2148)
local player_plat = getPlayerItemCount(cid,2152)*100
local player_crys = getPlayerItemCount(cid,2160)*10000
local player_money = player_gold + player_plat + player_crys

Code:
getPlayerMoney(cid)
 
To set only 4x you need to install this:
https://otland.net/threads/how-to-set-a-account-storage.30205/

use the storage value to check how many times they have changed orbs for premium.



lastly use this:
Code:
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 greet(cid)   talkState[cid] = 0   return true end
function getNpcName() return getCreatureName(getNpcId()) 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
   
   if msgcontains(msg, "name") then
     selfSay("My name is " .. getNpcName() .. ".", cid)
   elseif msgcontains(msg, "help") then
     selfSay("Keywords available: name, help, promotion, premium, experience.", cid)
     
   -- Promotion
   elseif msgcontains(msg, "promotion") and getPlayerPromotionLevel(cid) < 1 then
     selfSay("I can promote you for 15 million gold peices. Would you like to receive your promotion?", cid)
     talkState[talkUser] = 1
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 and getPlayerMoney(cid) >= 15000000 then
     doPlayerRemoveMoney(cid, 15000000)
     doPlayerSetPromotionLevel(cid, getPlayerPromotionLevel(cid) + 1)
     selfSay("Congratulations! You have been promoted to ".. getPlayerVocationName(cid) .."!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 and getPlayerMoney(cid) < 15000000 then
     selfSay("You do not have enough gold to complete this transaction.", cid)
     talkState[talkUser] = 0
     
   -- Premium
   elseif msgcontains(msg, "premium") then
     selfSay("I will trade 100 soul orbs for 20 days of premium. Would you like to do that?", cid)
     talkState[talkUser] = 2
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 and getPlayerItemCount(cid, 5944) >= 100 then
     doPlayerRemoveItem(cid, 5944, 100)
     doPlayerAddPremiumDays(cid, 20)
     selfSay("Congratulations! You have received 20 days of premium!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 and getPlayerItemCount(cid, 5944) < 100 then
     selfSay("You do not have enough soul orbs to complete this transaction.", cid)
     talkState[talkUser] = 0
     
   -- Experience
   elseif msgcontains(msg, "experience") then
     selfSay("I will trade 100 soul orbs for 1 million experience. Would you like to do that?", cid)
     talkState[talkUser] = 3
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 3 and getPlayerItemCount(cid, 5944) >= 100 then
     doPlayerRemoveItem(cid, 5944, 100)
     doPlayerAddExperience(cid, 1000000)
     selfSay("Congratulations! You have received 1 million experience!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 3 and getPlayerItemCount(cid, 5944) < 100 then
     selfSay("You do not have enough soul orbs to complete this transaction.", cid)
     talkState[talkUser] = 0
   
   -- If they say something other then yes
   elseif msgcontains(msg, "") and talkState[talkUser] >= 1
     selfSay("No then.", cid)
     talkState[talkUser] = 0
     
   end
   return true  
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
To set only 4x you need to install this:
https://otland.net/threads/how-to-set-a-account-storage.30205/

use the storage value to check how many times they have changed orbs for premium.



lastly use this:
Code:
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 greet(cid)   talkState[cid] = 0   return true end
function getNpcName() return getCreatureName(getNpcId()) 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
 
   if msgcontains(msg, "name") then
     selfSay("My name is " .. getNpcName() .. ".", cid)
   elseif msgcontains(msg, "help") then
     selfSay("Keywords available: name, help, promotion, premium, experience.", cid)
   
   -- Promotion
   elseif msgcontains(msg, "promotion") and getPlayerPromotionLevel(cid) < 1 then
     selfSay("I can promote you for 15 million gold peices. Would you like to receive your promotion?", cid)
     talkState[talkUser] = 1
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 and getPlayerMoney(cid) >= 15000000 then
     doPlayerRemoveMoney(cid, 15000000)
     doPlayerSetPromotionLevel(cid, getPlayerPromotionLevel(cid) + 1)
     selfSay("Congratulations! You have been promoted to ".. getPlayerVocationName(cid) .."!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 and getPlayerMoney(cid) < 15000000 then
     selfSay("You do not have enough gold to complete this transaction.", cid)
     talkState[talkUser] = 0
   
   -- Premium
   elseif msgcontains(msg, "premium") then
     selfSay("I will trade 100 soul orbs for 20 days of premium. Would you like to do that?", cid)
     talkState[talkUser] = 2
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 and getPlayerItemCount(cid, 5944) >= 100 then
     doPlayerRemoveItem(cid, 5944, 100)
     doPlayerAddPremiumDays(cid, 20)
     selfSay("Congratulations! You have received 20 days of premium!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 2 and getPlayerItemCount(cid, 5944) < 100 then
     selfSay("You do not have enough soul orbs to complete this transaction.", cid)
     talkState[talkUser] = 0
   
   -- Experience
   elseif msgcontains(msg, "experience") then
     selfSay("I will trade 100 soul orbs for 1 million experience. Would you like to do that?", cid)
     talkState[talkUser] = 3
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 3 and getPlayerItemCount(cid, 5944) >= 100 then
     doPlayerRemoveItem(cid, 5944, 100)
     doPlayerAddExperience(cid, 1000000)
     selfSay("Congratulations! You have received 1 million experience!", cid)
     talkState[talkUser] = 0
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 3 and getPlayerItemCount(cid, 5944) < 100 then
     selfSay("You do not have enough soul orbs to complete this transaction.", cid)
     talkState[talkUser] = 0
 
   -- If they say something other then yes
   elseif msgcontains(msg, "") and talkState[talkUser] >= 1
     selfSay("No then.", cid)
     talkState[talkUser] = 0
   
   end
   return true
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
you can just use getAccountNumberByPlayer and getPlayersByAccountNumber
 
Are you saying use something like this:
Code:
setPlayerStorageValue(cid, getAccountNumberByPlayer(cid), 1)
getPlayerStorageValue(cid, getAccountNumberByPlayer(cid))

If not then I dont think you know what your talking about.
 
Code:
local player = Player("Zothion")
local acc = getAccountNumberByPlayer(player)
local chars = getPlayersByAccountNumber(acc)
local n = getPlayerStorageValue(player, acc)
for i=1,#chars,1 do
setPlayerStorageValue(chars[i], acc, n+1)
end
and to check
Code:
getPlayerStorageValue(player, getAccountNumberByPlayer(player))
something like this
each time you redeem it you set the player storage value acc number to what it previously was +1, for all chars on the account, no need to database queries
 
Or he could install that account storage number and all of

Code:
local player = Player("Zothion")
local acc = getAccountNumberByPlayer(player)
local chars = getPlayersByAccountNumber(acc)
local n = getPlayerStorageValue(player, acc)
for i=1,#chars,1 do
setPlayerStorageValue(chars[i], acc, n+1)
end

Would just be

Code:
setPlayerAccountStorage(account, storage, value)
getPlayerAccountStorage(account, storage)
 
So if an account has 6 players you want to create 6 separate storage's for each player? This will cause a lot of lag. Especially if he uses this method for multiple scripts.
 
yes, when setting it would set an individual storage for each char on the account, but in most cases it will only be fetching a storage value (since you rarely need to set the storage value, but much more often need to get it, and on ots, atleast for me personally, i create a new account for each character since on most you cant be logged in with several from same acc)

i completely forgot about being able to create new characters and going around it, which is easily solveable but would require code either on login, or on char creation, but its more confusing

however, doing it with the link you provided, you have to run the query to create the correct table if you ever need to use a fresh database, and i personally prefer just having to copy some .lua files :)
 
Code:
getPlayerMoney(cid)
Not defending my old piece of code too liberally, but when it was scripted like that because many people were using new currency,this was the only way calculate all the available currencies.
But yes, you are correct. That is the more proper way, if everyone edited their sources correctly.
 
Back
Top