• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Add one function to moveEvent script

BugaS

Donżuan
Joined
Mar 12, 2009
Messages
1,219
Reaction score
9
Location
NYC
Hi guys!

I've got this script:

LUA:
-- idea by frankfarmer/fragdonut and script by cykotitan
-- step on tile and summon monster
local t = {
    storage = 32000, --storageid
    interval = 60, --how many seconds until next
    monster = {"Demon", {x=100, y=100, z=7}}, -- monster and coords
    msg = "It's too quiet here..." -- message players get
}
function onStepIn(cid, item, position, fromPosition)
    if os.difftime(os.time(), getGlobalStorageValue(t.storage)) >= t.interval then     
        doCreatureSay(cid, t.msg, TALKTYPE_ORANGE_1)
        doSummonCreature(t.monster[1], t.monster[2])
        setGlobalStorageValue(t.storage, os.time())
    end
end

Can you add there a function which change player HP to 15%? Also, is doSummonCreature works with NPC too?
 
Solution
X
It's better but not works too. First of all, the monster is spawning, the text is appearing but, the NPC is created for a half of seconds and disapear. BTW. I don't know how with HP, cause I'm testing it on GOD player and it doesn't get 15%
Installed, tested, added a few magic effects.
Fully working on my 0.3.7
LUA:
local config = {
   global_storage = 11111, -- any free storage
   tile_reset_interval = 60, -- seconds
   reduce_player_health_to = 0.15, -- percentage | 0.15 = 15%
   npc = {"Npc_name_here", {x = 100, y = 100, z = 7}, 30}, -- name, position, removal time in seconds
   monster = {"Demon", {x = 100, y = 100, z = 7}}, -- name, position
   player_text = "It's too quiet here..."
}

local function remove_npc(cid)
   if...
doPlayerAddHealth(cid, -getCreatureHealth(cid) * 0.15)

doSummonCreature doesn't work but doCreateNpc(name, pos[, displayError = true]) does
 
doPlayerAddHealth(cid, -getCreatureHealth(cid) * 0.15)

doSummonCreature doesn't work but doCreateNpc(name, pos[, displayError = true]) does
Thanks for your help! Is it possible, to make, that NPC will disapear after few seconds from create?
 
Thanks for your help! Is it possible, to make, that NPC will disapear after few seconds from create?
yes, something like this:
LUA:
local function remove(cid)
    if isNpc(cid) then
        doRemoveCreature(cid)
    end
end

-- under stepin function
local npc = doCreateNpc(name, pos)
addEvent(remove, 15 * 1000, npc)
 
yes, something like this:
LUA:
local function remove(cid)
    if isNpc(cid) then
        doRemoveCreature(cid)
    end
end

-- under stepin function
local npc = doCreateNpc(name, pos)
addEvent(remove, 15 * 1000, npc)
In the function remove i must type the name of the NPC somewhere?
 
no, the only thing you need to change is the name and position in doCreateNpc
just make sure you have function remove above your onStepIn function
I've got:

Code:
local t = {
    storage = 32111, --storageid
    interval = 30, --how many seconds until next
    monster = {"[SAGA] Tambourine", {x=1048, y=93, z=7}}, -- monster and coords
    msg = "Wha...what...?! [Tell him 'HI']" -- message players get
}

local function remove(cid)
    if isNpc(cid) then
        doRemoveCreature(cid)
    end
end

function onStepIn(cid, item, position, fromPosition)
    if os.difftime(os.time(), getGlobalStorageValue(t.storage)) >= t.interval then  
        doCreatureSay(cid, t.msg, TALKTYPE_ORANGE_1)
        setGlobalStorageValue(t.storage, os.time())
local npc = doCreateNpc(t.monster[1], t.monster[2])
addEvent(remove, 30 * 1000, npc)
    end
end

and it doesn't works. Nothing works

#EDIT

And in moveents.xml i've got:


<movevent type="StepIn" actionid="11112" event="script" value="tamburyn.lua"/>

