• 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 Action script

massuco

Brazilian, sorry for my bad english XD
Joined
Feb 17, 2013
Messages
199
Solutions
8
Reaction score
22
Location
Brasil
Im searching a way to do one script.
I want this:

I will use one rock (id 5000 example) on the map, and this rock will transform on other rock (id 5001), and have a chance of summon one creature or win one item, and after 5minutes, the rock decay to the id 5000 again.

Any ideas on how to start this?
 
Solution
try this. lol
Lua:
local config = {
   create_monster_here = {x = 1000, y = 1000, z = 7}, -- some random place that no players can get to
   teleport_monster_here = {x = 1000, y = 1000, z = 7}, -- location near stone
   stoneResetTimer = 1000
}

local function resetStone(position, current_item, new_item)
   doTransformItem(getTileItemById(position, current_item).uid, new_item)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
   if item.itemid ~= 5194 then
       doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
       doPlayerSendCancel(cid, "Sorry not possible.")
       return true
   end
   doTransformItem(item.uid, 5195)
   addEvent(resetStone, config.stoneResetTimer, toPosition, 5195, 5194)
   
   local summon =...
You start here..
XML:
<action actionid="47777" event="script" value="zz_test_script.lua"/>
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
  
   return true
end
and keep adding stuff that you want it to do.
So let's transform the rock to 5001
Lua:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   doTransformItem(item.uid, 5001)
   return true
end
Now let's get the rock to transform back into 5000 after 1 second.
Because the UID of the item changes when you transform it, you have to re-find the item.
Let's make a small function to do that, since we know the itemID's and position of the object.
Lua:
local function resetStone(position, current_item, new_item)
   doTransformItem(getTileItemById(position, current_item).uid, new_item)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
   doTransformItem(item.uid, 5001)
   addEvent(resetStone, 1000, toPosition, 5001, 5000)
   return true
end
Now, let's add in a small check, to make sure someone doesn't click multiple times and have the rock transform a whole bunch.
Since we know the rock starts at itemID 5000, and will become 5000 again after we 'reset it', we can just check for that,
and send the player some information to let them know we don't want them to keep clicking on the rock.
Lua:
local function resetStone(position, current_item, new_item)
   doTransformItem(getTileItemById(position, current_item).uid, new_item)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
   if item.itemid ~= 5000 then
       doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
       doPlayerSendCancel(cid, "Sorry not possible.")
       return true
   end
   doTransformItem(item.uid, 5001)
   addEvent(resetStone, 1000, toPosition, 5001, 5000)  
   return true
end
Okay, so now we start start adding the actual functionality that we wanted this rock to do
Let's add in the chance to summon a creature, or gain an item.
Lua:
local function resetStone(position, current_item, new_item)
   doTransformItem(getTileItemById(position, current_item).uid, new_item)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
   if item.itemid ~= 5000 then
       doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
       doPlayerSendCancel(cid, "Sorry not possible.")
       return true
   end
   doTransformItem(item.uid, 5001)
   addEvent(resetStone, 1000, toPosition, 5001, 5000)
   local rand = math.random(100)
   if rand <= 50 then
       doCreateMonster("rat", fromPosition)
   else
       doPlayerAddItem(cid, 2148, 1, true)
   end
   return true
end
Now, we know that a creature cannot be summoned in a pz zone, so let's restrict the usage of the item, to outside of pz zones,
and finally change the transform item timer to 5 minutes, because we are done testing and can make the timer the proper time now.
Lua:
local function resetStone(position, current_item, new_item)
   doTransformItem(getTileItemById(position, current_item).uid, new_item)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
   if item.itemid ~= 5000 then
       doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
       doPlayerSendCancel(cid, "Sorry not possible.")
       return true
   end
   if getTilePzInfo(getThingPosition(cid)) == true then
       doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
       doPlayerSendCancel(cid, "Item cannot be used inside of protection zones.")
       return true
   end
   doTransformItem(item.uid, 5001)
   addEvent(resetStone, 1000 * 60 * 5, toPosition, 5001, 5000)
   local rand = math.random(100)
   if rand <= 50 then
       doCreateMonster("rat", fromPosition)
   else
       doPlayerAddItem(cid, 2148, 1, true)
   end
   return true
end

And there we go, a completed script. (untested. xP)
 
WOW, more than a script, one tutorial, I will try it! very thanks

It don't works, sorry, maybe ive forget that say that im using othire 7.7...
It dont show any error, but I use the item and the show me You cannot use this object.
 
Last edited by a moderator:
It don't works, sorry, maybe ive forget that say that im using othire 7.7...
It dont show any error, but I use the item and the show me You cannot use this object.
It should work, if it's not showing an error you did something wrong for sure, maybe wrong ids, or wrong entry in actions.xml.
 
It dont have any error, but I think that is because he said (action actionid = 47777)
and on script dont say nothing about actionid. idk, dont works
 
It dont have any error, but I think that is because he said (action actionid = 47777)
and on script dont say nothing about actionid. idk, dont works
how u added it to actions.xml? It doesn't have to be on the script. You set the stone action id to 47777 in the map?
 
