Page 2 of 2 First 12

Thread: Help with code

  1. #11
    yako2020's Avatar
    Join Date
    Sep 2012
    Location
    São Carlos, São Paulo - Brazil
    Posts
    998
    Problem solved, some returns were wrong, now the effects are working.
    [FGC AND FGU ULTIMATE LICENSE HOLDER][BRAZILIAN][GMT-3]
    [D&D 5 PLAYER][CALL OF CTHULHU PLAYER][SAVAGE WORLDS PLAYER][GURPS PLAYER AND LOVER]
    [FANTASY GROUNDS STREAMER ON TWITCH]


  2. #12
    yako2020's Avatar
    Join Date
    Sep 2012
    Location
    São Carlos, São Paulo - Brazil
    Posts
    998
    local of file ->ruleset\scripts\manager_effect2.lua
    name of file in base.xml -> <script name="EffectManager2" file="scripts/manager_effect2.lua" />


    Converts time units and countdown works perfectly.


    Code:
    function onInit()  EffectManager.registerEffectVar("nStatus", { sDBType = "number", sDBField = "status", bSkipAdd = false });
      EffectManager.registerEffectVar("sUnits", { sDBType = "string", sDBField = "units", bSkipAdd = false });
      
      EffectManager.setCustomOnEffectAddStart(onEffectAddStart);
    
    
      EffectManager.setCustomOnEffectStartTurn(onEffectStartTurn);
      EffectManager.setCustomOnEffectEndTurn(onEffectEndTurn);
    
    
      EffectManager.setCustomOnEffectActorStartTurn(onEffectActorStartTurn);
      EffectManager.setCustomOnEffectActorEndTurn(onEffectActorEndTurn);
      
      EffectManager.setCustomOnEffectTextEncode(onEffectTextEncode);
      EffectManager.setCustomOnEffectTextDecode(onEffectTextDecode);
    end
    
    
    function onEffectAddStart(rEffect)
    	rEffect.nStatus = 0;    
    	rEffect.nDuration = rEffect.nDuration or 1;
    		if rEffect.sUnits == "min" then
    			rEffect.nDuration = rEffect.nDuration * 60;
    			rEffect.sUnits = "sec";
    			elseif rEffect.sUnits == "hr" then
    				rEffect.nDuration = rEffect.nDuration * 3600;
    				rEffect.sUnits = "sec";
    			elseif rEffect.sUnits == "day" then
    				rEffect.nDuration = rEffect.nDuration * 86400;
    				rEffect.sUnits = "sec";	
    
    
        
    		end
    			
    end
    
    
    function onEffectStartTurn(nodeActor, nodeEffect)
    	return false;
    end
    function onEffectEndTurn(nodeActor, nodeEffect)
    	return false;
    end
    
    
    function onEffectActorStartTurn(nodeActor, nodeEffect)
        DB.setValue(nodeEffect, "status", "number", 1);
    	return true;
    end
    
    
    function onEffectActorEndTurn(nodeActor, nodeEffect)
    	local nDuration = DB.getValue(nodeEffect, "duration", 0);
    	local sUnits = DB.getValue(nodeEffect, "units", "");
    	local nStatus = DB.getValue(nodeEffect, "status", 0);
    
    
    	-- Convert to seconds
    		if sUnits == "min" then
    			sUnits = "sec";
    			nDuration = nDuration * 60;
    			DB.setValue(nodeEffect, "units", "string", sUnits);
    			elseif sUnits == "hr" then
    				sUnits = "sec";
    				nDuration = nDuration * 3600;
    				DB.setValue(nodeEffect, "units", "string", sUnits);
    			elseif sUnits == "day" then
    				sUnits = "sec";
    				nDuration = nDuration * 86400;
    				DB.setValue(nodeEffect, "units", "string", sUnits);				
    		end
    
    
    			if sUnits == "sec" and nStatus == 1 then
    					nDuration = nDuration - 1;
    			end
    
    
    				if nDuration <= 0 and sUnits ~= "" and sUnits ~= "sec+" then
    					EffectManager.expireEffect(nodeActor, nodeEffect, 0);
    					else
    						DB.setValue(nodeEffect, "status", "number", 1);
    						DB.setValue(nodeEffect, "duration", "number", nDuration);
    				end
    end
    
    
    function onEffectTextEncode(rEffect)
    	local aMessage = {};
      
    		if rEffect.sUnits and rEffect.sUnits ~= "" then
    			local sOutputUnits = nil;
    			if rEffect.sUnits == "sec" then
    					sOutputUnits = "SEC";
    				elseif rEffect.sUnits == "min" then
    					sOutputUnits = "MIN";
    				elseif rEffect.sUnits == "hr" then
    					sOutputUnits = "HR";
    				elseif rEffect.sUnits == "day" then
    					sOutputUnits = "DAY";
    		end
    
    
    				if sOutputUnits then
    					table.insert(aMessage, "[UNITS " .. sOutputUnits .. "]");
    				end
    			end
      
    return table.concat(aMessage, " ");
    end
    
    
    function onEffectTextDecode(sEffect, rEffect)
    	local s = sEffect;
      
    	local sUnits = s:match("%[UNITS ([^]]+)]");
    		if sUnits then
    			s = s:gsub("%[UNITS ([^]]+)]", "");
    			if sUnits == "SEC" then
    					rEffect.sUnits = "sec";
    				elseif sUnits == "MIN" then
    					rEffect.sUnits = "min";
    				elseif sUnits == "HR" then
    					rEffect.sUnits = "hr";
    				elseif sUnits == "DAY" then
    					rEffect.sUnits = "day";
    		end
    			end
      
    		return s;
    end
    [FGC AND FGU ULTIMATE LICENSE HOLDER][BRAZILIAN][GMT-3]
    [D&D 5 PLAYER][CALL OF CTHULHU PLAYER][SAVAGE WORLDS PLAYER][GURPS PLAYER AND LOVER]
    [FANTASY GROUNDS STREAMER ON TWITCH]


  3. #13
    yako2020's Avatar
    Join Date
    Sep 2012
    Location
    São Carlos, São Paulo - Brazil
    Posts
    998
    local of file ->ruleset\scripts\manager_effect2.lua
    name of file in base.xml -> <script name="EffectManager2" file="scripts/manager_effect2.lua" />


    Practically the same as the previous code but with an increment in the count.

    Code:
    function onInit()  EffectManager.registerEffectVar("nStatus", { sDBType = "number", sDBField = "status", bSkipAdd = false });
      EffectManager.registerEffectVar("sUnits", { sDBType = "string", sDBField = "units", bSkipAdd = false });
      
      EffectManager.setCustomOnEffectAddStart(onEffectAddStart);
    
    
      EffectManager.setCustomOnEffectStartTurn(onEffectStartTurn);
      EffectManager.setCustomOnEffectEndTurn(onEffectEndTurn);
    
    
      EffectManager.setCustomOnEffectActorStartTurn(onEffectActorStartTurn);
      EffectManager.setCustomOnEffectActorEndTurn(onEffectActorEndTurn);
      
      EffectManager.setCustomOnEffectTextEncode(onEffectTextEncode);
      EffectManager.setCustomOnEffectTextDecode(onEffectTextDecode);
    end
    
    
    function onEffectAddStart(rEffect)
    	rEffect.nStatus = 0;    
    	rEffect.nDuration = rEffect.nDuration or 1;
    		if rEffect.sUnits == "min" then
    			rEffect.nDuration = rEffect.nDuration * 60;
    			rEffect.sUnits = "sec";
    			elseif rEffect.sUnits == "hr" then
    				rEffect.nDuration = rEffect.nDuration * 3600;
    				rEffect.sUnits = "sec";
    			elseif rEffect.sUnits == "day" then
    				rEffect.nDuration = rEffect.nDuration * 86400;
    				rEffect.sUnits = "sec";	
    				if rEffect.sUnits ~= "sec" and rEffect.nStatus ~= "0" then 
    					rEffect.sUnits = "sec+"
    					rEffect.nStatus = 1;
        
    		end
    				end
    end
    
    
    function onEffectStartTurn(nodeActor, nodeEffect)
      return true;
    end
    function onEffectEndTurn(nodeActor, nodeEffect)
      return false;
    end
    
    
    function onEffectActorStartTurn(nodeActor, nodeEffect)
        DB.setValue(nodeEffect, "status", "number", 1);
    	return true;
    end
    
    
    function onEffectActorEndTurn(nodeActor, nodeEffect)
    	local nDuration = DB.getValue(nodeEffect, "duration", 0);
    	local sUnits = DB.getValue(nodeEffect, "units", "");
    	local nStatus = DB.getValue(nodeEffect, "status", 0);
    
    
    	-- Convert to seconds
    		if sUnits == "min" then
    			sUnits = "sec";
    			nDuration = nDuration * 60;
    			DB.setValue(nodeEffect, "units", "string", sUnits);
    			elseif sUnits == "hr" then
    				sUnits = "sec";
    				nDuration = nDuration * 3600;
    				DB.setValue(nodeEffect, "units", "string", sUnits);
    			elseif sUnits == "day" then
    				sUnits = "sec";
    				nDuration = nDuration * 86400;
    				DB.setValue(nodeEffect, "units", "string", sUnits);				
    		end
    
    
    			if sUnits == "sec+" then
    				nDuration = nDuration + 1;
    				elseif sUnits == "sec" and nStatus == 1 then
    					nDuration = nDuration - 1;
    			end
    
    
    				if nDuration <= 0 and sUnits ~= "" and sUnits ~= "sec+" then
    					EffectManager.expireEffect(nodeActor, nodeEffect, 0);
    					else
    						DB.setValue(nodeEffect, "status", "number", 1);
    						DB.setValue(nodeEffect, "duration", "number", nDuration);
    				end
    				
    				return true;
    end
    
    
    function onEffectTextEncode(rEffect)
    	local aMessage = {};
      
    		if rEffect.sUnits and rEffect.sUnits ~= "" then
    			local sOutputUnits = nil;
    			if rEffect.sUnits == "sec+" then
    				sOutputUnits = "SEC+";
    				elseif rEffect.sUnits == "sec" then
    					sOutputUnits = "SEC";
    				elseif rEffect.sUnits == "min" then
    					sOutputUnits = "MIN";
    				elseif rEffect.sUnits == "hr" then
    					sOutputUnits = "HR";
    				elseif rEffect.sUnits == "day" then
    					sOutputUnits = "DAY";
    		end
    
    
    				if sOutputUnits then
    					table.insert(aMessage, "[UNITS " .. sOutputUnits .. "]");
    				end
    			end
      
    return table.concat(aMessage, " ");
    end
    
    
    function onEffectTextDecode(sEffect, rEffect)
    	local s = sEffect;
      
    	local sUnits = s:match("%[UNITS ([^]]+)]");
    		if sUnits then
    			s = s:gsub("%[UNITS ([^]]+)]", "");
    			if sUnits == "SEC+" then
    				rEffect.sUnits = "sec+";
    				elseif sUnits == "SEC" then
    					rEffect.sUnits = "sec";
    				elseif sUnits == "MIN" then
    					rEffect.sUnits = "min";
    				elseif sUnits == "HR" then
    					rEffect.sUnits = "hr";
    				elseif sUnits == "DAY" then
    					rEffect.sUnits = "day";
    		end
    			end
      
    		return s;
    end
    [FGC AND FGU ULTIMATE LICENSE HOLDER][BRAZILIAN][GMT-3]
    [D&D 5 PLAYER][CALL OF CTHULHU PLAYER][SAVAGE WORLDS PLAYER][GURPS PLAYER AND LOVER]
    [FANTASY GROUNDS STREAMER ON TWITCH]


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Log in

Log in