Action Piggy Bank and soul orb

Erikas Kontenis

Well-Known Member
Joined
Jul 3, 2009
Messages
1,446
Best answers
0
Reaction score
78
Location
Lithuania
hello its pretty easy scripts but the idea i thinking is pretty good for rpg servers :)

piggybank.lua
Lua:
local coin = {2148}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local count = 1
	if item.itemid == 2114 then
		local randomChance = math.random(1)
		if randomChance == 1 then
			count = math.random(1,100)
		elseif randomChance == 2 then
			count = 3
		end
		doPlayerAddItem(cid, coin[randomChance], count)
	end
	doSendMagicEffect(fromPosition, CONST_ME_GIFT_WRAPS)
	doTransformItem(item.uid, 2115)
	return TRUE
end
soul orb.lua

Lua:
local coin = {2148}

function onUse(cid, item, fromPosition, itemEx, toPosition)
	local count = 1
	if item.itemid == 5944 then
		local randomChance = math.random(1)
		if randomChance == 1 then
			count = math.random(1,100)
		elseif randomChance == 2 then
			count = 3
		end
		doPlayerAddItem(cid, coin[randomChance], count)
	end
	doSendMagicEffect(fromPosition, CONST_ME_GIFT_WRAPS)
	doRemoveItem(item.uid, 1)
	return TRUE
end

i hope us like it and wont forget to rep me :D


Tested on 0.2.5 and 0.3.5
 

Cykotitan

Experienced G'
Joined
Nov 4, 2008
Messages
16,894
Best answers
4
Reaction score
817
Good for RPG servers? Wouldn't say so.
By the looks of the first script, it makes no sense:
Lua:
	local count = 1
"ok", but what's this:
Lua:
		local randomChance = math.random(1)
		if randomChance == 1 then
			count = math.random(1,100)
		elseif randomChance == 2 then
			count = 3
		end
math.random(1) will always result in 1, which will set count to a random number between 1 and 100 afterwards.. "ok"

But what about this:
Lua:
		doPlayerAddItem(cid, coin[randomChance], count)
coin is array, but it only has 1 value .. so what's the point of making it an array?

I think you wanted to make something like this:
Lua:
local coin = 2148

function onUse(cid, item, fromPosition, itemEx, toPosition)
	doPlayerAddItem(cid, coin, math.random(3) == 1 and math.random(100) or 1)
	doSendMagicEffect(toPosition, CONST_ME_GIFT_WRAPS)
	doTransformItem(item.uid, 2115)
	return TRUE
end
soul orb.lua is also pointless and both could share the same script.
 
Last edited:
OP
Erikas Kontenis

Erikas Kontenis

Well-Known Member
Joined
Jul 3, 2009
Messages
1,446
Best answers
0
Reaction score
78
Location
Lithuania
Lua:
  local coin = 2148

function onUse(cid, item, fromPosition, itemEx, toPosition)
        doPlayerAddItem(cid, coin, math.random(3) == 1 and math.random(100) or 1)
        doSendMagicEffect(toPosition, CONST_ME_GIFT_WRAPS)
        doTransformItem(item.uid, 2115)
        return TRUE
end
not works it just allways giving 1 gold coin :p
 

Cykotitan

Experienced G'
Joined
Nov 4, 2008
Messages
16,894
Best answers
4
Reaction score
817
Lua:
  local coin = 2148

function onUse(cid, item, fromPosition, itemEx, toPosition)
        doPlayerAddItem(cid, coin, math.random(3) == 1 and math.random(100) or 1)
        doSendMagicEffect(toPosition, CONST_ME_GIFT_WRAPS)
        doTransformItem(item.uid, 2115)
        return TRUE
end
not works it just allways giving 1 gold coin :p
You gotta be really unlucky.



Anyway, here's a script closer to the real one:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
	local random = math.random(4)
	doSendMagicEffect(toPosition, random == 1 and CONST_ME_BLOCKHIT or CONST_ME_SOUND_YELLOW)
	doPlayerAddItem(cid, random == 1 and ITEM_GOLD_COIN or ITEM_PLATINUM_COIN, 1)
	return TRUE, (random == 1 and doTransformItem(item.uid, 2115))
end
 
Top