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

NPC Buy levels

Eazy M

Developer
Joined
Oct 17, 2010
Messages
911
Reaction score
61
Location
.
Here is my action script: http://otland.net/f81/buy-levels-176840/

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++? :)
 

try this:
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

local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end
function Player:addLevel(amount)
    return self:addExperience(getExpForLevel(self:getLevel() + (amount and amount or 1)) - self:getExperience())
end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local player = Player(cid)
    if not player then
        return
    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
                player:addLevel(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())
 
try this:
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

local function getExpForLevel(level)
    level = level - 1
    return ((50 * level * level * level) - (150 * level * level) + (400 * level)) / 3
end
function Player:addLevel(amount)
    return self:addExperience(getExpForLevel(self:getLevel() + (amount and amount or 1)) - self:getExperience())
end

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local player = Player(cid)
    if not player then
        return
    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
                player:addLevel(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())


I LOVE YOU!
 
Back
Top