And ofc actionid made in map
 
I've got:

Code:
local t = {
    storage = 32111, --storageid
    interval = 30, --how many seconds until next
    monster = {"[SAGA] Tambourine", {x=1048, y=93, z=7}}, -- monster and coords
    msg = "Wha...what...?! [Tell him 'HI']" -- message players get
}

local function remove(cid)
    if isNpc(cid) then
        doRemoveCreature(cid)
    end
end

function onStepIn(cid, item, position, fromPosition)
    if os.difftime(os.time(), getGlobalStorageValue(t.storage)) >= t.interval then 
        doCreatureSay(cid, t.msg, TALKTYPE_ORANGE_1)
        setGlobalStorageValue(t.storage, os.time())
local npc = doCreateNpc(t.monster[1], t.monster[2])
addEvent(remove, 30 * 1000, npc)
    end
end

and it doesn't works. Nothing works

#EDIT

And in moveents.xml i've got:


<movevent type="StepIn" actionid="11112" event="script" value="tamburyn.lua"/>

And ofc actionid made in map
what doesnt work about it?
are there no errors that you got?
 
try this
LUA:
local t = {
    storage = 32111, --storageid
    interval = 30, --how many seconds until next
    monster = {"[SAGA] Tambourine", {x=1048, y=93, z=7}}, -- monster and coords
    msg = "Wha...what...?! [Tell him 'HI']" -- message players get
}

local function remove(cid)
    if isNpc(cid) then
        doRemoveCreature(cid)
    end
end

time = 0

function onStepIn(cid, item, position, fromPosition)
    if os.time() >= time then 
        local npc = doCreateNpc(t.monster[1], t.monster[2])
        addEvent(remove, 30 * 1000, npc)
        doCreatureSay(cid, t.msg, TALKTYPE_ORANGE_1)
        time = os.time() + t.interval
    end
end
 
Last edited:
try this
LUA:
local t = {
    storage = 32111, --storageid
    interval = 30, --how many seconds until next
    monster = {"[SAGA] Tambourine", {x=1048, y=93, z=7}}, -- monster and coords
    msg = "Wha...what...?! [Tell him 'HI']" -- message players get
}

local function remove(cid)
    if isNpc(cid) then
        doRemoveCreature(cid)
    end
end

time = 0

function onStepIn(cid, item, position, fromPosition)
    if os.time() >= time then 
        local npc = doCreateNpc(t.monster[1], t.monster[2])
        addEvent(remove, 30 * 1000, npc)
        doCreatureSay(cid, t.msg, TALKTYPE_ORANGE_1)
        time = os.time() + interval
    end
end

[0:46:56.558] [Error - MoveEvents Interface]
[0:46:56.566] data/movements/scripts/tamburyn.lua:onStepIn
[0:46:56.568] Description:
[0:46:56.571] data/movements/scripts/tamburyn.lua:21: attempt to perform arithmetic on global 'interval' (a nil value)
[0:46:56.573] stack traceback:
[0:46:56.582] data/movements/scripts/tamburyn.lua:21: in function <data/movements/scripts/tamburyn.lua:16>
 
doPlayerAddHealth(cid, -getCreatureHealth(cid) * 0.15)

doSummonCreature doesn't work but doCreateNpc(name, pos[, displayError = true]) does

First doCreatureAddHealth you must have meant? And also getCreatureMaxHealth I would suppose.

try this
LUA:
local t = {
    storage = 32111, --storageid
    interval = 30, --how many seconds until next
    monster = {"[SAGA] Tambourine", {x=1048, y=93, z=7}}, -- monster and coords
    msg = "Wha...what...?! [Tell him 'HI']" -- message players get
}

local function remove(cid)
    if isNpc(cid) then
        doRemoveCreature(cid)
    end
end

time = 0

function onStepIn(cid, item, position, fromPosition)
    if os.time() >= time then
        local npc = doCreateNpc(t.monster[1], t.monster[2])
        addEvent(remove, 30 * 1000, npc)
        doCreatureSay(cid, t.msg, TALKTYPE_ORANGE_1)
        time = os.time() + t.interval
    end
