• 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] Script Problem

Status
Not open for further replies.

Lava Titan

Developer
Joined
Jul 25, 2009
Messages
1,571
Solutions
3
Reaction score
98
Location
Portugal
Sup guys.
I'm using this script:

LUA:
local cost = 1000000
local newItem = {7388, 1}

function onUse(cid, item, fromPosition, itemEx, toPosition)
        if doPlayerRemoveMoney(cid, cost) == FALSE then
                doPlayerSendTextMessage(cid, 26, "You need "..cost.." gold coins for "..newItem[2].."x "..getItemNameById(newItem[1])..".")
                doSendMagicEffect(getCreaturePosition(cid), 2)
                return TRUE
        end
       
        if item.itemid == 1945 then
                doTransformItem(item.uid, 1946)
        else
                doTransformItem(item.uid, 1945)
        end

        doPlayerAddItem(cid, newItem[1], newItem[2])
        doPlayerSendTextMessage(cid, 22, "You bought "..newItem[2].."x "..getItemNameById(newItem[1]).." for "..cost..".")
        return TRUE
end

for shop levers but the problem is even if the player doesnt have money to buy the item he will get the item anyway ...

Example: You dont got money and you still get the item without paying.

Can some1 help me fixing it?

Thanks for every1 that helps
Rep++ for every1 that helps to.

Regards
Lava Titan
 
LUA:
local cost = 1000000
local newItem = {7388, 1}

function onUse(cid, item, fromPosition, itemEx, toPosition)
        if doPlayerRemoveMoney(cid, cost) == FALSE then
                doPlayerSendTextMessage(cid, 26, "You need "..cost.." gold coins for "..newItem[2].."x "..getItemNameById(newItem[1])..".")
                doSendMagicEffect(getCreaturePosition(cid), 2)
	else        
		doPlayerAddItem(cid, newItem[1], newItem[2])
		doPlayerSendTextMessage(cid, 22, "You bought "..newItem[2].."x "..getItemNameById(newItem[1]).." for "..cost..".")
        end
       
        if item.itemid == 1945 then
                doTransformItem(item.uid, 1946)
        else
                doTransformItem(item.uid, 1945)
        end
        return TRUE
end
Should work, but its not tested
Honestly I would do sth like that kind of
Code:
if doPlayerRemoveMoney(cid, cost) == TRUE
add item
else
show error communicate
but this one should work too
 
I tested another scripts to, like "Buy bp of pot and when i buy the bp there are noting inside...

LUA:
function onUse(cid, item, frompos, item2, topos)

container = doPlayerAddItem(cid, 5926, 1)

if item.itemid == 1945 and doPlayerRemoveMoney(cid,4000) == 1 then
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doTransformItem(item.uid,item.itemid+1)

elseif item.itemid == 1946 and doPlayerRemoveMoney(cid,4000) == 1 then
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doAddContainerItem(container, 8473, 7)
doTransformItem(item.uid,item.itemid-1)

else
doPlayerSendCancel(cid,"Sorry, you don't have enough money!")
end
return 1
end
 
