1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

Progress Bars

Discussion in 'Development' started by Polis, Feb 17, 2014.

  1. Polis

    Polis Guest

    Hey. I was wondering, how does one use a progress bar (like seen when getting up from being unconscious) in their own plugins? Say I ran a command, and I wanted a progress bar that says 'derp' to pop up on the screen for a set amount of time before the function continued.
     
  2. Polis

    Polis Guest

    Bump.
     
  3. kurozael

    kurozael Cloud Sixteen Director Staff Member Administrator Investor

    Code:
    function PLUGIN:GetProgressBarInfo()
    	if (myProgressBarShouldShow) then
    		-- Percentage to display (from 0 to 100).
    		var barPercentage = 100;
    
    		-- Should the bar flash (boolean).
    		var barShouldFlash = (barPercentage < 10);
    
    		return {
    			text = "This is the text on the bar.",
    			percentage = barPercentage,
    			flash = barShouldFlash
    		};
    	end;
    end;
    
     
  4. Polis

    Polis Guest

    Cheers. :)
     
  5. kurozael

    kurozael Cloud Sixteen Director Staff Member Administrator Investor

    An example of GetProgressBarInfo can be found in the cl_kernel.lua file. Most hooks can be found in cl_kernel.lua or sv_kernel.lua

    https://github.com/CloudSixteen/Clockwork/blob/master/Clockwork/garrysmod/gamemodes/clockwork/framework/cl_kernel.lua#L1882
     
  6. kurozael

    kurozael Cloud Sixteen Director Staff Member Administrator Investor

    This hook is client-side though, so you'll probably need to send some information via usermessage or datastream to tell the client how to display it, how long for, etc etc.
     
  7. Razor

    Razor Guest

    (Posted this anyway because I was typing before kurozael replied)

    With all this information, you should just go ahead and build a plugin.
    Never edit the framework.


    Kurchio Saves The Day Kruzel replied before I was done typing.

    Look at this Clockwork hook:

    Code:
    -- Called when the progress bar info is needed.
    function Clockwork:GetProgressBarInfo()
    	local action, percentage = self.player:GetAction(self.Client, true);
    	
    	if (!self.Client:Alive() and action == "spawn") then
    		return {text = "You will be respawned shortly.", percentage = percentage, flash = percentage < 10};
    	end;
    	
    	if (!self.Client:IsRagdolled()) then
    		if (action == "lock") then
    			return {text = "The entity is being locked.", percentage = percentage, flash = percentage < 10};
    		elseif (action == "unlock") then
    			return {text = "The entity is being unlocked.", percentage = percentage, flash = percentage < 10};
    		end;
    	elseif (action == "unragdoll") then
    		if (self.Client:GetRagdollState() == RAGDOLL_FALLENOVER) then
    			return {text = "You are regaining stability.", percentage = percentage, flash = percentage < 10};
    		else
    			return {text = "You are regaining conciousness.", percentage = percentage, flash = percentage < 10};
    		end;
    	elseif (self.Client:GetRagdollState() == RAGDOLL_FALLENOVER) then
    		local fallenOver = self.Client:GetSharedVar("FallenOver");
    		
    		if (fallenOver and self.plugin:Call("PlayerCanGetUp")) then
    			return {text = "Press 'jump' to get up.", percentage = 100};
    		end;
    	end;
    end;
    Now take a look at this:
    Code:
    Clockwork.player:SetAction(player, action, duration, priority, Callback)
    player is the player whose action needs to be set.
    action is the name of the action
    duration is how long the action lasts
    priority is the priority of the action, it's a number. It determines if the old action can be overridden.
    Callback is the function ran when the action ends.

    Example Code:

    On the server, anywhere
    Code:
    Clockwork.player:SetAction(player, "dinosaur", 10);
    Inside the hook
    Code:
    local action, percentage = self.player:GetAction(self.Client, true);
    
    if (!self.Client:Alive() and action == "dinosaur") then
    	return {text = "Your character is walking the dinosaur.", percentage = percentage, flash = percentage < 10};
    end;
    A little overview on GetAction.
    Code:
    Clockwork.player:GetAction(player, percentage)
    player is the player whose action should be retrieved.
    percentage is a boolean (true, false) value, if true, it will return the action name and the percentage of the current action. If false, it will return the action name, the duration of the action, and when the action started.

    Explaining the hook:
    The hook must return a table at all times, Clockwork will then build a progressbar based on the table.
    It usually contains the text, the percentage, and if the progressbar should flash. (In this case "percentage < 10", will be replaced by true if percentage is less than 10, otherwise it's false.)
    I've never seen the progressbar actually flashing, but the way the code seems to be, it should start flashing white.

    It is also possible to specify a color, so that the progressbar has a different color than the standard one.

    Code:
    return {text = "Red Colored Progressbar", percentage = percentage, flash = false, color = Color(255, 0, 0, 255)}
     
  8. Polis

    Polis Guest

    Thanks a lot Kurochi, very helpful stuff. :)
     

Previous Readers (Total: 0)