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

help with a simple thing.

Elaney

Member
Joined
Jan 1, 2009
Messages
1,561
Reaction score
12
Location
Sweden
LUA:
local price = 100000 -- Price of reset
local newlevel = 10 -- level after reset
local newexp = 9300 -- Exp after reset
local maxreset = 10
-- end config
 
function addReset(cid)
	return setPlayerStorageValue(cid, 36874, getResets(cid) + 1)
end
 
function getResets(cid)
	return math.max(0, getPlayerStorageValue(cid, 36874))
end
 
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
 
	if msgcontains(msg, 'reset') then
		selfSay(' Do you want to reset for '..price..' GP.', cid)
		talkState[cid] = 1
	elseif(msgcontains(msg, 'yes') and talkState[cid] == 1) then
		local resets = getResets(cid)
		if resets <= 3 then
			resets=-1
		end
		local minlevel = math.max(math.min(500 ) * 2, 4)
		if getPlayerMoney(cid) < price then
			selfSay('You must pay '..price..' gold coins to reset.', cid)
		elseif getPlayerLevel(cid) < minlevel then
			selfSay('you need '.. minlevel ..' to reset.', cid)
		else
			doPlayerRemoveMoney(cid,price)
			addReset(cid)
			playerid = getPlayerGUID(cid)
			doRemoveCreature(cid)
			db.executeQuery("UPDATE `players` SET `level`="..newlevel..",`experience`="..newexp.." WHERE `players`.`id`= ".. playerid .."")
		end
		talkState[cid] = 0
	elseif msgcontains(msg, 'no') and isInArray({1}, talkState[cid]) then
		talkState[cid] = 0
		selfSay('Yes', cid)
	elseif msgcontains(msg, 'resets') then
		selfSay('You Have '..getResets(cid)..' reset(s).', cid)
	end
 
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

what i want to be fixed is that when you reset first time, next time you can reset is double the first reset.

so lets say first reset is level 1000. next reset should be 2000 and next 4000 and next 8000 and next 10000.

Thanks in advanced

/Elaney
 
This example could help you :
LUA:
local money = 10292  -- storage for money

local cost = 2000   -- base cost


cost = math.max(getPlayerStorageValue(cid,money)*2, cost)  -- needed
if doPlayerRemoveMoney(cid,cost) then
	doReset(cid)
	setPlayerStorageValue(cid,money,cost)   -- needed
else
	selfSay("You dont have enough money.",cid)
end

I hope you get what i mean :p
 
LUA:
-- 
-- config
--local minlevel = 3000 -- level to reset
--local minlevel_vip = 2500 --  level for VIP
local price = 100000 -- Price of reset
local newlevel = 10 -- level after reset
local newexp = 9300 -- Exp after reset
local maxreset = 10
local cost = 500
local money = 36874
-- end config
 
function addReset(cid)
	return setPlayerStorageValue(cid,money,cost)
end
 
function getResets(cid)
	return math.max(0, getPlayerStorageValue(cid, 36874))
end
 
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
 
	if msgcontains(msg, 'reset') then
		selfSay(' Do you want to reset for '..price..' GP?', cid)
		talkState[cid] = 1
	elseif(msgcontains(msg, 'yes') and talkState[cid] == 1) then
		local resets = getResets(cid)
		if resets <= 3 then
			resets=-1
		end
		cost = math.max(getPlayerStorageValue(cid,money)*2, cost)
		if getPlayerMoney(cid) < price then
			selfSay('You must pay '..price..' gold coins to reset.', cid)
		elseif getPlayerLevel(cid) < cost then
			selfSay('you need to be level '.. cost ..' to reset.', cid)
		else
			doPlayerRemoveMoney(cid,price)
			addReset(cid)
			playerid = getPlayerGUID(cid)
			doRemoveCreature(cid)
			db.executeQuery("UPDATE `players` SET `level`="..newlevel..",`experience`="..newexp.." WHERE `players`.`id`= ".. playerid .."")
		end
		talkState[cid] = 0
	elseif msgcontains(msg, 'no') and isInArray({1}, talkState[cid]) then
		talkState[cid] = 0
		selfSay('Yes', cid)
	elseif msgcontains(msg, 'resets') then
		selfSay('You Have '..getResets(cid)..' reset(s).', cid)
	end
 
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

tho now something else got messed up XD
 
let me edit it to you fast sec

Try that :

LUA:
local price = 100000 -- This would be the default price
local money = 12912  -- Empty storage
local newlevel = 10 -- level after reset
local newexp = 9300 -- Exp after reset
local maxreset = 10


-- end config
 
function addReset(cid)
	return setPlayerStorageValue(cid, 36874, getResets(cid) + 1)
end
 
function getResets(cid)
	return math.max(0, getPlayerStorageValue(cid, 36874))
end
 
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
 
	if msgcontains(msg, 'reset') then
		selfSay(' Do you want to reset for '..price..' GP.', cid)
		talkState[cid] = 1
	elseif(msgcontains(msg, 'yes') and talkState[cid] == 1) then
		local resets = getResets(cid)
		if resets <= 3 then
			resets=-1
		end
		local minlevel = math.max(math.min(500 ) * 2, 4)
		price = math.max(getPlayerStorageValue(cid,money)*2,price)
		if getPlayerMoney(cid) < price then
			selfSay('You must pay '..price..' gold coins to reset.', cid)
		elseif getPlayerLevel(cid) < minlevel then
			selfSay('you need '.. minlevel ..' to reset.', cid)
		else
			doPlayerRemoveMoney(cid,price)
			setPlayerStorageValue(cid,money,price)
			addReset(cid)
			playerid = getPlayerGUID(cid)
			doRemoveCreature(cid)
			db.executeQuery("UPDATE `players` SET `level`="..newlevel..",`experience`="..newexp.." WHERE `players`.`id`= ".. playerid .."")
		end
		talkState[cid] = 0
	elseif msgcontains(msg, 'no') and isInArray({1}, talkState[cid]) then
		talkState[cid] = 0
		selfSay('Yes', cid)
	elseif msgcontains(msg, 'resets') then
		selfSay('You Have '..getResets(cid)..' reset(s).', cid)
	end
 
	return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
my client is 9.10 my distro tfs 0.2.11pl2 in my console show error msg attemp to index global ´db´(a nil value)stack traceback in function callback

db.executeQuery("UPDATE `players` SET `level`="..newlevel..",`experience`="..newexp.." WHERE `players`.`id`= ".. playerid .."")
 
Back
Top