• 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...
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 isNpc(cid) then
       doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
       addEvent(doRemoveCreature, 0, 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))
           doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_RED)
       end
       local npc = doCreateNpc(config.npc[1], config.npc[2])
       addEvent(remove_npc, config.npc[3] * 1000, 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
 
Solution
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 isNpc(cid) then
       doSendMagicEffect(getThingPos(cid), CONST_ME_POFF)
       addEvent(doRemoveCreature, 0, 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))
           doSendMagicEffect(getThingPosition(cid), CONST_ME_MAGIC_RED)
       end
       local npc = doCreateNpc(config.npc[1], config.npc[2])
       addEvent(remove_npc, config.npc[3] * 1000, 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 works! Thanks a lot!
 
Back
Top