Here is my action script: http://otland.net/f81/buy-levels-176840/
data/npc/Eazy.xml
data/npc/scripts/buylevel.lua:
Rep++?
data/npc/Eazy.xml
XML:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Eazy" nameDescription="Eazy, the npc that sells levels" script="buylevel.lua" walkinterval="2000" floorchange="0" skull="green">
<health now="100" max="100"/>
<look type="130" head="39" body="122" legs="125" feet="57" addons="0"/>
<parameters>
<parameter key="message_greet" value="Hello |PLAYERNAME|. I am selling levels."/>
<parameter key="message_decline" value="Is one million gold coins too much for you? Get out of here!"/>
</parameters>
</npc>
data/npc/scripts/buylevel.lua:
Lua:
-- Created by Eazy M @ otland.net
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 config = {
addLevels = 2,
costAmount = 1000000,
maxLevel = 300,
}
if(msgcontains(msg, 'buy') or msgcontains(msg, 'level')) then
selfSay('Do you want to buy '..config.addLevels..' level(s) for '..config.costAmount..' gold?', cid)
talkState[talkUser] = 1
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
if getPlayerLevel(cid) < config.maxLevel then
if(doPlayerRemoveMoney(cid, config.costAmount)) then
doPlayerAddLevel(cid, config.addLevels)
selfSay('You just bought '.. config.addLevels ..' levels for '.. config.costAmount ..' gold coins.', cid)
else
selfSay('Sorry, you don\'t have enough gold.', cid)
end
else
selfSay('Sorry, you are too high level to buy levels.', cid)
end
talkState[talkUser] = 0
elseif(msgcontains(msg, 'no') and isInArray({1}, talkState[talkUser])) then
talkState[talkUser] = 0
selfSay('Ok then.', cid)
end
return true
end
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Rep++?