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

I need to fix this script!

Status
Not open for further replies.

5mok3

Emporia
Joined
Jan 18, 2009
Messages
1,767
Reaction score
25
Location
California, US
I'm not a pro coder so.. I've been struggling for a while trying to fix this piece of code <_<

What it does.. or it's supposed to do
When you say !buy name the script runs.. and you buy one of the offers available on the list

The script is not a 100% and it's not working.. its just a piece of code i never finished :(

LUA:
-- Emporia.vapus.net --
----------------------------
-- 	Author: 5moke	-- 
-- 	Emporia VAPus 	--
----------------------------

local shop =
{
-- ["Offer name"] = {id = ITEM_ID, cost = POINTS_COST, charges = ITEM_COUNT, effect = DISPLAY_EFFECT} --

        ["crystal coins"] = {id = 2160, cost = 5, charges = 50, effect = CONST_ME_GIFT_WRAPS}

}

function onSay(cid, words, param, channel)
	local v = shop[item.name]
	local weight = getItemWeightById(v.id, tonumber(getItemInfo(v.container).maxItems)) + getItemWeightById(v.container, 1)
	if(getPlayerFreeCap(cid) >= weight) then
		if(getAccountPoints(cid) >= v.cost) then
			if(doPlayerAddItemEx(cid, v.id, v.charges) ~= RETURNVALUE_NOERROR) then
				doPlayerSendCancel(cid, "Sorry, you do not have enough space.")
			else
					doPlayerAddItem(cid, v.id, v.charges)
				end
				doRemovePoints(cid, v.cost)
				doSendMagicEffect(getThingPos(cid), v.effect)
				doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You have purchased: " .. getItemInfo(v.id).plural .. ".")
			end
		else
			doPlayerSendCancel(cid, "Sorry, you must have " .. v.cost .. " points.")
		end
	else
		doPlayerSendCancel(cid, "Sorry, you need " .. weight:format("%.2f") .. " oz. to carry this item: " .. getItemInfo(v.id).plural .. ".")
	end
	return TRUE
end
-- Emporia.vapus.net --

Hopefully someone will help me finish it! :wub:

I'll rep your asses off if you do jaja
 
Code:
local offers = {
	["Test Item"] = {itemid=2160,cost=5,count=50,effect=CONST_ME_GIFT_WRAPS}
	}

function onSay(cid,words,param)
local r,w,v = offers[param],getItemWeightById(r.itemid,r.count),getThingPos(cid)
	if r then
		if getPlayerFreeCap(cid) >= w then
			if doRemovePoints(cid,r.cost) then
				doPlayerAddItem(cid,r.itemid,r.count)
				doSendMagicEffect(v,r.effect)
				doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_ORANGE,"You have purchased: "..getItemInfo(v.id).plural..".")
			else
				doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_ORANGE,"You don't have enough points!\nYou need "..r.cost.." points.")
				doSendMagicEffect(v,2)
			end
		else
			doPlayerSendCancel(cid,'Not enough cap.')
			doSendMagicEffect(v,2)
		end
	end
	return true
end

try
 
Assuming you have thses functions [remove points and getaccout points]
LUA:
local shop =
{
["golden armor"] = {id = 2466, cost = 14, charges = 1, effect = CONST_ME_GIFT_WRAPS} --
}
function onSay(cid, words, param, channel)
        for k, v in pairs(shop) do 
                     if param ~= k then
		       return true
                     end
						local itemm = getItemWeightById(v.id, v.charges)
                        if getPlayerFreeCap(cid) < itemm then
                          doPlayerSendCancel(cid, "Sorry, you do not have enough cap.You need "..itemm.." oz to carry : "..param..".")
                        end
                        if (getAccountPoints(cid) < v.cost) then
                           doPlayerSendCancel(cid, "Sorry, you need : "..v.cost.." poits to buy this item.")
                        end
                           doPlayerAddItem(cid,v.id,v.charges)
                           doRemovePoints(cid,v.cost)
                           doSendMagicEffect(getThingPos(cid), v.effect)
		end
  return true                                              
end
 
Last edited:
Okay i updated your code a bit.. it was missing the check if player has points thing..

LUA:
local offers = {
	["crystal coins"] = {itemid=2160, cost=5, count=50, effect=CONST_ME_GIFT_WRAPS}
	}