Code:
local config = {
	price = 4000,
	backpack = 5926,
	itemid = 8473,
	subtype = 1
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(getPlayerMoney(cid) >= config.price) then
		local container = doCreateItemEx(config.backpack, 1)
		for i = 1, getContainerCapById(config.backpack) do
			doAddContainerItem(container, config.itemid, config.subtype)
		end
		if(doPlayerAddItemEx(cid, container, false) ~= RETURNVALUE_NOERROR) then
			doPlayerSendCancel(cid, getPlayerFreeCap(cid) < getItemWeight(container) and "You don't have enough capacity." or "You don't have enough room to take it.")
		else
			doPlayerRemoveMoney(cid, config.price)
			doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
		end
	else
		doPlayerSendCancel(cid, "You don't have enough money.")
	end
	return TRUE
end
 
Last edited:
works perfectly rep++ but can you help me fixing this one to?
LUA:
  local cost = 1000000
local newItem = {7388, 1}

function onUse(cid, item, fromPosition, itemEx, toPosition)
        if doPlayerRemoveMoney(cid, cost) == FALSE then
                doPlayerSendTextMessage(cid, 26, "You need "..cost.." gold coins for "..newItem[2].."x "..getItemNameById(newItem[1])..".")
                doSendMagicEffect(getCreaturePosition(cid), 2)
                return TRUE
        end
       
        if item.itemid == 1945 then
                doTransformItem(item.uid, 1946)
        else
                doTransformItem(item.uid, 1945)
        end

        doPlayerAddItem(cid, newItem[1], newItem[2])
        doPlayerSendTextMessage(cid, 22, "You bought "..newItem[2].."x "..getItemNameById(newItem[1]).." for "..cost..".")
        return TRUE
end

On this one i get the item without paying.
But only 1 item without backpacks
 
Code:
local config = {
	cost = 1000000,
	newItem = {7388, 1}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(not(doPlayerRemoveMoney(cid, config.cost))) then
		doPlayerSendTextMessage(cid, 26, "You need "..config.cost.." gold coins for "..config.newItem[2].."x "..getItemNameById(config.newItem[1])..".")
		doSendMagicEffect(getCreaturePosition(cid), 2)
		return true
	end
	doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
	doPlayerAddItem(cid, config.newItem[1], config.newItem[2])
	doPlayerSendTextMessage(cid, 22, "You bought "..config.newItem[2].."x "..getItemNameById(config.newItem[1]).." for "..config.cost.." gold coins.")
	return true
end
 
@up not tested but should work ;)

LUA:
function onUse(cid, item, fromPosition, itemEx, toPosition)
        if item.uid == xxxx then -- unique id of switch
                doPlayerSendTextMessage(cid, 26, "You need 1000000 gold coins for Vile axe.")
				doPlayerAddItem(cid,7388,1)
                doSendMagicEffect(getCreaturePosition(cid), 2)
				doPlayerRemoveMoney(cid,1000000)
                return TRUE
        end
       
        if item.itemid == 1945 then
                doTransformItem(item.uid, 1946)
        else
                doTransformItem(item.uid, 1945)
        end

        doPlayerAddItem(cid, newItem[1], newItem[2])
        doPlayerSendTextMessage(cid, 22, "You bought Vile axe for 1000000 gold coins.")
        return TRUE
end
 
Code:
local config = {
	cost = 1000000,
	newItem = {7388, 1}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(not(doPlayerRemoveMoney(cid, config.cost))) then
		doPlayerSendTextMessage(cid, 26, "You need "..config.cost.." gold coins for "..config.newItem[2].."x "..getItemNameById(config.newItem[1])..".")
		doSendMagicEffect(getCreaturePosition(cid), 2)
		return true
	end
	doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
	doPlayerAddItem(cid, config.newItem[1], config.newItem[2])
	doPlayerSendTextMessage(cid, 22, "You bought "..config.newItem[2].."x "..getItemNameById(config.newItem[1]).." for "..config.cost.." gold coins.")
	return true
end

works fine!
but last requirement =p
buying this item not for money but for another item
i made a new type of coins but that can only be used for special armors
id of coin 9970
 
please test it and say me where problems :D or mayby no problems :D

Code:
local config = {
	oldItem = {9970, 2}
	newItem = {7388, 1}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
	if(not(doPlayerRemoveItem(cid, config.oldItem))) then
		doPlayerSendTextMessage(cid, 26, "You need "..config.oldItem.." for "..config.newItem[2].."x "..getItemNameById(config.newItem[1])..".")
		doSendMagicEffect(getCreaturePosition(cid), 2)
		return true
	end
	doTransformItem(item.uid, item.itemid == 1945 and 1946 or 1945)
	doPlayerAddItem(cid, config.newItem[1], config.newItem[2])
	doPlayerSendTextMessage(cid, 22, "You bought "..config.newItem[2].."x "..getItemNameById(config.newItem[1]).." for "..config.oldItem..".")
	return true
end
 
Status
Not open for further replies.
Back
Top