Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eluna Running and reloading on Multiple maps causing issues #485

Closed
JadaDev opened this issue Jul 5, 2024 · 3 comments
Closed

Eluna Running and reloading on Multiple maps causing issues #485

JadaDev opened this issue Jul 5, 2024 · 3 comments

Comments

@JadaDev
Copy link

JadaDev commented Jul 5, 2024

When i use reload Eluna it actually reloads on all maps i understand that but -1 should be all maps,

image

Now my problem is i wrote normal script and it's running multiple times :

image

Simple Script :

-- Simple server time announcing.

local eachmsec = 60000

local function AnnounceServerTime(eventId, delay, repeats)
    local currentTime = GetGameTime()
    local hours = math.floor(currentTime / 3600) % 24
    local minutes = math.floor(currentTime / 60) % 60
    local ampm = "AM"
    if hours >= 12 then
        ampm = "PM"
    end
    if hours > 12 then
        hours = hours - 12
    elseif hours == 0 then
        hours = 12
    end
    local timeString = string.format("%02d:%02d %s", hours, minutes, ampm)
    SendWorldMessage("Server Time: " .. timeString)
end

CreateLuaEvent(AnnounceServerTime, eachmsec, 0)

@Foereaper
Copy link
Member

Foereaper commented Jul 6, 2024

That's as expected. Each map has its own Lua state, and each state runs every script that is considered global.

If you want a script to only run on a specific map, put it in a subdirectory prefixed with the map id. If you only want it to run in the global state, add the following to the top of the script.

-- Do not load for the global state
if(GetStateMapId() ~= -1) then return; end

If you want it to run on all states except the global state, then reverse the logic and do ==.

@JadaDev
Copy link
Author

JadaDev commented Jul 10, 2024

That wasn't the case before, why this change all of sudden ?

@JadaDev JadaDev closed this as completed Jul 10, 2024
@Foereaper
Copy link
Member

Foereaper commented Jul 10, 2024

I imagine you didn't intend to close the issue, so I'll reopen it.

From July 1st we've officially switched from the old, single state implementation to multistate by default. What multistate is, is explained in length on our discord server. I'm not sure if you're a member there or not, but it's in the announcement channel.

I'm short, multistate has unique Lua states per map for pretty large performance reasons. The old single state scheme forced emulators to run single threaded, which is pretty bad. Some scripts therefore need to be adjusted to work as intended with multistate.

@Foereaper Foereaper reopened this Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants