• 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 Function OnSay to summon a creature

Apoccalypse

New Member
Joined
Apr 15, 2017
Messages
114
Solutions
2
Reaction score
4
Hello Guys,
I have the following script:

local level = 400


function onUse(cid, item, frompos, item2, topos)
piece1pos = {x=789, y=700, z=6, stackpos=1}
getpiece1 = getThingfromPos(piece1pos)
if item.uid == 8223 and item.itemid == 9825 and getpiece1.itemid == 2159 then
doRemoveItem(getpiece1.uid,1)


TheDavyJonespos = {x=789, y=704, z=6}

doSummonCreature("The Davy Jones", TheDavyJonespos)



doSendMagicEffect(TheDavyJonespos,6)


end
return 1
end

It works fine but I want to rewrite that script a little.
Presently when I place an itemid=2159 at piece1pos the item disapears after I use a lever (id9825) and the boss shows up.
Although instead of using the lever I want to make the item=2159 to disapear and the boss show up as a result of the termination of the specific words by the player.
I know that I have to use function onSay but I can not deal with it.
I have also another problem.
The required amount of the item (2159) to run the script is currently one.Is it a way to increase it up to 100?

piece1pos = {x=789, y=700, z=6, stackpos=1}

I thought that if I change stackpos=1 to stackpos=100 it will solve my problem but unfortunately it doesn't work that way :(

If anyone could help that would be great :)
 
Solution
Lua:
-------------------------------------------
-- for values that don't ever change define them
-- outside of onUse
------------------------------------------
local level = 400
piece1pos = {x = 789, y = 700, z = 6, stackpos = 1}
TheDavyJonespos = {x = 789, y = 704, z = 6}
local amount = 10
--------------------------------------------

-- use indentation so we can see the level of execution
function onUse(cid, item, frompos, item2, topos)
    getpiece1 = getThingfromPos(piece1pos)
    if getpiece1.itemid == 2159 then
        if doRemoveItem(getpiece1.uid, amount) then
            if item.uid == 8223 and item.itemid == 9825 then
                doSummonCreature("The Davy Jones", TheDavyJonespos)...
if you look at the documentation for that function you will found this:
C++:
//doRemoveItem(uid[, count = -1])
so you will need to edit this line
Lua:
doRemoveItem(getpiece1.uid,1)
and editing that "1" because that is the item count
so if you need 10
Lua:
doRemoveItem(getpiece1.uid, 10)
 
hmm ,it works but I can still put like 1 ,2,3 and so items and the boss will be summoned. I need to declared also something like this:
if item.uid == 8223 and item.itemid == 9825 and (getpiece1.itemid == 2159) = 10
, because for this
if item.uid == 8223 and item.itemid == 9825 and getpiece1.itemid == 2159
it is always true for every item >=1
but unfortunately that upper line is not correct.
 
Lua:
-------------------------------------------
-- for values that don't ever change define them
-- outside of onUse
------------------------------------------
local level = 400
piece1pos = {x = 789, y = 700, z = 6, stackpos = 1}
TheDavyJonespos = {x = 789, y = 704, z = 6}
local amount = 10
--------------------------------------------

-- use indentation so we can see the level of execution
function onUse(cid, item, frompos, item2, topos)
    getpiece1 = getThingfromPos(piece1pos)
    if getpiece1.itemid == 2159 then
        if doRemoveItem(getpiece1.uid, amount) then
            if item.uid == 8223 and item.itemid == 9825 then
                doSummonCreature("The Davy Jones", TheDavyJonespos)
                doSendMagicEffect(TheDavyJonespos, 6)
            end
        end
    end
    return 1
end
 
Solution
Thank you very much you helped me a lot !
I have another problem though. I changed the script a little:
local level = 400
piece1pos = {x = 789, y = 700, z = 6, stackpos = 1}
TheDavyJonespos = {x = 789, y = 705, z = 6}
local amount = 100
local itemt = 6561
local items = 3970


--------------------------------------------

-- use indentation so we can see the level of execution
function onUse(cid, item, frompos, item2, topos)
getpiece1 = getThingfromPos(piece1pos)
if item.uid == 8223 and item.itemid == 9825 then
if (getPlayerItemCount(cid, 6561) == 1) then
if getpiece1.itemid == 2159 then
if doRemoveItem(getpiece1.uid, amount) then
doSummonCreature("The Davy Jones", TheDavyJonespos)
doSendMagicEffect(TheDavyJonespos, 6)
doTransformItem(itemt.uid,item.items)
doPlayerSendTextMessage(cid, 21,"The Davy Jones has come from the underworld!")
else
doPlayerSendCancel(cid,"")
doPlayerSendTextMessage(cid, 21,"You haven't got all required things to make a ritual.")
end
end
end
end
return 1
end

I added

else
doPlayerSendCancel(cid,"")
doPlayerSendTextMessage(cid, 21,"You haven't got all required things to make a ritual." , because the script was always true .Presently everything works fine but the problem is that I do not get that message above. I 've tried to do sth like this:

else
doPlayerSendCancel(cid,"You haven't got all required things to make a ritual.")

but still no message appears.
What would be a problem?

I also added the line:
local itemt = 6561
local items = 3970
..................
doTransformItem(itemt.uid,item.items)

but the item id=6561 from the player backpack does not transform into 3870 :(
What could be wrong?
 
Back
Top