Cuberite Forum
Countdown - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: Countdown (/thread-1314.html)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13


RE: Countdown - bearbin - 01-17-2014

But if it was static, how would it know what world to count ticks against?


RE: Countdown - daniel0916 - 01-17-2014

(01-17-2014, 03:59 AM)STR_Warrior Wrote: Maybe it's static? then you have to use: cWorld:ScheduleTask
Also don't work.

(01-17-2014, 04:00 AM)bearbin Wrote: But if it was static, how would it know what world to count ticks against?
right.


RE: Countdown - xoft - 01-17-2014

The ScheduleTask has not yet been exported, I'm doing it now.


RE: Countdown - daniel0916 - 01-17-2014

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 #1
[14:33:13] Stack trace:
[14:33:13]   [C](-1): (no name)
[14:33:13]   [C](-1): ScheduleTask
[14:33:13]   Plugins/SurvivalGames/onplayerspawn.lua(34): (no name)
[14:33:13] Stack trace end
[14:33:13] Error in plugin SurvivalGames calling function <callback>()

I use the newest MCServer Version.


RE: Countdown - xoft - 01-17-2014

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.


RE: Countdown - daniel0916 - 01-18-2014

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



RE: Countdown - xoft - 01-18-2014

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.


RE: Countdown - daniel0916 - 01-18-2014

Thanks, this code looks very better Smile.

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);



RE: Countdown - xoft - 01-18-2014

The SendMessage function expects a string as its parameter, and you are giving it a number.


RE: Countdown - daniel0916 - 01-18-2014

(01-18-2014, 08:10 AM)xoft Wrote: The SendMessage function expects a string as its parameter, and you are giving it a number.

Oh, thanks.
What program are you using for mcserver programming?
And can i start mcserver from them? without compiling?

Edit: Should i download Visual C++ 2013 or 2008?