• 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 Global Event lightning effect on outfit

Status
Not open for further replies.

Goku97

Member
Joined
May 23, 2016
Messages
123
Solutions
2
Reaction score
6
Hi Otland
I have a problem with a script that I'm trying to make also am a newbie with Lua so please go easy on me.
Basically what I'm trying to do is to give a lightning effect on the character / outfit.

The Forgotten Server: 0.3.6
Globalevents.xml:
Code:
<globalevent name="effects" interval="1.0" event="script" value="effects.lua"/>

Script:
Lua:
local config =
{
    effect1 = 1
}
function onThink(interval)

if (getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 2 or getPlayerVocation(cid) == 3 or getPlayerVocation(cid) == 4 or getPlayerVocation(cid) == 5) then
    doSendMagicEffect(getPlayerPosition(cid, config.effect1))
   
end
return true
end

Console Error:
Code:
[15/11/2017 16:20:40] [Error - GlobalEvent Interface] 
[15/11/2017 16:20:40] data/globalevents/scripts/effects.lua:onThink
[15/11/2017 16:20:40] Description: 
[15/11/2017 16:20:40] (internalGetPlayerInfo) Player not found when requesting player info #6

Can anyone help or tell me what I'm doing wrong ?

Thank you in advance for help.
Regards Goku97
 
The variable cid does not exist in onThink so you have to loop the players online:
Lua:
local config = {
    effect1 = 1
}

function onThink(interval)
    local players = getPlayersOnline()
    for i = 1, #players do
        local cid = players[i]
        if isInArray({1, ,2, 3, 4, 5}, getPlayerVocation(cid))
            doSendMagicEffect(getPlayerPosition(cid, config.effect1))
        end
    end
    return true
end

Cleaned the code abit also added isInArray insted of 5 or statments :p
 
Hi @WibbenZ
Thanks for helping but I guess I missed something like always lol.
First error:
Code:
[15/11/2017 17:32:56] [Error - LuaScriptInterface::loadFile] data/globalevents/scripts/effects.lua:9: unexpected symbol near ','
[15/11/2017 17:32:56] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/effects.lua)
[15/11/2017 17:32:56] data/globalevents/scripts/effects.lua:9: unexpected symbol near ','
Fixed that.

Second Error:
Code:
[15/11/2017 17:35:41] [Error - LuaScriptInterface::loadFile] data/globalevents/scripts/effects.lua:10: 'then' expected near 'doSendMagicEffect'
[15/11/2017 17:35:41] [Warning - Event::loadScript] Cannot load script (data/globalevents/scripts/effects.lua)
[15/11/2017 17:35:41] data/globalevents/scripts/effects.lua:10: 'then' expected near 'doSendMagicEffect'
Added 'then '

Third Error:
Code:
[15/11/2017 17:37:14] [Error - GlobalEvent Interface]
[15/11/2017 17:37:14] data/globalevents/scripts/effects.lua:onThink
[15/11/2017 17:37:14] Description:
[15/11/2017 17:37:14] (luaGetThingPosition) Thing not found

[15/11/2017 17:37:14] [Error - GlobalEvent Interface]
[15/11/2017 17:37:14] data/globalevents/scripts/effects.lua:onThink
[15/11/2017 17:37:14] Description:
[15/11/2017 17:37:14] attempt to index a function value
[15/11/2017 17:37:14] stack traceback:
[15/11/2017 17:37:14]     [C]: in function 'doSendMagicEffect'
[15/11/2017 17:37:14]     data/globalevents/scripts/effects.lua:10: in function <data/globalevents/scripts/effects.lua:5>
[15/11/2017 17:37:14] [Error - GlobalEvents::think] Couldn't execute event: effects

So what now ?
Current Code:
Lua:
local config = {
    effect1 = 1
}

function onThink(interval)
    local players = getPlayersOnline()
    for i = 1, #players do
        local cid = players[i]
        if isInArray({1, 2, 3, 4, 5}, getPlayerVocation(cid)) then
            doSendMagicEffect(getPlayerPosition(cid, config.effect1))
        end
    end
    return true
end

Question: did I supposed to add something to it or ?

Thank you for help.
Regards Goku97
 
Hi @Sarah Wesker
Thank for responding to my thread but...

