PDA

View Full Version : Need one easy script.



germanzel
02-05-2016, 07:05 AM
Hello brothers, i need one scripts:

1 - Use item (ID - 11328) in my BP.

Jontor
02-05-2016, 02:53 PM
for i = 0, 16 do
if (i:isOpen()) then
for spot = 0, i:ItemCount() - 1 do
if (i:GetItemData(spot).id == 11328) then
return i, spot
end
end
end
end

---- use \/ with the above function
function Container:UseItem(spot)

Elfisyn
02-07-2016, 11:02 AM
for i = 0, 16 do
if (i:isOpen()) then
for spot = 0, i:ItemCount() - 1 do
if (i:GetItemData(spot).id == 11328) then
return i, spot
end
end
end
end

---- use \/ with the above function
function Container:UseItem(spot)


Can I ask to remake this script: use item in my bp when my mana (or mana percent) is below some number.

Jontor
02-07-2016, 11:32 AM
Can I ask to remake this script: use item in my bp when my mana (or mana percent) is below some number.



local manaPercent = 20
local itemToUse = "brown mushroom"

local function findItem()
for i = 0, 16 do
if (i:isOpen()) then
for spot = 0, i:ItemCount() - 1 do
if (i:GetItemData(spot).id == Item.GetID(itemToUse) then
return i, spot
end
end
end
end
return nil
end

while (true) do
if ((Self.Mana() / Self.MaxMana()) * 100 <= manaPercent) then
local cont, spot = findItem()
if (not cont) then
return
end
cont:UseItem(spot)
end
end

Elfisyn
02-07-2016, 11:36 AM
Thank you very much for you answer!
this will work only if i have opened bp with this item?

edit: is not working :(
I have been using it but it crashing after about 1 hour and turn off. I dont know why. This is what I use:

local function healer()
local Mana = 4400
local ItemToUse = 11632
if Self.Mana() < Mana then
Self.UseItem(ItemToUse)
end
sleep(math.random(140,420))
healer()
end

healer()



This is error message:

13:57 XenoScript Error:
Script: monk manarune.lua
Line #: 4
Chunk: ...??MONKMA?1.LUA
Error: stack overflow
This is an error with user-input and should not be reported as a bug with XenoBot.

Jontor
02-07-2016, 02:19 PM
Thank you very much for you answer!
this will work only if i have opened bp with this item?

edit: is not working :(
I have been using it but it crashing after about 1 hour and turn off. I dont know why. This is what I use:

local function healer()
local Mana = 4400
local ItemToUse = 11632
if Self.Mana() < Mana then
Self.UseItem(ItemToUse)
end
sleep(math.random(140,420))
healer()
end

healer()



This is error message:

13:57 XenoScript Error:
Script: monk manarune.lua
Line #: 4
Chunk: ...??MONKMA?1.LUA
Error: stack overflow
This is an error with user-input and should not be reported as a bug with XenoBot.

Wow, there is "Self.UseItem(id)" :facepalm:

Anyways, you don't want to make an infinite loop inside functions ( not enough time for garbage collector I think )
Remove 'healer()' inside your healer function and add a loop like this


while (true) do
healer()
end


Or if you want to use it with another code, make something like this


Module.New("useItem", function()
healer()
end)

^ Waiting inside the function in this case is not needed