Last edited:
As Peonso stated,
In map editor, set ActionID of stone to 47777 (or whatever you set in actions.xml)
For the script.. if there are still no errors, start putting prints everywhere.

I know for 0.4 (and a few other server versions), ".uid" doesn't work. If your getting an error near those lines try putting ".uniqueid" instead.

XML:
<action actionid="47777" event="script" value="zz_test_script.lua"/>
Lua:
local resetStoneTimer = 4000 -- 1000 * 60 * 5

local function resetStone(position, current_item, new_item)
    print(5)
    doTransformItem(getTileItemById(position, current_item).uid, new_item)
    print(6)
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
 
    print(1)
    if item.itemid ~= 5000 then
        print(7)
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "Sorry not possible.")
        return true
    end
  
    print(2)
    if getTilePzInfo(getThingPosition(cid)) == true then
        print(8)
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "Item cannot be used inside of protection zones.")
        return true
    end
  
    print(3)
    doTransformItem(item.uid, 5001)
    addEvent(resetStone, resetStoneTimer, toPosition, 5001, 5000)
    local rand = math.random(100)
    if rand <= 50 then
        doCreateMonster("rat", fromPosition)
    else
        doPlayerAddItem(cid, 2148, 1, true)
    end
  
    print(4)
    return true
end
 
how u added it to actions.xml? It doesn't have to be on the script. You set the stone action id to 47777 in the map?
Yes, I have set the stone on the map with actionID 47777

And dont works, The stone ids is 3608, that decay to 3609, i have changed it too, and it dont work, dont show any error, with comands print dont show nothing too.. I think that the function onUse is not working.
 
Then your not seeing the error.
It's probably erroring upon start-up of the server.
look carefully while server is loading.
 
Try to register it with:
Lua:
<action actionid="47777" script="scriptname.lua"/>
instead.
 
right 2rec.. now It show me the errors
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/pile_of_bones.lua:onUse

data/actions/scripts/pile_of_bones.lua:20: attempt to call global 'getThingPosition' (a nil value)
stack traceback:
        data/actions/scripts/pile_of_bones.lua:20: in function <data/actions/scripts/pile_of_bones.lua:9>
 
Change getThingPosition(cid) to getCreaturePosition(cid).
Ive just removed this part:
Lua:
    print(2)
    if getTilePzInfo(getThingPosition(cid)) == true then
        print(8)
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "Item cannot be used inside of protection zones.")
        return true
    end

because it dont need to check if is pz. but dont works too.. and dont show any error now

Ahhh , Now it WORKS!!!
For one simple error.. on actions.xml was
Lua:
<action actionid="47777"  value="pile_of_bones.lua"/>
just replaced "value" to "script"

and on script the function doCreateMonster dont exist, ive changed to doSummonCreature
 
Last edited by a moderator:
Didn't script print any numbers? Like '1'?

Did you change that part too, for an item id you wanna use?
Lua:
    if item.itemid ~= 5000 then
        print(7)
        doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "Sorry not possible.")
        return true
    end

Now worked, I have edited the post above.
look, now I want to when the monster is summoned it make one magic effect on the monster.

I have added this:
Lua:
       doSendMagicEffect(getCreaturePosition(cid), CONST_ME_TELEPORT)
But it make a magic effect on the rock, how to make the magic effect appear on the summoned monster?

Other thing, If dont have place to summon the creature, the rock transform.
Example, a player can shot magic walls around the stone, and use the stone, and dont summon the creature, only gain the item
 
Last edited:
Try:
Lua:
local ratso = doSummonCreature("rat", fromPosition)
doSendMagicEffect(getCreaturePosition(ratso), CONST_ME_TELEPORT)

Also, don't forget to mark Xikini's post as Best Answer.
 
Try:
Lua:
local ratso = doSummonCreature("rat", fromPosition)
doSendMagicEffect(getCreaturePosition(ratso), CONST_ME_TELEPORT)

Also, don't forget to mark Xikini's post as Best Answer.

The effect worked, but I have the problem that, If dont have sqm to place the monster you only receive the item and I got this error:
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/pile_of_bones.lua:onUse

attempt to index a boolean value
stack traceback:
        [C]: in function 'doSendMagicEffect'
        data/actions/scripts/pile_of_bones.lua:17: in function <data/actions/scripts/pile_of_bones.lua:5>
 
Try:
Lua:
doSummonCreature("rat", fromPositionn, true, true)
Now the rock summon the monster 1sqm after the rock, but only at certain point, if you shot magic wall arround the rock is the same of the on script exist only the part of addItem.
and get this error:
Code:
Lua Script Error: [Action Interface]
data/actions/scripts/pile_of_bones.lua:onUse

LuaScriptInterface::luaDoSummonCreature(). Can not summon monster: rat

EYb4kuo.png

If I put fire on the ground, or magic walls, the monster will never appear, it only will give a item to the player.
 
Last edited by a moderator:
umm..
a xikini style janky work-around could be to summon the monster somewhere, then teleport the monster into the room. That way the monster is gaurenteed to spawn, and there are less restrictions on teleporting creatures then creating them.
 
Back
Top