• 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 Random item and exp script

sick

Member
Joined
Feb 5, 2009
Messages
258
Reaction score
6
Location
Lithuania, Vilnius
So i got this script which doesn't work for me, i want it to give me 500exp when used and to have some % chance to randomly give 1 of some items, however it can also give no items. Anyone could fix this or make on working. Rep for for helper :) It doesn't give any errors it just doesn't work when used.

PHP:
 local id = {5919, 5912, 6500, 5890} 

function onUse(cid, item, fromPosition, itemEx, toPosition)
        if(fromPosition.x ~= CONTAINER_POSITION) then
           local randomChance = math.random(1, #id)
             if(randomChance(1, 6) == 1) then
                doPlayerAddItem(cid, id[randomChance])
    doPlayerAddExp(cid, 500)
    doCreatureSay(cid, "You Gained 500 Experience Points!", TALKTYPE_ORANGE_1)
    doRemoveItem(item.uid,1)
end
        return true
end 
end


XML:
PHP:
<action itemid="10578" script="other/expscroll.lua"/>
 
So i got this script which doesn't work for me, i want it to give me 500exp when used and to have some % chance to randomly give 1 of some items, however it can also give no items. Anyone could fix this or make on working. Rep for for helper :) It doesn't give any errors it just doesn't work when used.

PHP:
 local id = {5919, 5912, 6500, 5890} 

function onUse(cid, item, fromPosition, itemEx, toPosition)
        if(fromPosition.x ~= CONTAINER_POSITION) then
           local randomChance = math.random(1, #id)
             if(randomChance(1, 6) == 1) then
                doPlayerAddItem(cid, id[randomChance])
    doPlayerAddExp(cid, 500)
    doCreatureSay(cid, "You Gained 500 Experience Points!", TALKTYPE_ORANGE_1)
    doRemoveItem(item.uid,1)
end
        return true
end 
end
XML:
PHP:
<action itemid="10578" script="other/expscroll.lua"/>

I believe when you call this:

PHP:
           local randomChance = math.random(1, #id)
The "to" point, will return the ids in the ID structure.

I dont know if it's like this so

PHP:
local id={
 1 = 3160
 2 = 2160
}
 
Didn't test but should work....
Code:
local chance = 3 -- You have now 1/3 chance to get an item.
local id = {5919, 5912, 6500, 5890}  

function onUse(cid, item, fromPosition, itemEx, toPosition) 
	if(math.random(1, chance) == 1) then
	doPlayerAddItem(cid, id[math.random(1, #id)]) 
	end
    doPlayerAddExp(cid, 500) 
    doCreatureSay(cid, "You Gained 500 Experience Points!", TALKTYPE_ORANGE_1) 
    doRemoveItem(item.uid,1) 
end 
        return true 
end  
end
 
Didn't test but should work....
Code:
local chance = 3 -- You have now 1/3 chance to get an item.
local id = {5919, 5912, 6500, 5890}  

function onUse(cid, item, fromPosition, itemEx, toPosition) 
	if(math.random(1, chance) == 1) then
	doPlayerAddItem(cid, id[math.random(1, #id)]) 
	end
    doPlayerAddExp(cid, 500) 
    doCreatureSay(cid, "You Gained 500 Experience Points!", TALKTYPE_ORANGE_1) 
    doRemoveItem(item.uid,1) 
end 
        return true 
end  
end



Something wrong with the end.
The error i got is : [Error - LuaScriptInterface::loadFile] data/actions/scripts/other/expscroll.lua:13: '<eof>' expected near 'end'
 
I forget to delete ends while editing your script...
Code:
local chance = 3 -- You have now 1/3 chance to get an item.
local id = {5919, 5912, 6500, 5890}  

function onUse(cid, item, fromPosition, itemEx, toPosition) 
	if(math.random(1, chance) == 1) then
	    doPlayerAddItem(cid, id[math.random(1, #id)]) 
	end
    doPlayerAddExp(cid, 500) 
    doCreatureSay(cid, "You Gained 500 Experience Points!", TALKTYPE_ORANGE_1) 
    doRemoveItem(item.uid,1) 
    return TRUE
end
 
Back
Top