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

onUse - questions

Inteligentny

Im not.
Joined
Aug 2, 2008
Messages
485
Reaction score
0
Hello, I was trying to change Gesior's Santa Claus npc on Christmas Tree but its not working xD If someone could help me I will be grateful :d


PHP:
random_items = {
{100,2399,100}, -- 30% to get thro stars
{100,2410,1}, -- 30% to get thro knifes
{100,2488,1}, -- 1.5% to get c legs
{100,2519,1}, -- 1.5% to get c armor
{100,2306,1}, -- 100% to get 8 cookies
{50,2674,15}, -- 40% to get 15 red apples 
{50,2675,10}, -- 45% to get 10 oranges 
{15,2487,1}, -- 1.5% to get c armor
{20,2112,1}, --  0.5% to get teddy bear 
{300,6512,1}, -- 2% to get santa doll 
{600,2114,1}, -- 4% to get piggy bank 
{800,2111,10}, -- 8% to get 5 snowballs 
{600,2688,8}, -- 8% to get 8 candy canes 
{800,2110,1}, -- 8% to get doll 
{1000,2687,8} -- 100% to get 8 cookies 
} 
PRESENT_STORAGE = 54148 -- storage ID 


function onUse(cid, parameters, item, frompos, item2, topos) 
       if (parameters.present == true) then 
        if (getPlayerStorageValue(cid, PRESENT_STORAGE) < 1) then 
            local item = {} 
            local reward = 0 
            local count = "" 
            for i = 1, #random_items do 
                item = random_items[i] 
                if (math.random(0,999) < item[1]) then 
                    reward = item[2] 
                    subType = item[3] 
                    if subType > 1 then 
                        count = subType .. " " 
                    end 
                    break 
                end 
            end 
            doPlayerAddItem(cid, reward, subType) 
            setPlayerStorageValue(cid, PRESENT_STORAGE, 1) 
               doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "Marry Chrismtas, here is your present... ")
        else 
            doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have found already present.")
        end 
    end 
    
end

Is it even possible to mix npc's scripts with those onUse?
 
Of course its possible, as its always LUA :rolleyes:

My christmas tree - added more items, like boh, g arm, g boots (0.1% chance), fixed bug with percents (IN gesior NPC CHANCE for each present is bugged), added min level.

Code:
local random_items = {
	{1,2646,1}, --  0.1% to get golden boots
	{5,2112,1}, --  0.5% to get teddy bear
	{20,6512,1}, -- 2% to get santa doll
	{25,6132,1}, -- 2.5% to get soft boots
	{30,6578,1}, -- 3% to get party hat
	{40,8891,1}, -- 4% to get paladin armor
	{60,2195,1}, -- 6% to get boots of haste
	{70,2534,1}, -- 7% to get vampire shield
	{85,7957,1}, -- 8% to get jester hat
	{88,2110,1}, -- 8% to get doll
	{90,7902,1}, -- 9% to get glacier mask
	{95,2520,1}, -- 9.5% to get demon shield
	{120,2466,1}, -- 12% to get golden armor
	{140,8883,1}, -- 14% to get ----
	{170,8878,1}, -- 17% to get ----
	{200,2160,2}, -- 20% to get 2 crystal coins
	{250,2273,100}, -- 25% to get 100x UH
	{300,2476,1}, -- 30% to get knight legs
	{330,2268,50}, -- 33% to get 50x SD
	{400,2674,15}, -- 40% to get 15 red apples
	{430,2114,1}, -- 43% to get piggy bank
	{440,2498,10}, -- 45% to get royal helmet
	{450,2675,10}, -- 45% to get 10 oranges
	{600,6531,1}, -- 60% to get santa hat
	{700,2111,5}, -- 70% to get 5 snowballs
	{800,2688,8}, -- 80% to get 8 candy canes
	{1000,2687,8} -- 100% to get 8 cookies
}

local PRESENT_STORAGE = 54165 -- storage ID
local MIN_LEVEL = 75

function onUse(cid, item, fromPosition, itemEx, toPosition)
	if getPlayerStorageValue(cid, PRESENT_STORAGE) < 1 then
		if getPlayerLevel(cid) >= MIN_LEVEL then
			local item = {}
			local reward = 0
			local count = ""

			local chance = math.random(0,999)
			for i = 1, #random_items do
				item = random_items[i]
				if (chance < item[1]) then
					reward = item[2]
					subType = item[3]
					if subType > 1 then
						count = subType .. " "
					end
					break
				end
			end

			doPlayerAddItem(cid, reward, subType)
			setPlayerStorageValue(cid, PRESENT_STORAGE, 1)
			doCreatureSay(cid, "Merry Christmas " .. getCreatureName(cid) .. "! I hope you were good like a little dwarf this year!", TALKTYPE_ORANGE_1)
		else
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need " .. MIN_LEVEL .. " level to take presents.")
		end
	else
		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "I gave you a present already.")
	end

	return TRUE
end
 
Back
Top