Console Error:
Code:
[15/11/2017 17:58:43] [Error - GlobalEvent Interface]
[15/11/2017 17:58:43] data/globalevents/scripts/effects.lua:onThink
[15/11/2017 17:58:43] Description:
[15/11/2017 17:58:43] data/globalevents/scripts/effects.lua:8: attempt to call global 'Player' (a nil value)
[15/11/2017 17:58:43] stack traceback:
[15/11/2017 17:58:43]     data/globalevents/scripts/effects.lua:8: in function <data/globalevents/scripts/effects.lua:5>
[15/11/2017 17:58:43] [Error - GlobalEvents::think] Couldn't execute event: effects

Current Code:
Lua:
local config = {
    effect1 = 1
}
function onThink(interval)
    local players = getPlayersOnline()
    for i = 1, #players do
        local cid = Player(players[i])
        if isInArray({1, 2, 3, 4, 5}, getPlayerVocation(cid)) then
            doSendMagicEffect(getPlayerPosition(cid, config.effect1))
        end
    end
    return true
end

I hope I've change the right thing.

Thank you for help.
Regards Goku97
 
Hi @Sarah Wesker
Thank for responding to my thread but...

Console Error:
Code:
[15/11/2017 17:58:43] [Error - GlobalEvent Interface]
[15/11/2017 17:58:43] data/globalevents/scripts/effects.lua:onThink
[15/11/2017 17:58:43] Description:
[15/11/2017 17:58:43] data/globalevents/scripts/effects.lua:8: attempt to call global 'Player' (a nil value)
[15/11/2017 17:58:43] stack traceback:
[15/11/2017 17:58:43]     data/globalevents/scripts/effects.lua:8: in function <data/globalevents/scripts/effects.lua:5>
[15/11/2017 17:58:43] [Error - GlobalEvents::think] Couldn't execute event: effects

Current Code:
Lua:
local config = {
    effect1 = 1
}
function onThink(interval)
    local players = getPlayersOnline()
    for i = 1, #players do
        local cid = Player(players[i])
        if isInArray({1, 2, 3, 4, 5}, getPlayerVocation(cid)) then
            doSendMagicEffect(getPlayerPosition(cid, config.effect1))
        end
    end
    return true
end

I hope I've change the right thing.

Thank you for help.
Regards Goku97

Player userdata is for 1.x not for 0.x.
Try this;
Lua:
local config = {
    effect1 = 1
}

function onThink(interval)
    local players = getPlayersOnline()
    for i = 1, #players do
        local cid = players[i]
        if isPlayer(cid) and isInArray({1, 2, 3, 4, 5}, getPlayerVocation(cid)) then
            doSendMagicEffect(getPlayerPosition(cid, config.effect1))
        end
    end
    return true
end
 
Hi @WibbenZ

Console error:
Code:
[15/11/2017 19:29:03] [Error - GlobalEvent Interface]
[15/11/2017 19:29:03] data/globalevents/scripts/effects.lua:onThink
[15/11/2017 19:29:03] Description:
[15/11/2017 19:29:03] (luaGetThingPosition) Thing not found

[15/11/2017 19:29:03] [Error - GlobalEvent Interface]
[15/11/2017 19:29:03] data/globalevents/scripts/effects.lua:onThink
[15/11/2017 19:29:03] Description:
[15/11/2017 19:29:03] attempt to index a function value
[15/11/2017 19:29:03] stack traceback:
[15/11/2017 19:29:03]     [C]: in function 'doSendMagicEffect'
[15/11/2017 19:29:03]     data/globalevents/scripts/effects.lua:10: in function <data/globalevents/scripts/effects.lua:5>
[15/11/2017 19:29:03] [Error - GlobalEvents::think] Couldn't execute event: effects

Thanks for help
Regards Goku97

Hi Otland
I took me awhile but I did it!
Here is the working code:
Lua:
-- Script made by GraveWalker --
local config = {
storage = 31520,
timee = 1,
effect1 = 1,
}

function onThink(interval)
    local players = getPlayersOnline()
    for _, cid in ipairs(getPlayersOnline()) do
if (getPlayerVocation(cid) == 1 or getPlayerVocation(cid) == 2)
    and exhaustion.get(cid, config.storage) == false then
        doSendMagicEffect(getPlayerPosition(cid), config.effect1)
        exhaustion.set(cid, config.storage, config.timee)
    end
end
return true
end

Thanks to @WibbenZ and to @Sarah Wesker for trying to help.

Thanks for help.
Regards Goku97
 
Status
Not open for further replies.
Back
Top