function onSay(cid,words,param)
local r,w,v = offers[param],getItemWeightById(r.itemid,r.count),getThingPos(cid)
	if r then
		if getPlayerFreeCap(cid) >= w then
			if(getAccountPoints(cid) >= r.cost) then
				doRemovePoints(cid,r.cost)
				doPlayerAddItem(cid,r.itemid,r.count)
				doSendMagicEffect(v,r.effect)
				doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_ORANGE,"You have purchased: "..getItemInfo(v.id).plural..".")
			else
				doPlayerSendTextMessage(cid,MESSAGE_STATUS_CONSOLE_ORANGE,"You don't have enough points!\nYou need "..r.cost.." points.")
				doSendMagicEffect(v,2)
			end
		else
			doPlayerSendCancel(cid,'Not enough cap.')
			doSendMagicEffect(v,2)
		end
	end
	return true
end

And this is the error i get :S
Code:
[19:45:57.385] [Error - TalkAction Interface]
[19:45:57.385] data/talkactions/scripts/custom/shop.lua:onSay
[19:45:57.385] Description:
[19:45:57.385] data/talkactions/scripts/custom/shop.lua:6: attempt to index global 'r' (a nil value)
[19:45:57.385] stack traceback:
[19:45:57.385]  data/talkactions/scripts/custom/shop.lua:6: in function <data/talkactions/scripts/custom/shop.lua:5>
 
LUA:
local shop =
{
["golden armor"] = {id = 2466, cost = 14, charges = 1, effect = CONST_ME_GIFT_WRAPS},
["pharo sword"] = {id = 2446, cost = 14, charges = 1, effect = CONST_ME_GIFT_WRAPS} 
}
function onSay(cid, words, param, channel)
local v = shop[param]
local itemm = getItemWeightById(v.id, v.charges)
		        if not v then
		            doPlayerSendCancel(cid,"Item not found.")
		           return true
		        end
		
                        if getPlayerFreeCap(cid) < itemm then
                            doPlayerSendCancel(cid, "Sorry, you do not have enough cap.You need "..itemm.." oz to carry : "..param..".")
                        end
                        if (getAccountPoints(cid) < v.cost) then
                            doPlayerSendCancel(cid, "Sorry, you need : "..v.cost.." poits to buy this item.")
                        end
                           doPlayerAddItem(cid,v.id,v.charges)
                           doRemovePoints(cid,v.cost)
			   doSendMagicEffect(getThingPos(cid), v.effect)
  return true                                              
end
 
Last edited:
It works.. bugged but it does jaja!

the if (getAccountPoints(cid) < v.cost) doesn't work
It still removes the points (-14) and adds the items

EDIT
I made it work :D

But i wasn't able to make this part work at all
Code:
local v = shop[param]
if (not v) then
	doPlayerSendCancel(cid,"Item not found.")
	doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
return false
end

Thanks for everything guys!
 
Last edited:
i donno why , this should have worked :/
LUA:
local v = shop[param]
if (not v) then
	doPlayerSendCancel(cid,"Item not found.")
	doSendMagicEffect(getPlayerPosition(cid), CONST_ME_POFF)
return false
end

Have you changed anything in script ?
 
@UP

Nop.. just modified few things.. everything else works perfectly with my modifications but for example my command is !buy

If i say something is not on the list ex. !buy nothing it should send "Item not found." instead it tells me variable v is wrong

get me?

i even edited the lines you had with these ones
LUA:
if (not v) then
return false

But no success
 
Ah, maybe try it like that, this happen as we put the local to check item weight before checking if it is an item, so if you write somthng other than a item name it will give that error :)
LUA:
local shop =
{
["golden armor"] = {id = 2466, cost = 14, charges = 1, effect = CONST_ME_GIFT_WRAPS},
["pharo sword"] = {id = 2446, cost = 14, charges = 1, effect = CONST_ME_GIFT_WRAPS} 
}
function onSay(cid, words, param, channel)
local v = shop[param]

                        if not v then
                            doPlayerSendCancel(cid,"Item not found.")
                           return true
                        end
                  local itemm = getItemWeightById(v.id, v.charges)
                        if getPlayerFreeCap(cid) < itemm then
                            doPlayerSendCancel(cid, "Sorry, you do not have enough cap.You need "..itemm.." oz to carry : "..param..".")
                        end
                        if (getAccountPoints(cid) < v.cost) then
                            doPlayerSendCancel(cid, "Sorry, you need : "..v.cost.." poits to buy this item.")
                        end
                           doPlayerAddItem(cid,v.id,v.charges)
                           doRemovePoints(cid,v.cost)
                           doSendMagicEffect(getThingPos(cid), v.effect)
  return true                                              
end
 
Status
Not open for further replies.
Back
Top