• 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 [talkaction] buy charges

soul4soul

Intermediate OT User
Joined
Aug 13, 2007
Messages
1,875
Solutions
3
Reaction score
129
Location
USA
here is the script
Code:
function onSay(cid, words, param)	
--Start configuration --
	local items = 
	{
	 ['hp'] = {cost = 45, storage = 49989},
	 ['shp'] = {cost = 100, storage = 49988},
	 ['ghp'] = {cost = 190, storage = 49987},
	 ['uhp'] = {cost = 310, storage = 49986},
	 ['mp'] = {cost = 50, storage = 49985},
	 ['smp'] = {cost = 80, storage = 49984},
	 ['gmp'] = {cost = 120, storage = 49983}, 
	 ['gsp'] = {cost = 190, storage = 49982}
	}	
-- End configuration --	

	local t = string.explode(param, ",")
	local item = t[1]
	local amount = tonumber(t[2])	
	
	-- Checks if we can use that itemname --
	if item then
		-- Checks if the player has enough money --
		if doPlayerRemoveMoney(cid, item.cost*amount) == 1 then
			doPlayerSendTextMessage(cid, 24, 'You have bought '..amount..' '..item..' charges for '..(item.cost*amount)..' golden pieces.')
			setPlayerStorageValue(cid, potion.storage, getPlayerStorageValue(cid, potion.storage)+amount)
		else
			doPlayerSendCancel(cid, 'You dont have enough money to buy that many charges.')
			doSendMagicEffect(getPlayerPosition (cid), CONST_ME_POFF)	
		end
	else			
		-- Sends the player a message wich includes items he can buy --
		doPlayerSendTextMessage (cid, 24, 'You can buy the following items:')
		-- Getting the all itemnames --
		for item1 in pairs (items) do	
			-- Sends a message with each itemname and price --
			doPlayerSendTextMessage (cid, 24, item1)
		end
	end
end
Code:
<talkaction words="!charges" event="script" value="charges.lua"/>
when i say "!charges mp,10" my storage value is suppose to increase by 10 b/c i bought more potion charges... instead i get this error.

[13/08/2010 11:07:48] [Error - TalkAction Interface]
[13/08/2010 11:07:48] data/talkactions/scripts/charges.lua:eek:nSay
[13/08/2010 11:07:48] Description:
[13/08/2010 11:07:48] data/talkactions/scripts/charges.lua:23: attempt to perform arithmetic on field 'cost' (a nil value)
[13/08/2010 11:07:48] stack traceback:
[13/08/2010 11:07:48] data/talkactions/scripts/charges.lua:23: in function <data/talkactions/scripts/charges.lua:1>
 
Try this. Rep++ if works.
Code:
function onSay(cid, words, param)	
--Start configuration --
	local items = 
	{
	 ['hp'] = {cost = 45, storage = 49989},
	 ['shp'] = {cost = 100, storage = 49988},
	 ['ghp'] = {cost = 190, storage = 49987},
	 ['uhp'] = {cost = 310, storage = 49986},
	 ['mp'] = {cost = 50, storage = 49985},
	 ['smp'] = {cost = 80, storage = 49984},
	 ['gmp'] = {cost = 120, storage = 49983}, 
	 ['gsp'] = {cost = 190, storage = 49982}
	}	
-- End configuration --	

	local t = string.explode(param, ",")
	local item = items[t[1]]
	local amount = tonumber(t[2])	
	
	-- Checks if we can use that itemname --
	if item then
		-- Checks if the player has enough money --
		if doPlayerRemoveMoney(cid, item.cost*amount) == 1 then
			doPlayerSendTextMessage(cid, 24, 'You have bought '..amount..' '..item..' charges for '..(item.cost*amount)..' golden pieces.')
			setPlayerStorageValue(cid, potion.storage, getPlayerStorageValue(cid, potion.storage)+amount)
		else
			doPlayerSendCancel(cid, 'You dont have enough money to buy that many charges.')
			doSendMagicEffect(getPlayerPosition (cid), CONST_ME_POFF)	
		end
	else			
		-- Sends the player a message wich includes items he can buy --
		doPlayerSendTextMessage (cid, 24, 'You can buy the following items:')
		-- Getting the all itemnames --
		for item1 in pairs (items) do	
			-- Sends a message with each itemname and price --
			doPlayerSendTextMessage (cid, 24, item1)
		end
	end
end
 
ha. damn cant believe it missed that.
local item = items[t[1]]
but it still doesnt work.
i have 10cc on me
ill say !charges mp, 100
it takes 50k
and i poof and it says you dont have enough money to buy that many charges.


@up
what else do u want me to use? and also why bother posting if ur not going to help at all.
 
Last edited:
i tried changing
if doPlayerRemoveMoney(cid, item.cost*amount) == 1 then
to
if doPlayerRemoveMoney(cid, item.cost*amount) == LUA_NO_ERROR then

but it didnt help.... i said !charges mp,100 and i lost 50k but didnt get any type of message and i didnt poof
 
alright i got it to work.

Code:
function onSay(cid, words, param)	
--Start configuration --
	local items = 
	{
	 ['hp'] = {cost = 45, storage = 49989},
	 ['shp'] = {cost = 100, storage = 49988},
	 ['ghp'] = {cost = 190, storage = 49987},
	 ['uhp'] = {cost = 310, storage = 49986},
	 ['mp'] = {cost = 50, storage = 49985},
	 ['smp'] = {cost = 80, storage = 49984},
	 ['gmp'] = {cost = 120, storage = 49983}, 
	 ['gsp'] = {cost = 190, storage = 49982}
	}	
-- End configuration --	

	local t = string.explode(param, ",")
	local item = items[t[1]]
	local amount = tonumber(t[2])	
	
	-- Checks if we can use that itemname --
	if item then
		-- Checks if the player has enough money --
		if doPlayerRemoveMoney(cid, item.cost*amount) == LUA_NO_ERROR then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You have bought '..amount..' '..t[1]..' charges for '..(item.cost*amount)..' golden pieces.')
			setPlayerStorageValue(cid, item.storage, getPlayerStorageValue(cid, item.storage)+amount)
		else
			doPlayerSendCancel(cid, 'You dont have enough money to buy that many charges.')
			doSendMagicEffect(getPlayerPosition (cid), CONST_ME_POFF)	
		end
	else			
		-- Sends the player a message wich includes items he can buy --
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, 'You can buy the following items:')
		-- Getting the all itemnames --
		for item1 in pairs (items) do	
			-- Sends a message with each itemname and price --
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, item1)
		end
	end
	return true
end
there was a few bugs but everything seems to be fine now.
 
Back
Top