end

Weren't you meant to add above code in there, as originally requested?
 
Last edited:
You guys are butchering this script :(

-- Edit

Wasn't home earlier.
Here's a working script.

Tile can only be activated by a player, every x seconds.
Spawns 1 creature and 1 npc.
Npc removed after y seconds.
Reduces players hp to zz%. If players life is below this percent, does nothing.
LUA:
local config = {
   global_storage = 11111, -- any free storage
   tile_reset_interval = 60, -- seconds
   reduce_player_health_to = 0.15, -- percentage | 0.15 = 15%
   npc = {"Npc_name_here", {x = 100, y = 100, z = 7}, 30}, -- name, position, removal time in seconds
   monster = {"Demon", {x = 100, y = 100, z = 7}}, -- name, position
   player_text = "It's too quiet here..."
}

local function remove_npc(cid)
   if isNpc(cid) then
       doRemoveCreature(cid)
   end
end

function onStepIn(cid, item, position, fromPosition)
   local cur_time = os.time()
   if isPlayer(cid) and cur_time > getGlobalStorageValue(config.global_storage) + config.tile_reset_interval then
       if getCreatureHealth(cid) > getCreatureMaxHealth(cid) * config.reduce_player_health_to then
           doCreatureAddHealth(cid, -(getCreatureHealth(cid) - getCreatureMaxHealth(cid) * config.reduce_player_health_to))
       end
       local npc = doCreateNpc(config.npc[1], config.npc[2])
       addEvent(remove_npc, config.npc[3], npc)
       doSummonCreature(config.monster[1], config.monster[2])
       doCreatureSay(cid, config.player_text, TALKTYPE_ORANGE_1)
       setGlobalStorageValue(config.global_storage, cur_time)
   end
   return true
end
 
Last edited by a moderator:
You guys are butchering this script :(

-- Edit

Wasn't home earlier.
Here's a working script.

Tile can only be activated by a player, every x seconds.
Spawns 1 creature and 1 npc.
Npc removed after y seconds.
Reduces players hp to zz%. If players life is below this percent, does nothing.
LUA:
local config = {
   global_storage = 11111, -- any free storage
   tile_reset_interval = 60, -- seconds
   reduce_player_health_to = 0.15, -- percentage | 0.15 = 15%
   npc = {"Npc_name_here", {x = 100, y = 100, z = 7}, 30}, -- name, position, removal time in seconds
   monster = {"Demon", {x = 100, y = 100, z = 7}}, -- name, position
   player_text = "It's too quiet here..."
}

local function remove_npc(cid)
    if isNpc(cid) then
        doRemoveCreature(cid)
    end
end

function onStepIn(cid, item, position, fromPosition)
   local cur_time = os.time()
   if not isPlayer(cid) and cur_time > getGlobalStorageValue(config.global_storage) + config.tile_reset_interval then
       if getCreatureHealth(cid) > getCreatureMaxHealth(cid) * config.reduce_player_health_to then
           doPlayerAddHealth(cid, -(getCreatureHealth(cid) - getCreatureMaxHealth(cid) * config.reduce_player_health_to))
       end
       local npc = doCreateNpc(config.npc[1], config.npc[2])
       addEvent(remove_npc, config.npc[3], npc)
       doSummonCreature(config.monster[1], config.monster[2])
       doCreatureSay(cid, config.player_text, TALKTYPE_ORANGE_1)
       setGlobalStorageValue(config.global_storage, cur_time)
   end
   return true
end
Hey! Thanks for your help! I'm getting error btw:

Code:
 [Error - MoveEvents Interface]
[10:16:21.778] data/movements/scripts/tamburyn.lua:onStepIn
[10:16:21.778] Description:
[10:16:21.778] data/movements/scripts/tamburyn.lua:20: attempt to call global 'doPlayerAddHealth' (a nil value)
[10:16:21.793] stack traceback:
[10:16:21.793]  data/movements/scripts/tamburyn.lua:20: in function <data/movements/scripts/tamburyn.lua:16>
 
Oops. I copied @Xeraphus's code from post 2.
I'll remember not to do that.
Hey! Thanks for your help! I'm getting error btw:

Code:
 [Error - MoveEvents Interface]
[10:16:21.778] data/movements/scripts/tamburyn.lua:onStepIn
[10:16:21.778] Description:
[10:16:21.778] data/movements/scripts/tamburyn.lua:20: attempt to call global 'doPlayerAddHealth' (a nil value)
[10:16:21.793] stack traceback:
[10:16:21.793]  data/movements/scripts/tamburyn.lua:20: in function <data/movements/scripts/tamburyn.lua:16>
LUA:
local config = {
   global_storage = 11111, -- any free storage
   tile_reset_interval = 60, -- seconds
   reduce_player_health_to = 0.15, -- percentage | 0.15 = 15%
   npc = {"Npc_name_here", {x = 100, y = 100, z = 7}, 30}, -- name, position, removal time in seconds
   monster = {"Demon", {x = 100, y = 100, z = 7}}, -- name, position
   player_text = "It's too quiet here..."
}

local function remove_npc(cid)
   if isNpc(cid) then
       doRemoveCreature(cid)
   end
end

function onStepIn(cid, item, position, fromPosition)
   local cur_time = os.time()
   if isPlayer(cid) and cur_time > getGlobalStorageValue(config.global_storage) + config.tile_reset_interval then
       if getCreatureHealth(cid) > getCreatureMaxHealth(cid) * config.reduce_player_health_to then
           doCreatureAddHealth(cid, -(getCreatureHealth(cid) - getCreatureMaxHealth(cid) * config.reduce_player_health_to))
       end
       local npc = doCreateNpc(config.npc[1], config.npc[2])
       addEvent(remove_npc, config.npc[3], npc)
       doSummonCreature(config.monster[1], config.monster[2])
       doCreatureSay(cid, config.player_text, TALKTYPE_ORANGE_1)
       setGlobalStorageValue(config.global_storage, cur_time)
   end
   return true
end
 
Last edited by a moderator:
Oops. I copied @Xeraphus's code from post 2.
I'll remember not to do that.

LUA:
local config = {
   global_storage = 11111, -- any free storage
   tile_reset_interval = 60, -- seconds
   reduce_player_health_to = 0.15, -- percentage | 0.15 = 15%
   npc = {"Npc_name_here", {x = 100, y = 100, z = 7}, 30}, -- name, position, removal time in seconds
   monster = {"Demon", {x = 100, y = 100, z = 7}}, -- name, position
   player_text = "It's too quiet here..."
}

local function remove_npc(cid)
   if isNpc(cid) then
       doRemoveCreature(cid)
   end
end

function onStepIn(cid, item, position, fromPosition)
   local cur_time = os.time()
   if isPlayer(cid) and cur_time > getGlobalStorageValue(config.global_storage) + config.tile_reset_interval then
       if getCreatureHealth(cid) > getCreatureMaxHealth(cid) * config.reduce_player_health_to then
           doCreatureAddHealth(cid, -(getCreatureHealth(cid) - getCreatureMaxHealth(cid) * config.reduce_player_health_to))
       end
       local npc = doCreateNpc(config.npc[1], config.npc[2])
       addEvent(remove_npc, config.npc[3], npc)
       doSummonCreature(config.monster[1], config.monster[2])
       doCreatureSay(cid, config.player_text, TALKTYPE_ORANGE_1)
       setGlobalStorageValue(config.global_storage, cur_time)
   end
   return true
end
It's better but not works too. First of all, the monster is spawning, the text is appearing but, the NPC is created for a half of seconds and disapear. BTW. I don't know how with HP, cause I'm testing it on GOD player and it doesn't get 15%
 
Back
Top