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

Solved Magic Effect on SQM

Ussef

New Member
Joined
May 27, 2009
Messages
123
Reaction score
2
Hi there! Not sure if I'm asking in the right place. I need help with a script of making a magic effect on a certain sqm. So like every 5 seconds a teleport says Dragons! Not sure how im suppose to do this.
 
Code:
local config = {
positions = {
{pos = { x =32345, y =32228, z= 4 }, text = "Dragons", effects = {CONST_ME_MAGIC_BLUE}},
{pos = {x = 32350,y = 32230,z = 4 }, text = "Trainer"}
},
effects = {CONST_ME_POFF, CONST_ME_TELEPORT, CONST_ME_MAGIC_RED}
}

function onThink(interval)
local people = getPlayersOnline()
if #people == 0 then
return true
end

for _, info in pairs(config.positions) do
doPlayerSay(people[1], info.text, TALKTYPE_MONSTER_SAY, false, 0, info.pos)
if info.effects and #info.effects > 0 then
doSendMagicEffect(info.pos, info.effects[math.random(#info.effects)])
elseif config.effects and #config.effects > 0 then
doSendMagicEffect(info.pos, config.effects[math.random(#config.effects)])
end
end
return true
end
 
Thanks mate! But one more thing where do I put the file movements? It's been a long time since I scripted so I forgot a lot of things..... Gettin back into it.
 
globalevents.xml
Code:
<globalevent name="talkingSigns" interval="4000" script="talking.lua"/>

talking.lua
Code:
local config = {
     positions = {
         {pos = {x = 100, y = 120, z = 7}, text = "Dragons", effects = {CONST_ME_MAGIC_BLUE}},
         {pos = {x = 101, y = 120, z = 7}, text = "Trainer"}
     },
     effects = {CONST_ME_POFF, CONST_ME_TELEPORT, CONST_ME_MAGIC_RED}
}

function onThink(interval)
     local people = getOnlinePlayers()
     if #people == 0 then
         return true
     end

     for _, info in pairs(config.positions) do
         doCreatureSay(getPlayerByName(people[1]), info.text, TALKTYPE_ORANGE_1, false, 0, info.pos)
         if info.effects and #info.effects > 0 then
             doSendMagicEffect(info.pos, info.effects[math.random(#info.effects)])
         elseif config.effects and #config.effects > 0 then
             doSendMagicEffect(info.pos, config.effects[math.random(#config.effects)])
         end
     end
     return true
end
 
ye definetly. look i dont completely understand the script put what i did was this..

i put this in the globalevents.xml file
<globalevent name="talkingSigns" interval="4000" script="talking.lua"/>

then
i put the other script in an lua file i named talking..
local config = {
positions = {
{pos = {x = 824, y = 884, z = 7}, text = "Dragons", effects = {CONST_ME_MAGIC_BLUE}},
{pos = {x = 824, y = 885, z = 7}, text = "Trainer"}
},
effects = {CONST_ME_POFF, CONST_ME_TELEPORT, CONST_ME_MAGIC_RED}
}

function onThink(interval)
local people = getOnlinePlayers()
if #people == 0 then
return true
end

for _, info in pairs(config.positions) do
doCreatureSay(getPlayerByName(people[1]), info.text, TALKTYPE_ORANGE_1, false, 0, info.pos)
if info.effects and #info.effects > 0 then
doSendMagicEffect(info.pos, info.effects[math.random(#info.effects)])
elseif config.effects and #config.effects > 0 then
doSendMagicEffect(info.pos, config.effects[math.random(#config.effects)])
end
end
return true
end




all i did was change the position

wht did i do wrong?
 
Code:
doCreatureSay(getPlayerByName(people[1]), info.text, TALKTYPE_ORANGE_1, false, 0, info.pos)
It saying only to the first logged player.

You have to add two loops, one for players and 2nd for effects positions.
Code:
for p = 1, #people do
    doCreatureSay(getPlayerByName(people[p]), info.text, TALKTYPE_ORANGE_1, false, 0, info.pos)
    ...
 
The function doCreatureSay with TALKTYPE_ORANGE_1/TALKTYPE_MONSTER does not give a message to a player, it shows the message for everyone, like animated text.
The script already works, there is something else wrong.

@Ussef
You can add something like a broadcast message or print (under function onThink) to see if the script is loading, if it loads, it should give this message every 4 seconds.
 
Omg it worked!! thanks guys!!! I love you for all the help.

basically i solved it... i was an idiot and there was nothing wrong with the script.. i put the line in globalevents in btween a comment...
 
Hello I tried the edit on 1.1 TFS, eventhough its all in compat.lua wrote like this, it colidates with anything :/


Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/talking.lua:onThink
data/globalevents/scripts/talking.lua:9: attempt to call global 'getOnlinePlayers' (a nil value)
stack traceback:
        [C]: in function 'getOnlinePlayers'
        data/globalevents/scripts/talking.lua:9: in function <data/globalevents/scripts/talking.lua:8>
[Error - GlobalEvents::think] Failed to execute event: talkingSigns
 
Hello I tried the edit on 1.1 TFS, eventhough its all in compat.lua wrote like this, it colidates with anything :/


Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/talking.lua:onThink
data/globalevents/scripts/talking.lua:9: attempt to call global 'getOnlinePlayers' (a nil value)
stack traceback:
        [C]: in function 'getOnlinePlayers'
        data/globalevents/scripts/talking.lua:9: in function <data/globalevents/scripts/talking.lua:8>
[Error - GlobalEvents::think] Failed to execute event: talkingSigns
getOnlinePlayers() > Game.getPlayers()
 
Didnt fix the problem
my script:
Code:
local config = {
     positions = {
         {pos = {x = 32358, y = 32241, z = 7}, text = "VIP ZONE!"}
     },
     effects = {CONST_ME_POFF, CONST_ME_TELEPORT, CONST_ME_MAGIC_RED}
}

function onThink(interval)
     local people = Game.getPlayers()
     if #people == 0 then
         return true
     end

     for _, info in pairs(config.positions) do
         doCreatureSay(getPlayerByName(people[1]), info.text, TALKTYPE_ORANGE_1, false, 0, info.pos)
         if info.effects and #info.effects > 0 then
             doSendMagicEffect(info.pos, info.effects[math.random(#info.effects)])
         elseif config.effects and #config.effects > 0 then
             doSendMagicEffect(info.pos, config.effects[math.random(#config.effects)])
         end
     end
     return true
end
 
Didnt fix the problem
my script:
Code:
local config = {
     positions = {
         {pos = {x = 32358, y = 32241, z = 7}, text = "VIP ZONE!"}
     },
     effects = {CONST_ME_POFF, CONST_ME_TELEPORT, CONST_ME_MAGIC_RED}
}

function onThink(interval)
     local people = Game.getPlayers()
     if #people == 0 then
         return true
     end

     for _, info in pairs(config.positions) do
         doCreatureSay(getPlayerByName(people[1]), info.text, TALKTYPE_ORANGE_1, false, 0, info.pos)
         if info.effects and #info.effects > 0 then
             doSendMagicEffect(info.pos, info.effects[math.random(#info.effects)])
         elseif config.effects and #config.effects > 0 then
             doSendMagicEffect(info.pos, config.effects[math.random(#config.effects)])
         end
     end
     return true
end


I'm also using this script, and on TFS 1.1.
Error:
Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/tpeffect.lua:onThink
data/globalevents/scripts/tpeffect.lua:17: attempt to call global 'getPlayerByName' (a nil value)
stack traceback:
    [C]: in function 'getPlayerByName'
    data/globalevents/scripts/tpeffect.lua:17: in function <data/globalevents/scripts/tpeffect.lua:10>
[Error - GlobalEvents::think] Failed to execute event: talkingSigns
 
Back
Top