01-17-2014, 04:00 AM
But if it was static, how would it know what world to count ticks against?
|
Countdown
|
|
01-17-2014, 04:00 AM
But if it was static, how would it know what world to count ticks against?
01-17-2014, 04:07 AM
(This post was last modified: 01-17-2014, 04:08 AM by daniel0916.)
01-17-2014, 04:49 AM
The ScheduleTask has not yet been exported, I'm doing it now.
Thanks given by: daniel0916
01-17-2014, 11:35 PM
cRoot:Get():GetWorld("world"):ScheduleTask(LobbyCountDown(I), (COUNT_TO - I) * 20);
function LobbyCountDown(Time) Error: Code: [14:33:13] LUA: Plugins/SurvivalGames/onplayerspawn.lua:34: Error in function call 'ScheduleTask': Expected a function for parameter #1I use the newest MCServer Version.
01-17-2014, 11:59 PM
You need to first define the function, and only then use it.
Since you're probably trying to make a closure, too, post a more complete code snippet.
01-18-2014, 12:07 AM
local COUNT_TO = 60;
for I=COUNT_TO, 0, -1 do -- Countdown
--AddLobbySchedule(LobbyCountDown, {I}, (COUNT_TO - I) * 20);
cRoot:Get():GetWorld("world"):ScheduleTask(LobbyCountDown(I), (COUNT_TO - I) * 20);
end
function LobbyCountDown(Time)
cRoot:Get():ForEachPlayer(function(Player)
Player:DeltaExperience(-(cPlayer:XpForLevel(Player:GetXpLevel()) - cPlayer:XpForLevel(Player:GetXpLevel() - 1)));
end)
if (Time == 60) then
cRoot:Get():ForEachPlayer(function(Player)
Player:DeltaExperience(-Player:GetXpLevel());
Player:DeltaExperience(cPlayer:XpForLevel(60));
end)
cRoot:Get():BroadcastChat(Time);
elseif (Time == 50) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 40) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 30) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 20) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 15) then
cRoot:Get():ForEachPlayer(function(Player)
Player:GetInventory():Clear();
Player:GetInventory():SetHotbarSlot(8, cItem(E_ITEM_FIRE_CHARGE));
end)
--cRoot:Get():BroadcastChat("The Voting has ended!");
--cRoot:Get():BroadcastChat("Map: " .. map);
elseif (Time == 10) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 9) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 8) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 7) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 6) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 5) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 4) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 3) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 2) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 1) then
cRoot:Get():BroadcastChat(Time);
elseif (Time == 0) then
cRoot:Get():BroadcastChat(Time);
local onlineplayers = cRoot:Get():GetServer():GetNumPlayers();
if (onlineplayers >= 0) then
gamerunning = "yes";
cRoot:Get():ForEachPlayer(function(Player)
--Player:DeltaExperience(-Player:GetXpLevel());
Player:GetInventory():Clear();
Player:SetGameMode(0);
--Player:MoveToWorld(map);
--Teleport player to right coords...
--Player:TeleportToCoords(48, 4, 283);
local COUNT_TO = 30;
for I=COUNT_TO, 0, -1 do -- Countdown
--AddStartSchedule(StartCountDown, {I}, (COUNT_TO - I) * 20);
cRoot:Get():GetWorld("world").ScheduleTask(StartCountDown(I), (COUNT_TO - I) * 20);
end
end)
else
cRoot:Get():BroadcastChat("Game don't start. Too few players!");
end
end
end
Well, what a mess...
local World = cRoot:Get():GetWorld("world")
local GameStartSecond = 60 -- Number of seconds till the game start
local GameStartTick = GameStartSecond * 20
-- Set up timed messages until the game start:
local AnnouncedSecods = {60, 50, 40, 30, 20, 10, 9, 8, 7, 6, 5, 4, 3, 2} -- When to broadcast
for idx, Second in ipairs(AnnouncedSeconds) do
World:ScheduleTask(
function (a_World)
a_World:BroadcastChat("Time till game start: " .. Second .. " seconds")
end,
GameStartTick - Second * 20
)
end
-- One last message to schedule, due to message text change:
World:ScheduleTask(
function (a_World)
a_World:BroadcastChat("Time till game start: 1 second");
end,
GameStartTick - 20 -- 1 second before game start
)
-- Schedule the Voting end:
World:ScheduleTask(
function (a_World)
-- a_World:BroadcastChat("The Voting has ended!");
a_World:ForEachPlayer(
function(Player)
Player:GetInventory():Clear();
Player:GetInventory():SetHotbarSlot(8, cItem(E_ITEM_FIRE_CHARGE));
end
)
end,
GameStartTick - 15 * 20 -- 15 seconds before game start
)
-- Schedule the game start:
World:ScheduleTask(
function (a_World)
-- TODO: Start the game
end,
GameStartTick
)
Note that this was written off memory, so it may contain errors. Thanks given by: daniel0916
01-18-2014, 02:40 AM
(This post was last modified: 01-18-2014, 07:50 AM by daniel0916.)
Thanks, this code looks very better
.Edit: I think i found the mistake. You writed AnnouncedSecods and not AnnouncedSeconds.. Edit2: Okay, now it comes no error but the schedule isn't starting.. i will see if i can fix it. Edit3: What is here false? I will try something with mcserver code. Code: a_Player->SendMessage(a_Item.m_ItemType);
01-18-2014, 08:10 AM
The SendMessage function expects a string as its parameter, and you are giving it a number.
01-18-2014, 07:28 PM
(This post was last modified: 01-18-2014, 08:00 PM by daniel0916.)
|
|
« Next Oldest | Next Newest »
|