CesarZ
Well-Known Member
- Joined
- Sep 20, 2012
- Messages
- 268
- Solutions
- 4
- Reaction score
- 63
Im having this Issue with global.lua
How can i register the "broadcastMessage" in my Global.lua? its been mayor problem when i try to run scripts i find because some of the things are not registered. When i run the script with another global.lua it works fine, but the other things don't work because they obviously not registered in the new global.lua.
I extracted the 'broadcastMessage' function from the Global.lua that work with the script, Set it up in the Global I need for the server to work properly, and still get the error message.
This is the script i extracted from the Global.lua that worked with the script:
the Script im trying to run:
solved
How can i register the "broadcastMessage" in my Global.lua? its been mayor problem when i try to run scripts i find because some of the things are not registered. When i run the script with another global.lua it works fine, but the other things don't work because they obviously not registered in the new global.lua.
I extracted the 'broadcastMessage' function from the Global.lua that work with the script, Set it up in the Global I need for the server to work properly, and still get the error message.
This is the script i extracted from the Global.lua that worked with the script:
Code:
function Game.broadcastMessage(message, messageType)
if messageType == nil then
messageType = MESSAGE_STATUS_WARNING
end
for _, player in ipairs(Game.getPlayers()) do
player:sendTextMessage(messageType, message)
end
end
the Script im trying to run:
Lua:
local centeroffight = {x = 1085, y = 964, z = 7} --Fighting room--
local waitingplace = {x = 1032, y = 946, z = 7} -- Waiting room--
local depotcenter = {x = 805, y = 999, z = 6} --where lost players will exit--
local MinimumPlayers = 2
local rewardpoints = 2
local function lmsclosed1()
broadcastMessage("Last Man Standing event will start in 1 minutes. Portal is opened in depot", MESSAGE_STATUS_WARNING)
end
local function lmsclosed()
count = 0
local spectators = getSpectators(waitingplace, 10, 10, false)
if spectators ~= nil then
for _, spectator in ipairs(spectators) do
if isPlayer(spectator) then
count = count + 1
end
end
end
if (count >= MinimumPlayers) then
broadcastMessage("Last Man Standing event portal closed and event started!", MESSAGE_STATUS_WARNING)
for _, pid in ipairs(getOnlinePlayers()) do
if getPlayerStorageValue(pid, 25001) == 1 then
local playerids = getPlayerByName(pid)
doTeleportThing(playerids,centeroffight)
doSendMagicEffect(center, CONST_ME_TELEPORT)
end
end
else
broadcastMessage("Not enough players to start Last man Standing event! Minimum: "..MinimumPlayers.." players. We have "..count.."!", MESSAGE_STATUS_WARNING)
setGlobalStorageValue(25002, 0)
for _, pid in ipairs(getOnlinePlayers()) do
if getPlayerStorageValue(pid, 25001) == 1 then
local playerids = getPlayerByName(pid)
doTeleportThing(playerids,depotcenter)
doSendMagicEffect(depotcenter, CONST_ME_TELEPORT)
setPlayerStorageValue(pid, 25001, 0)
end
end
end
return true
end
local function lmscheck()
count = 0
local spectators = getSpectators(centeroffight, 10, 10, false)
if spectators ~= nil then
for _, spectator in ipairs(spectators) do
if isPlayer(spectator) then
count = count + 1
end
end
end
if count == 1 then
for _, pid in ipairs(getOnlinePlayers()) do
if getPlayerStorageValue(pid, 25001) == 1 then
local playerids = getPlayerByName(pid)
setPlayerStorageValue(playerids, 25001, 0)
end
end
local spectators = getSpectators(centeroffight, 10, 10, false)
if spectators ~= nil then
for _, spectator in ipairs(spectators) do
if isPlayer(spectator) then
doTeleportThing(spectator,depotcenter)
doSendMagicEffect(depotcenter, CONST_ME_TELEPORT)
broadcastMessage("LMS ended winner is: "..getPlayerName(spectator)..", reward is 2 premium points.", MESSAGE_STATUS_WARNING)
local accid = Player(spectator):getAccountId()
local points = rewardpoints
db.query("UPDATE `znote_accounts` SET `points` = `points` + " .. points .. " WHERE `id` = " .. accid)
end
end
end
for _, pid in ipairs(getOnlinePlayers()) do
if getPlayerStorageValue(pid, 25001) == 1 then
local playerids = getPlayerByName(pid)
setPlayerStorageValue(pid, 25001, 0)
end
end
stopEvent(lmscheck)
else
addEvent(lmscheck, 10*1000)
end
end
local function lms()
broadcastMessage("Last Man Standing event will start in 2 minutes. Portal is opened in depot", MESSAGE_STATUS_WARNING)
portalwhere = {x= 805, y=999, z=7} -- where the portal will apear in the city --
local portal = doCreateItem(11796,1,portalwhere)
doSetItemActionId(portal, 25001)
doSendMagicEffect(portalwhere, CONST_ME_TELEPORT)
iteminfo = {x= 804, y=999, z=7} --Teleport Sing right next to the teleport---
local item = doCreateItem(1431,1,iteminfo)
doSetItemActionId(item, 25002)
doSendMagicEffect(iteminfo, CONST_ME_TELEPORT)
addEvent(function() doRemoveItem(getTileItemById(portalwhere, 11796).uid) end, 120 * 1000)
addEvent(function() doSendMagicEffect(portalwhere, CONST_ME_TELEPORT) end, 120 * 1000)
addEvent(function() doRemoveItem(getTileItemById(iteminfo, 1431).uid) end, 120 * 1000)
addEvent(function() doSendMagicEffect(iteminfo, CONST_ME_TELEPORT) end, 120 * 1000)
addEvent(lmsclosed, 2*60*1000)
addEvent(lmsclosed1, 1*60*1000)
addEvent(lmscheck, 130*1000)
return true
end
function onTime(interval)
broadcastMessage("Last Man Standing event will start in 3 minutes.", MESSAGE_STATUS_WARNING)
addEvent(lms, 60*1000)
return true
end
Post automatically merged:
solved
Lua:
function Game.broadcastMessage(message, messageType)
if messageType == nil then
messageType = MESSAGE_STATUS_WARNING
end
for _, player in ipairs(Game.getPlayers()) do
player:sendTextMessage(messageType, message)
end
return true
end
Last edited: