• 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!

A script reading var of other script

boby psaico

Member
Joined
Oct 17, 2009
Messages
84
Reaction score
5
Well, someone knows tell me why the script reads a var from another script?

Example:

This script, called Obujos.lua:

Code:
local BOSS_GLOBAL_STORAGE = 80510
local BOSS = "Obujos"

function onKill(cid, target)

if getCreatureName(target) == BOSS then
if(getGlobalStorageValue(BOSS_GLOBAL_STORAGE) < 1) then
setGlobalStorageValue(BOSS_GLOBAL_STORAGE, 1)
end
end
return true
end

And this, called Jaul.lua

Code:
local BOSS_GLOBAL_STORAGE = 80509
local BOSS = "Jaul"

function onKill(cid, target)

if getCreatureName(target) == BOSS then
if(getGlobalStorageValue(BOSS_GLOBAL_STORAGE) < 1) then
setGlobalStorageValue(BOSS_GLOBAL_STORAGE, 1)
end
end
return true
end

What happens is that when i kill Jaul, the script Jaul.lua reads the var BOSS_GLOBAL_STORAGE from both scripts, and then changes both (80509 and 80510) to 1

Why this is happening?
 
It can't change both unless both scripts are executed. Add this print after onKill to check the values.

Code:
print(getCreatureName(target) .. " - storage: " .. BOSS_GLOBAL_STORAGE .. ", name: " .. BOSS)
 
this print only shows 80509 when I kill Jaul
I'll redo it and then I say if it worked.
Must be some my mistake, im tired lately

But thanks :p
 
No problem. Two more questions. Did you put this print to both scripts and did the change of 2 storages occurred again?
 
I've put both, but just what I killed changed, as it should

i'll redo and post here to us

EDIT:

It's done.

This is script to kill deepling bosses, I still didn't the chests.

Well, create a line in creaturescripts.xml:

PHP:
    <event type="kill" name="Obujos" script="bosses/obujos.lua"/>

Later, create the folder "bosses" and obujos.lua inside, put this there:

Code:
local BOSS_GLOBAL_STORAGE = 80510 -- to differentiate one from another boss
local TEMPO_SALA = 20 * 60 -- time to be kicked from the room (20 minutes)
local TEMPO_QUEST = 24 * 60 * 60 -- time to enter again on the boss room after killing one (24hours)
local STORAGE_TEMPO_ESPERAR = 22001 -- storage to count 24 hours
local BOSS = "Obujos" -- boss name
local room = {fromx = 33416, tox = 33446, fromy = 31254, toy = 31275, z = 11} -- area boss room
local PLAYER_OUT = {x = 33438, y = 31249, z = 11} -- where will be kicked
local UID_TELEPORT = 8001 -- uid of entrance teleport

function onKill(cid, target)
    if getCreatureName(target) == BOSS then
        setPlayerStorageValue(cid, STORAGE_TEMPO_ESPERAR, os.time() + TEMPO_QUEST)
        doSetItemActionId(UID_TELEPORT, 8001)
        if(getGlobalStorageValue(BOSS_GLOBAL_STORAGE + 1000) < 1) then
            setGlobalStorageValue(BOSS_GLOBAL_STORAGE + 1000, 1)
            addEvent(removePlayerJaul, TEMPO_SALA * 1000)
        end
    end
    return true
end

-- REMOVE O JOGADOR SE EXCEDER O TEMPO
function removePlayerJaul()

for x = room.fromx, room.tox do
for y = room.fromy, room.toy do
for z = room.z, room.z do

creature = {x = x, y = y, z = z}
mob = getTopCreature(creature).uid

if isPlayer(mob) then
    doTeleportThing(mob, PLAYER_OUT)
    doSendMagicEffect(PLAYER_OUT, CONST_ME_TELEPORT)
end
addEvent(storageObujosDelay, 1000)
end
end
end
return TRUE
end

-- VOLTA O STORAGE AO NORMAL
function storageObujosDelay()
    setGlobalStorageValue(BOSS_GLOBAL_STORAGE + 1000, -1)
    doSetItemActionId(UID_TELEPORT, 8000)
end


Now, add this line in globalevents.xml:

PHP:
<globalevent name="Obujos" interval="5000" script="bosses/Obujos.lua"/>

Create folder with name "bosses" and Obujos.lua inside there:

Code:
local BOSS = "Obujos" -- boss name
local BOSS_POS = {x = 33434, y = 31262, z = 11} -- boss spawn coord
local room = {fromx = 33416, tox = 33446, fromy = 31254, toy = 31275, z = 11} -- boss room
local BOSS_GLOBAL_STORAGE = 80510 -- dont change
local BOSS_GLOBAL_STORAGE_SUMMON = 25001 -- dont change
local TEMPO_RESP = 3 * 60 -- em segundos -- respawn time

function onThink(interval, lastExecution)

local boss = 0
for x = room.fromx, room.tox do
for y = room.fromy, room.toy do
for z = room.z, room.z do

creature = {x = x, y = y, z = z}
mob = getTopCreature(creature).uid

    if isMonster(mob) and not(isSummon(mob)) and getCreatureName(mob) == BOSS then
        boss = 1
    end
end
end
end

if boss == 1 then
end

if boss == 0 then
    if getGlobalStorageValue(BOSS_GLOBAL_STORAGE) == -1 and getGlobalStorageValue(BOSS_GLOBAL_STORAGE_SUMMON) == 1 then
        setGlobalStorageValue(BOSS_GLOBAL_STORAGE, 1)
        addEvent(efeito1Obujos1, TEMPO_RESP * 1000)
    end
end

return TRUE
end

-- EFEITO 1
function efeito1Obujos1()
    doSendMagicEffect(BOSS_POS, CONST_ME_TELEPORT)
    addEvent(efeito2Obujos1, 2000)
end

-- EFEITO 2
function efeito2Obujos1()
    doSendMagicEffect(BOSS_POS, CONST_ME_TELEPORT)
    addEvent(efeito3Obujos1, 2000)
end

-- EFEITO 3
function efeito3Obujos1()
    doSendMagicEffect(BOSS_POS, CONST_ME_TELEPORT)
    addEvent(spawnObujos1, 2000)
end

-- SPAWN OBUJOS
function spawnObujos1()
    doForceSummonCreature(BOSS, BOSS_POS)
        setGlobalStorageValue(BOSS_GLOBAL_STORAGE, -1)
end

Then, add other line in globalevents.xml:

PHP:
<globalevent name="Obujos2" interval="1000" script="bosses/obujosSpawn.lua"/>

REMEMBER: to add this line u need erase the spawn of obujos from map editor, he will auto spawned with this script

create obujosSpawn.lua inside of folder "bosses":

Code:
function onThink(interval, lastExecution)

local BOSS_GLOBAL_STORAGE = 25001 -- dont change
local BOSS = "Obujos" -- boss name
local BOSS_POS = {x = 33434, y = 31262, z = 11} -- spawn coord

    if getGlobalStorageValue(BOSS_GLOBAL_STORAGE) == -1 then
        doForceSummonCreature(BOSS, BOSS_POS)
            setGlobalStorageValue(BOSS_GLOBAL_STORAGE, 1)
        end
return TRUE
end

To finish, add this line in movements.xml

PHP:
<movevent event="StepIn" uniqueid="8001" script="deepling/obujosEnter.lua"/>

CHANGE the uniqueid to 8001 and actionID to 8000 of teleport on map editor and erase the coordinates there

create folder "deepling" and obujosEnter.lua:

Code:
function onStepIn(cid, item, position, lastPosition, fromPosition, toPosition, actor)
local TEMPO_RESTANTE = getPlayerStorageValue(cid, 22001) - os.time() -- dont change
local UID_TELEPORT = 8001 -- uid from teleport, dont change

    if item.uid == UID_TELEPORT and item.actionid == 8000 then
          if TEMPO_RESTANTE <= 0 then
            doTeleportThing(cid, {x = 33420, y = 31256, z = 11}) -- enter coord
            doSendMagicEffect({x = 33420, y = 31256, z = 11}, CONST_ME_TELEPORT)
          else
            doTeleportThing(cid, {x = 33440, y = 31249, z = 11}) -- exit coord
            doSendMagicEffect({x = 33440, y = 31249, z = 11}, CONST_ME_TELEPORT)
              doCreatureSay(cid, "Do You still need to wait " .. TEMPO_RESTANTE .. " seconds to enter.", TALKTYPE_ORANGE_1)
        end
        end
     
        if item.uid == UID_TELEPORT and item.actionid == 8001 then
                doTeleportThing(cid, {x = 33440, y = 31249, z = 11}) -- exit coord
        doSendMagicEffect({x = 33440, y = 31249, z = 11}, CONST_ME_TELEPORT)
        doCreatureSay(cid, "You cannot enter because have other team inside there.", TALKTYPE_ORANGE_1)
    end

    return true
end


I know that this script is very tiring
and I can't make a good tutorial because my english is bad
but I will try to answer any questions
OBS: ive used global map coord
 
Last edited:
Back
Top