Jump to content
Rinor

Respawn on the same map

Recommended Posts

Hello everyone, im having an issue with the auto respawn in the same map, example “Capture the Flag”

I’m using the function at functions.lua:

CUSTOM_RETURN_POINTS         = {
                ['puzzleworld']            = 'Sacred Snow Mountain',
                ['puzzleworld2']        = 'Sacred Snow Mountain',
                ['garner2']        = 'Chaos Portal',
            }
            
            function GetChaRespawnPoint(Player, mapname)
                local ret                 = ""
                for i,v in pairs(CUSTOM_RETURN_POINTS) do
                    if(i == mapname) then
        if mapname == "puzzleworld" or  mapname == "puzzleworld2" then
            ReAll(Player)
        end
                        ret             = v
                    end
                end
                local SideID                = GetChaSideID(Player)
                if (mapname == "ctf") then
                    if (SideID == 1) then
                        return CTF.Spawns[2].Spawn
                    elseif (SideID == 2) then
                        return CTF.Spawns[1].Spawn
                    end
                end
                return ret
            end

 

And this is the code at sources inside void CCharacter::BackToCity

if (g_CParser.DoString("GetChaRespawnPoint", enumSCRIPT_RETURN_STRING, 1, enumSCRIPT_PARAM_LIGHTUSERDATA, 1, pCMainCha, DOSTRING_PARAM_END))
		szCityName = g_CParser.GetReturnString(0);

	if (!szCityName || !strcmp(szCityName, ""))
		pCMainCha->ResetBirthInfo();
	else
	{
		SBirthPoint	*pSBirthP;
		pSBirthP = GetRandBirthPoint(GetLogName(), szCityName);
		SetBirthMap(pSBirthP->szMapName);
		SetPos(pSBirthP->x * 100, pSBirthP->y * 100);
	}
	pCMainCha->SwitchMap(pCMap, pCMainCha->GetBirthMap(), pCMainCha->GetPos().x, pCMainCha->GetPos().y, false, chSwitchType, lMapCpyNO);
}

 

im still being respawned to argent city when i’m dying instead of being Respawned into CTF

Share this post


Link to post
Share on other sites

Hello @Rinor!

 

1) Is the name of the CTF map correct in the script? Does this condition work?

if (mapname == "ctf") then

Note, that "CTF" and "ctf" are different strings and not equal (case sensitive comparison).

 

2) Are CTF.Spawns [2] .Spawn and CTF.Spawns[1].Spawn variables defined in this script?

 

To answer these questions, write several debug lines:

   	 . . . 

	local SideID = GetChaSideID(Player)
	
	print(mapname)
	print(CTF.Spawns[1].Spawn)
	print(CTF.Spawns[2].Spawn)
      
	 . . . 

You will see output in GameServer.exe window.

 

 


Share this post


Link to post
Share on other sites

GetChaRespawnPoint is declared to return a String, and takes only 1 argument which is a pointer to the main character, you're not passing the second param at all


also why this approach? I'd go with the current declaration you only need a pointer to the player


1- Get char's current map if the map is "CTF" continue parsing else return
2-  get the side  (you already did)
3- respawn the character on the correct side.

 

so I'd do the following:

	g_CParser.DoString("GetChaRespawnPoint", enumSCRIPT_RETURN_STRING, 1, enumSCRIPT_PARAM_LIGHTUSERDATA, 1, pCMainCha, DOSTRING_PARAM_END)

	szSpawn = g_CParser.GetReturnString(0);
	if (!strcmp(szSpawn, "")) // you should return an empty string to indicate normal flow, i.e execute the default action for spawning/re-spawning
	{
		pSBirthP = GetRandBirthPoint(GetLogName(), szSpawn); // get coords from birth_conf
		pCMainCha->SwitchMap(pCMap, szSpawn, pSBirthP->x * 100,pSBirthP->y * 100, false, chSwitchType, lMapCpyNO); // coords multiplied by 100 if you're using arbitrary coords i.e coords drawn on the GUI "Map Interface", and it is the case for all maps saved in "birth\birth_conf.lua"
		return; // we're done, exit the function
	} 
	else
	{
		if (!szCityName || !strcmp(szCityName, ""))
			pCMainCha->ResetBirthInfo();
		else
		{
			SBirthPoint	*pSBirthP;
			pSBirthP = GetRandBirthPoint(GetLogName(), szCityName);
			SetBirthMap(pSBirthP->szMapName);
			SetPos(pSBirthP->x * 100, pSBirthP->y * 100);
		}
		pCMainCha->SwitchMap(pCMap, pCMainCha->GetBirthMap(), pCMainCha->GetPos().x, pCMainCha->GetPos().y, false, chSwitchType, lMapCpyNO);
	}
function GetChaRespawnPoint(Player)
	local ret = ""
    if GetChaMapName(Player) == "CTF" then
	    local SideID = GetChaSideID(Player)
	        if (SideID == 1) then
	            ret =  CTF.Spawns[2].Spawn -- I'd assume that those are defined in your current lua file which lead to similiar declarations in your birth_conf.lua
	        else
	            ret = CTF.Spawns[1].Spawn
	        end
    return ret
end

 

  • Thanks 1

Kind regards, AG.

Share this post


Link to post
Share on other sites
On 11/16/2021 at 5:23 PM, J0k3r said:

GetChaRespawnPoint is declared to return a String, and takes only 1 argument which is a pointer to the main character, you're not passing the second param at all


also why this approach? I'd go with the current declaration you only need a pointer to the player


1- Get char's current map if the map is "CTF" continue parsing else return
2-  get the side  (you already did)
3- respawn the character on the correct side.

 

so I'd do the following:


	g_CParser.DoString("GetChaRespawnPoint", enumSCRIPT_RETURN_STRING, 1, enumSCRIPT_PARAM_LIGHTUSERDATA, 1, pCMainCha, DOSTRING_PARAM_END)

	szSpawn = g_CParser.GetReturnString(0);
	if (!strcmp(szSpawn, "")) // you should return an empty string to indicate normal flow, i.e execute the default action for spawning/re-spawning
	{
		pSBirthP = GetRandBirthPoint(GetLogName(), szSpawn); // get coords from birth_conf
		pCMainCha->SwitchMap(pCMap, szSpawn, pSBirthP->x * 100,pSBirthP->y * 100, false, chSwitchType, lMapCpyNO); // coords multiplied by 100 if you're using arbitrary coords i.e coords drawn on the GUI "Map Interface", and it is the case for all maps saved in "birth\birth_conf.lua"
		return; // we're done, exit the function
	} 
	else
	{
		if (!szCityName || !strcmp(szCityName, ""))
			pCMainCha->ResetBirthInfo();
		else
		{
			SBirthPoint	*pSBirthP;
			pSBirthP = GetRandBirthPoint(GetLogName(), szCityName);
			SetBirthMap(pSBirthP->szMapName);
			SetPos(pSBirthP->x * 100, pSBirthP->y * 100);
		}
		pCMainCha->SwitchMap(pCMap, pCMainCha->GetBirthMap(), pCMainCha->GetPos().x, pCMainCha->GetPos().y, false, chSwitchType, lMapCpyNO);
	}

function GetChaRespawnPoint(Player)
	local ret = ""
    if GetChaMapName(Player) == "CTF" then
	    local SideID = GetChaSideID(Player)
	        if (SideID == 1) then
	            ret =  CTF.Spawns[2].Spawn -- I'd assume that those are defined in your current lua file which lead to similiar declarations in your birth_conf.lua
	        else
	            ret = CTF.Spawns[1].Spawn
	        end
    return ret
end

 

Hey @J0k3r thanks for the reply and sorry for my late reply, i did tried what you sent and is missing something as the code is different.

https://imgur.com/a/vLhOqJk

Share this post


Link to post
Share on other sites

Hello @Rinor!

 

Try to replace

szSpawn = g_CParser.GetReturnString(0);

to 

const char* szSpawn = g_CParser.GetReturnString(0);

 

  • Thanks 1

Share this post


Link to post
Share on other sites
6 hours ago, J0k3r said:

SBirthPoint *pSBirthP; is declared below in your code, just lift it up before the assignment of "pSBirthP"

I’ve done it already after the last reply by @V3ct0r but i was having problems inside the CTF map, after dying it was Disconnecting the character instead of respawning inside the map, DC happened after clicking Revive button.

Share this post


Link to post
Share on other sites
On 1/2/2022 at 2:41 PM, Rinor said:

I’ve done it already after the last reply by @V3ct0r but i was having problems inside the CTF map, after dying it was Disconnecting the character instead of respawning inside the map, DC happened after clicking Revive button.

Make sure that your lua script (function GetChaRespawnPoint) returns the correct name of birth point.


Share this post


Link to post
Share on other sites
On 1/3/2022 at 2:01 PM, V3ct0r said:

Make sure that your lua script (function GetChaRespawnPoint) returns the correct name of birth point.

Just checked and tested its same issue, it results on disconnect when clicking revive button, maybe something wrong in the src code? @J0k3r

Share this post


Link to post
Share on other sites
On 1/3/2022 at 2:01 PM, V3ct0r said:

Make sure that your lua script (function GetChaRespawnPoint) returns the correct name of birth point.

I tried this both ways:

--[[
-- Required functions.
function GetChaRespawnPoint(Player)
	local ret = ""
    if GetChaMapName(Player) == "CTF" then
	    local SideID = GetChaSideID(Player)
	        if (SideID == 1) then
	            ret =  CTF.Spawns[2].Spawn -- I'd assume that those are defined in your current lua file which lead to similiar declarations in your birth_conf.lua
	        else
	            ret = CTF.Spawns[1].Spawn
	        end
    return ret
end
end
]]--

-- Required functions.
function GetChaRespawnPoint(role)
    local map_name = GetChaMapName(role)
    if (map_name == "ctf") then
        local side_id = GetChaSideID(role)
        if (side_id == 1) then
			return "CTF Green Team"
		elseif (side_id == 2) then
			return "CTF Red Team"
    end
end
    return ""
end

this is on functions file (is a file inside map files):

-- Call that on "birth.lua"
CTF.CreateSpawn = function()
	for a = 1, (table.getn(CTF.Spawns)), 1 do
		AddBirthPoint(CTF.Spawns[a].Name, CTF.Spawns[a].Map, CTF.Spawns[a].X, CTF.Spawns[a].Y)
		AddBirthPoint(CTF.Spawns[a].Spawn, CTF.Spawns[a].Map, CTF.Spawns[a].X, CTF.Spawns[a].Y)
	end
end

this is birth_config:

CTF.CreateSpawn()

and this is configuration.lua (is a file inside map files):

	-- You can edit this if you are using a different map than the one that came with the files and modify the coordinates if you want different spawns.
	-- This also affects in the code if you aren't using the random spawn function.
	CTF.Spawns[1] = {Name = CTF.Conf.MapName, Map = "ctf", Spawn = "CTF Red Team", X = 43, Y = 243}
	CTF.Spawns[2] = {Name = CTF.Conf.MapName, Map = "ctf", Spawn = "CTF Green Team", X = 241, Y = 44}

 

Edited by Rinor

Share this post


Link to post
Share on other sites

@Rinor is CTF.Conf.MapName defined some where else? I can't see it in the code you provided.
also in your loop you're not being consistent 

line

CTF.Spawns[a].Name?

then 

CTF.Spawns[a].Spawn 

 you're aware that in this loop u're adding each spawn 2 times, why? get rid of this line.

AddBirthPoint(CTF.Spawns[a].Name, CTF.Spawns[a].Map, CTF.Spawns[a].X, CTF.Spawns[a].Y)

unless you're using this field, some where else you don't need it.

Name = CTF.Conf.MapName

 


Kind regards, AG.

Share this post


Link to post
Share on other sites
On 1/9/2022 at 11:20 PM, Rinor said:

--[[ -- Required functions. function GetChaRespawnPoint(Player) local ret = "" if GetChaMapName(Player) == "CTF" then local SideID = GetChaSideID(Player) if (SideID == 1) then ret = CTF.Spawns[2].Spawn -- I'd assume that those are defined in your current lua file which lead to similiar declarations in your birth_conf.lua else ret = CTF.Spawns[1].Spawn end return ret end end ]]-- -- Required functions. function GetChaRespawnPoint(role) local map_name = GetChaMapName(role) if (map_name == "ctf") then local side_id = GetChaSideID(role) if (side_id == 1) then return "CTF Green Team" elseif (side_id == 2) then return "CTF Red Team" end end return "" end

some thing else is that, upper case "CTF" is NOT equal to lower case "ctf".


Kind regards, AG.

Share this post


Link to post
Share on other sites
On 1/21/2022 at 11:16 PM, J0k3r said:

@Rinor is CTF.Conf.MapName defined some where else? I can't see it in the code you provided.
also in your loop you're not being consistent 

line


CTF.Spawns[a].Name?

then 


CTF.Spawns[a].Spawn 

 you're aware that in this loop u're adding each spawn 2 times, why? get rid of this line.


AddBirthPoint(CTF.Spawns[a].Name, CTF.Spawns[a].Map, CTF.Spawns[a].X, CTF.Spawns[a].Y)

unless you're using this field, some where else you don't need it.


Name = CTF.Conf.MapName

 

this is loaded inside birth_config.lua:
CTF.CreateSpawn()

this is loaded from Configuration.lua inside map folder

	CTF.Conf.MapName 			= "Capture The Flag"		-- This is the overall map name, also displayed in notices/messages.
	CTF.Conf.NumMapCopy 		= 1							-- Number of map copies available, you must either edit ctrl.lua (v1.X) or MapCopyNum.txt (v2.X) to the same number.
	CTF.Conf.NumPlayer 			= 2						-- Number of players needed in lobby to start battle (by default: 50).
	CTF.Conf.MinLv 				= 45							-- Set a minimum level to be able to register.
	CTF.Conf.MaxLv 				= 100						-- Set a maximum level to be able to register.
	CTF.Conf.ServerLv			= 100						-- Set the max level available in server, this is needed for EXP rewards.
	CTF.Conf.ServerVersion 		= 1							-- This is your server's version (v1.X = 1, v2.X = 2). If your server is v1.x and you put 1, it will automatically create the copies. If your server version is v2.x, put 2 and you have to manually adjust MapCopyNum.txt.
	CTF.Conf.MapType 			= 17						-- This is your map type, it should be different from any other maps you may have, be sure to check your maps or "is_friend" function to avoid duplicates.

	CTF.Conf.Flag				= {ID = 75, Pos_X = 150, Pos_Y = 150, State = 199}
	
	CTF.Conf.FlagZone[1] 		= {245, 53}					-- Coordinates of green team flag zone. 							
	CTF.Conf.FlagZone[2] 		= {48, 246}					-- Coordinates of red team flag zone.								
	
	CTF.Conf.ScorePlayer		= 1							-- Amount of points team will get after killing a enemy (by default: 1).
	CTF.Conf.ChanceScore		= .25						-- Percentage to player get points after killing a enemy (by default: 25%).
	
	CTF.Conf.ScoreBase			= 1							-- Amount of points team will get after carries the flag to theirs base.
	CTF.Conf.ScoreEnemy			= 2							-- Amount of points team will get after carries the flag to enemy base.
	
	CTF.Conf.ScoreLimit			= 5							-- Minimum points the team needs to win battle (by default: 100).
	
	CTF.Conf.Time.Lobby 		= 300						-- Overall time to battle start if minimum player number in lobby did not reached (by default : 5 min).
	CTF.Conf.Time.Attempt 		= 120						-- Time in seconds that player have to return match if DC (by default: 2 min).	
	CTF.Conf.Time.Map 			= 1200						-- Overall time duration of the battle (by default: 20 min).
	CTF.Conf.Time.Refresh 		= 180						-- Time (in seconds) to announce round and team score in system (by default: 3 min).
	CTF.Conf.Time.Close 		= 20						-- Time (in seconds) to close map when battle ends (by default: 20 sec).
	CTF.Conf.Time.StartShow		= {1,2,3,4,5,6,7,8,9,10,20,30,45,60,120,180,240,280}
	
	CTF.Conf.OpenDay			= {0,1,2,3,4,5,6}			-- Set the days available to register for CTF (by default: all day).	
	CTF.Conf.OpenHour			= {16,17}	-- Set the hours available to register for CTF (by default: 17:00).
	CTF.Conf.CloseMin			= 37							-- That minute which where registration will be available, after that it will be closed.
	
	
	-- Balance for classes in map (Gems and equipment will make no difference).
	CTF.Conf.Balance[8] 		= {Max = {HP = 5570, SP = 155}, Attack = {Min = 332, Max = 428, Speed = 72}, Defense = 292, PhysicalResist = 28, HitRate = 146, Dodge = 142, Critical = 15, Recovery = {HP = 56, SP = 2}, MoveSpeed = 480}	
	CTF.Conf.Balance[9] 		= {Max = {HP = 2858, SP = 155}, Attack = {Min = 352, Max = 387, Speed = 100}, Defense = 125, PhysicalResist = 25, HitRate = 151, Dodge = 181, Critical = 15, Recovery = {HP = 31, SP = 3}, MoveSpeed = 480}	
	CTF.Conf.Balance[12] 		= {Max = {HP = 2811, SP = 155}, Attack = {Min = 398, Max = 525, Speed = 100}, Defense = 105, PhysicalResist = 25, HitRate = 185, Dodge = 161, Critical = 15, Recovery = {HP = 34, SP = 1}, MoveSpeed = 480}
	CTF.Conf.Balance[13] 		= {Max = {HP = 2953, SP = 1700}, Attack = {Min = 168, Max = 234, Speed = 72}, Defense = 118, PhysicalResist = 24, HitRate = 154, Dodge = 148, Critical = 15, Recovery = {HP = 42, SP = 19}, MoveSpeed = 480}
	CTF.Conf.Balance[14] 		= {Max = {HP = 3652, SP = 1341}, Attack = {Min = 168, Max = 234, Speed = 72}, Defense = 137, PhysicalResist = 24, HitRate = 154, Dodge = 147, Critical = 15, Recovery = {HP = 55, SP = 15}, MoveSpeed = 480}
	CTF.Conf.Balance[16] 		= {Max = {HP = 3707, SP = 1307}, Attack = {Min = 162, Max = 215, Speed = 77}, Defense = 139, PhysicalResist = 24, HitRate = 146, Dodge = 147, Critical = 15, Recovery = {HP = 52, SP = 16}, MoveSpeed = 480}
						
	-- This are the rewards given at the end of the match to the green team
	-- If values are set to "0", if will not prompt to give out that reward, including items.
	-- For "EXP", it's in percentage of player's current level.	
	CTF.Rewards.Reputation		= 0
	CTF.Rewards.Gold			= 20000
	CTF.Rewards.Honor			= 0
	CTF.Rewards.EXP				= 0
	CTF.Rewards.Items[1]		= {ID = 5707, Quantity = 1, Quality = 4} 	-- The Universe Purse
	CTF.Rewards.Items[2]		= {ID = 0938, Quantity = 1, Quality = 4}	-- Goddess's Favor
	CTF.Rewards.Items[3]		= {ID = 3095, Quantity = 1, Quality = 4}	-- Hi-Amplifier of Strive
	CTF.Rewards.Items[4]		= {ID = 3097, Quantity = 1, Quality = 4}	-- Hi-Amplifier of Luck
	CTF.Rewards.Items[5]		= {ID = 0854, Quantity = 1, Quality = 4}	-- Million Dollar Note
	CTF.Rewards.Items[6]		= {ID = 5750, Quantity = 1, Quality = 101}	-- Yellow Jade
	CTF.Rewards.Items[7]		= {ID = 5751, Quantity = 1, Quality = 101}	-- Red Jade
	CTF.Rewards.Items[8]		= {ID = 5752, Quantity = 1, Quality = 101}	-- Green Jade
	
	-- You can edit this if you are using a different map than the one that came with the files and modify the coordinates if you want different spawns.
	-- This also affects in the code if you aren't using the random spawn function.
	CTF.Spawns[1] = {Name = CTF.Conf.MapName, Map = "ctf", Spawn = "CTF Red Team", X = 43, Y = 243}
	CTF.Spawns[2] = {Name = CTF.Conf.MapName, Map = "ctf", Spawn = "CTF Green Team", X = 241, Y = 44}

 
and this is function.lua which is inside map folder:
 

-- DO NOT EDIT THIS, PERIOD.
if CTF == nil then
	CTF 											= {}
	CTF.Conf 										= {}
	CTF.Conf.Time 									= {}	
	CTF.Conf.FlagZone								= {}
	CTF.Conf.Balance								= {}
	
	CTF.Spawns 										= {}
	CTF.Rewards										= {}
	CTF.Rewards.Items								= {}
end
-- Calling those customizable variables.
dofile(GetResPath("ctf/Configuration.lua"))

function CTF.Init()
	CTF.Members										= {}
	CTF.Flag										= {}
	CTF.EnterLobby									= {} 					-- Stores the data to players if they entered the Lobby.
	CTF.LeaveTime									= {} 					-- Stores the time players have to enter map again after leave the battle.	
	CTF.Lobby_Tick									= CTF.Conf.Time.Lobby	-- Lobby wait time before battle start if minimum player not reached.
	CTF.LobbyOpened									= false					-- Declares if the lobby is opened or not.
	CTF.MapOpened									= false					-- Declares if the battle has started or not.
end
CTF.Init()
--[[
-- Required functions.
function GetChaRespawnPoint(Player)
	local ret = ""
    if GetChaMapName(Player) == "CTF" then
	    local SideID = GetChaSideID(Player)
	        if (SideID == 1) then
	            ret =  CTF.Spawns[2].Spawn -- I'd assume that those are defined in your current lua file which lead to similiar declarations in your birth_conf.lua
	        else
	            ret = CTF.Spawns[1].Spawn
	        end
    return ret
end
end
]]
--Required functions.
function GetChaRespawnPoint(role)
    local map_name = GetChaMapName(role)
    if (map_name == "ctf") then
        local side_id = GetChaSideID(role)
        if (side_id == 1) then
			return "CTF Red Team"
		elseif (side_id == 2) then
			return "CTF Green Team"
    end
end
    return ""
end

AdjustTextSpace = AdjustTextSpace or function(Text, Spaces, End)
	local Count = math.floor((Spaces - string.len(Text)) * 0.5)
	local Message = ""
	for C = 1, Count, 1 do
		Message = Message.." "
	end
	Message = Message..Text
	Count = math.floor(Spaces - string.len(Message))
	for C = 1, Count, 1 do
		Message = Message.." "
	end
	if End ~= nil then
		Message = Message..End
	end
	return Message
end	
function StartPlayerCTF(Player)
	local TeamID									= 0
	local PID										= GetPlayerID(GetChaPlayer(Player))
	if (CTF.Players[PID] == nil) then
		if (CTF.GreenTeam.Counter == CTF.RedTeam.Counter) then
			TeamID									= math.random(1,2)
		else
			if (CTF.GreenTeam.Counter > CTF.RedTeam.Counter) then
				TeamID								= 1
			else
				TeamID								= 2
			end
		end
		CTF.Players[PID]							= { cha 		= Player,
														side_id 	= TeamID,
														entered 	= LUA_FALSE }
	else
		CTF.Players[PID].cha						= Player
		CTF.Players[PID].side_id					= CTF.Players[PID].side_id
		CTF.Players[PID].entered					= LUA_FALSE
		TeamID										= CTF.Players[PID].side_id
	end
	if (TeamID == 1) then
		CTF.RedTeam.Counter						= CTF.RedTeam.Counter + 1
		MoveCity(Player, CTF.Spawns[TeamID].Spawn)
	else
		CTF.GreenTeam.Counter						= CTF.GreenTeam.Counter + 1
		MoveCity(Player, CTF.Spawns[TeamID].Spawn)
	end
end
-- Carry the flag to enemy team
function CarryTheFlag(Player)
	local MapCopy									= GetChaMapCopy(Player)
	local PID										= GetRoleID(Player)
	local Name										= GetChaDefaultName(Player)
	local side_id 									= GetChaSideID(Player)
	local x,y 										= GetChaPos(Player)
	x												= math.floor(x/100)
	y												= math.floor(y/100)
	local red_base									= 4 * math.abs(x - CTF.Conf.FlagZone[2][1]) + 4 * math.abs(y - CTF.Conf.FlagZone[2][2])
	local green_base								= 4 * math.abs(x - CTF.Conf.FlagZone[1][1]) + 4 * math.abs(y - CTF.Conf.FlagZone[1][2])
	if (red_base <= 12) then
		if (side_id == 1) then
			CTF.Flag_ChaID							= 0
			CTF.GreenTeam.Score						= CTF.GreenTeam.Score + CTF.Conf.ScoreEnemy
			RemoveState(Player, CTF.Conf.Flag.State)
			MapCopyNotice(MapCopy, "["..CTF.Conf.MapName.."]: "..Name..", from the Green Team succesfully carried the flag to Red Team Base and gets +"..CTF.Conf.ScoreEnemy.." points!")
		end
	end
	
	if (green_base <= 12) then
		if (side_id == 2) then
			CTF.Flag_ChaID							= 0
			CTF.RedTeam.Score						= CTF.RedTeam.Score + CTF.Conf.ScoreEnemy
			RemoveState(Player, CTF.Conf.Flag.State)
			MapCopyNotice(MapCopy, "["..CTF.Conf.MapName.."]: "..Name..", from the Red Team succesfully carried the flag to Green Team Base and gets +"..CTF.Conf.ScoreEnemy.." point!")
		end
	end	
	
	--[[if (red_base <= 12 or green_base <= 12) then
		CTF.Flag_ChaID								= 0
		RemoveState(Player, CTF.Conf.Flag.State)
	end--]]
end

-- Calculating custom balance for classes in map.
CTF.MapBalance										= function(Player)
	if (GetChaMapName(Player) == "ctf") then
		local Job 									= GetChaAttr(Player, ATTR_JOB)
		if (CTF.Conf.Balance[Job] ~= nil) then
			local mf_final 							= Mf_final(Player)	
			local crt_final 						= Crt_final(Player)
			local hrec_final 						= Hrec_final(Player)
			local srec_final 						= Srec_final(Player)
			local adis_final 						= Adis_final(Player)
			SetCharaAttr(CTF.Conf.Balance[Job].Max.HP, Player, ATTR_MXHP)
			SetCharaAttr(CTF.Conf.Balance[Job].Max.SP, Player, ATTR_MXSP)
			SetCharaAttr(CTF.Conf.Balance[Job].Attack.Min, Player, ATTR_MNATK)
			SetCharaAttr(CTF.Conf.Balance[Job].Attack.Max, Player, ATTR_MXATK)
			SetCharaAttr(CTF.Conf.Balance[Job].Defense, Player, ATTR_DEF)
			SetCharaAttr(CTF.Conf.Balance[Job].PhysicalResist, Player, ATTR_PDEF) 
			SetCharaAttr(CTF.Conf.Balance[Job].HitRate, Player, ATTR_HIT)
			SetCharaAttr(CTF.Conf.Balance[Job].Dodge, Player, ATTR_FLEE)
			SetCharaAttr(mf_final, Player, ATTR_MF)
			SetCharaAttr(crt_final, Player, ATTR_CRT)
			SetCharaAttr(hrec_final, Player, ATTR_HREC)
			SetCharaAttr(srec_final, Player, ATTR_SREC)
			SetCharaAttr(adis_final, Player, ATTR_ADIS)
			SetCharaAttr(CTF.Conf.Balance[Job].MoveSpeed, Player, ATTR_MSPD)
			SetCharaAttr(100000/CTF.Conf.Balance[Job].Attack.Speed, Player, ATTR_ASPD)	
		end
	end
end

-- Checking if the player team is equal the function argument.
CTF.CheckChaSide									= function(Player, SideID)
	if (GetChaSideID(TurnToCha(Player)) == SideID) then
		return LUA_TRUE
	end
	return LUA_FALSE
end

-- Checking team score in map.
CTF.DisplayInfo										= function(Player)	
	local Message									= ""
	Message 										= AdjustTextSpace(">> Capture The Flag <<", 42, "_")
	Message 										= Message..AdjustTextSpace("Red Team Score: ", 16)..AdjustTextSpace(CTF.RedTeam.Score, 20, "_")
	Message 										= Message..AdjustTextSpace("Green Team Score: ", 16)..AdjustTextSpace(CTF.GreenTeam.Score, 16, "_")
	Message 										= Message..AdjustTextSpace("Battle ends in: ", 16)..AdjustTextSpace(toclock(CTF.BattleTime), 21, "_")
	HelpInfoX(Player, 0, Message)
	return LUA_TRUE
end

-- Call that on "is_friend" at functions.lua
CTF.Friendly										= function(ATKER, DEFER)
	local ATKER_Team								= GetChaSideID(ATKER)
	local DEFER_Team								= GetChaSideID(DEFER)
	if ATKER_Team == DEFER_Team then
		return 1
	else
		return 0
	end
end
-- Call that on "birth.lua"
CTF.CreateSpawn = function()
	for a = 1, (table.getn(CTF.Spawns)), 1 do
		AddBirthPoint(CTF.Spawns[a].Name, CTF.Spawns[a].Map, CTF.Spawns[a].X, CTF.Spawns[a].Y)
		AddBirthPoint(CTF.Spawns[a].Spawn, CTF.Spawns[a].Map, CTF.Spawns[a].X, CTF.Spawns[a].Y)
	end
end
CTF.StartMap 										= function()
	CTF.Players										= {}					-- Stores the data for players in battle.
	CTF.GreenTeam									= {}					-- Stores the data for the Green Team.
	CTF.RedTeam										= {}					-- Stores the data for the Red Team.
				
	CTF.GreenTeam.Counter 							= 0						-- Stores the number of players in Green Team.
	CTF.RedTeam.Counter 							= 0						-- Stores the number of players in Red Team.
			
	CTF.GreenTeam.Score 							= 0						-- Stores the score of the Red Team.
	CTF.RedTeam.Score  								= 0						-- Stores the score of the Green Team.
	
	CTF.BattleTime									= CTF.Conf.Time.Map		-- Stores the time of whole battle duration.

	CTF.MapOpened 									= true					-- Starts the battle.
	CTF.LobbyOpened									= false					-- Closes the lobby.
	
	CTF.WinnerTeam									= nil					-- Declares the team winner of battle.

	CTF.Flag_ChaID									= 0						-- Declares the player who carries the flag.
	CTF.Flag_Spawned								= 0						-- Declares if the flag has been spawned.
	
	CTF.MapShutdown									= CTF.Conf.Time.Close
end

function CTF.PKM(Mob, Player)
	local MobMap									= GetChaMapName(Mob)
	local MapName									= GetChaMapName(Player)
	local ChaName									= GetChaDefaultName(Player)
	local ChaID										= GetRoleID(Player)
	if (MapName == "ctf" and MobMap == "ctf") then
		local MobID									= GetChaTypeID(Mob)
		if (MobID == CTF.Conf.Flag.ID) then
			local SideID							= GetChaSideID(Player)
			local MapCopy							= GetChaMapCopy(Player)
			local x,y 								= GetChaPos(Player)
			x										= math.floor(x/100)
			y										= math.floor(y/100)
			if (SideID == 2) then
				MapCopyNotice(MapCopy, "["..CTF.Conf.MapName.."]: "..ChaName..", from the Red Team captured the Flag at ("..x..","..y..")!")
			else
				MapCopyNotice(MapCopy, "["..CTF.Conf.MapName.."]: "..ChaName..", from the Green Team captured the Flag at ("..x..","..y..")!")
			end
			CTF.Flag_ChaID							= ChaID
			CTF.Flag_Spawned						= 0
			AddState(Player, Player, CTF.Conf.Flag.State, 1, 86400)
		end
	end
end

function CTF.PKP(ATKER, DEFER)
	local MapName_ATKER								= GetChaMapName(ATKER)
	local MapName_DEFER								= GetChaMapName(DEFER)
	if (MapName_ATKER == "ctf" and MapName_DEFER == "ctf") then
		local MapCopy								= GetChaMapCopy(ATKER)
		local Name_ATKER							= GetChaDefaultName(ATKER)
		local Name_DEFER							= GetChaDefaultName(DEFER)
		local Side_ATKER							= GetChaSideID(ATKER)
		local Side_DEFER							= GetChaSideID(DEFER)
		local ChaID_ATKER							= GetRoleID(ATKER)
		local ChaID_DEFER							= GetRoleID(DEFER)
		if (Side_ATKER == 1) then
			Name_ATKER								= Name_ATKER.." from the Green Team"
			-- Calculating the chance to grant points after kill enemy player
			if (Percentage_Random(CTF.Conf.ChanceScore) == 1) then
				CTF.GreenTeam.Score					= CTF.Conf.ScorePlayer
				BickerNotice(ATKER, "Red Team enemy killed, your team gets +"..CTF.Conf.ScorePlayer.." point!")
			end
		else
			Name_ATKER								= Name_ATKER.." from the Red Team"
			-- Calculating the chance to grant points after kill enemy player
			if (Percentage_Random(CTF.Conf.ChanceScore) == 1) then
				CTF.RedTeam.Score					= CTF.Conf.ScorePlayer
				BickerNotice(ATKER, "Green Team enemy killed, your team gets +"..CTF.Conf.ScorePlayer.." point!")
			end			
		end
		if (Side_DEFER == 1) then
			Name_DEFER								= Name_DEFER.." from the Green Team"
		else
			Name_DEFER								= Name_DEFER.." from the Red Team"
		end		
		Notice("["..CTF.Conf.MapName.."]: "..Name_DEFER.." #03 was defeated by "..Name_ATKER.." #14 !")
		
		if (ChaID_DEFER == CTF.Flag_ChaID) then
			local x,y								= GetChaPos(ATKER)
			x										= math.floor(x/100)
			y										= math.floor(y/100)
			if (Side_ATKER == 2) then
				MapCopyNotice(MapCopy, "["..CTF.Conf.MapName.."]: "..Name_ATKER.." captured the Flag at ("..x..", "..y..")!")
			else
				MapCopyNotice(MapCopy, "["..CTF.Conf.MapName.."]: "..Name_ATKER.." captured the Flag at ("..x..", "..y..")!")
			end
			CTF.Flag_ChaID							= ChaID_ATKER
			RemoveState(DEFER, CTF.Conf.Flag.State)
			AddState(ATKER, ATKER, CTF.Conf.Flag.State, 1, 86400)
		end
	end	
end
			
CTF.GiveRewards 									= function(Player, Reward)
	if Reward.Gold > 0 then
		AddMoney(Player, 0, Reward.Gold)
	end
	if Reward.Reputation > 0 then
		AddCreditX(Player, 0, Reward.Reputation)
	end
	if Reward.Honor > 0 and CheckBagItem(Player, 3849) == 1 then
		local Medal 								= GetChaItem2(Player, 2, 3849)
		local Honor 								= Reward.Honor + GetItemAttr(Medal, ITEMATTR_VAL_STR)
		SetItemAttr(Medal, ITEMATTR_VAL_STR, Honor)
	end	
	if Reward.Items ~= nil then
		if GetChaFreeBagGridNum(Player) > 0 then
			local ItemID 						= Reward.Items[math.random(1,table.getn(Reward.Items))].ID
			local Quantity 						= Reward.Items[math.random(1,table.getn(Reward.Items))].Quantity
			local Quality 						= Reward.Items[math.random(1,table.getn(Reward.Items))].Quality
			GiveItem(Player, 0, ItemID, Quantity, Quality)
			BickerNotice(Player, "["..CTF.Conf.MapName.."]: Your team wins! Received x"..Quantity.." "..GetItemName(ItemID)..".")
		else
			GiveItemX(Player, 0, ItemID, Quantity, Quality)
			BickerNotice(Player, "["..CTF.Conf.MapName.."]: Your team wins! Received x"..Quantity.." "..GetItemName(ItemID)..".")
		end
	end
	local Level 									= Lv(Player)
	if Reward.EXP > 0 and Level < CTF.Conf.ServerLv then
		local CurrentEXP = GetChaAttr(Player, ATTR_CEXP) + ((DEXP[Level+1] - DEXP[Level]) * (Reward.EXP/100))
		SetChaAttrI(Player, ATTR_CEXP, CurrentEXP)
	end	
end
CTF.Finish 											= function(MapCopy)
	if CTF.MapShutdown > 0 then
		for i = 1, table.getn(CTF.Conf.Time.StartShow) do
			if CTF.MapShutdown == CTF.Conf.Time.StartShow[i] then
				MapCopyNotice(MapCopy, "["..CTF.Conf.MapName.."]: Battle has come to an end! All players will leave in "..CTF.MapShutdown.." seconds!")
			end
		end
		CTF.MapShutdown								= CTF.MapShutdown - 1
		if CTF.MapShutdown == 0 then
			if CTF.GreenTeam.Score > CTF.RedTeam.Score then
				CTF.WinnerTeam								= 1
				MapCopyNotice(MapCopy, "["..CTF.Conf.MapName.."]: The Green Team wins the battle with ("..CTF.GreenTeam.Score.."/"..CTF.Conf.ScoreLimit..") points!")
				GMNotice("["..CTF.Conf.MapName.."]: The Green Team wins the battle with ("..CTF.GreenTeam.Score.."/"..CTF.Conf.ScoreLimit..") points!")
			elseif CTF.RedTeam.Score > CTF.GreenTeam.Score then
				CTF.WinnerTeam								= 2
				MapCopyNotice(MapCopy, "["..CTF.Conf.MapName.."]: The Red Team wins the battle with ("..CTF.RedTeam.Score.."/"..CTF.Conf.ScoreLimit..") points!")
				GMNotice("["..CTF.Conf.MapName.."]: The Red Team wins the battle with ("..CTF.RedTeam.Score.."/"..CTF.Conf.ScoreLimit..") points!")
			else
				MapCopyNotice(MapCopy, "["..CTF.Conf.MapName.."]: It seems there was no winners at this match!")
				GMNotice("["..CTF.Conf.MapName.."]: It seems there was no winners at this match!")
			end
			local PlayerNum									= GetMapCopyPlayerNum(MapCopy)
			BeginGetMapCopyPlayerCha(MapCopy)
			for i = 1, PlayerNum, 1 do
				local Player								= GetMapCopyNextPlayerCha(MapCopy)
				if (ValidCha(Player) == 1) then
					local SideID							= GetChaSideID(Player)
					if CTF.WinnerTeam ~= nil and SideID == CTF.WinnerTeam then
						CTF.GiveRewards(Player, CTF.Rewards)
					end
				end
			end	
			DealAllActivePlayerInMap(MapCopy, "TakeOutSideCTF")
			CTF.Init()										-- Reloads the map variables.
			ClearAllSubMapMonster(MapCopy)
			CloseMapCopy("ctf")
			return
		end
	end
end
TakeOutSideCTF										= function(Player)
	MoveCity(Player, "")
end
CTF.OpenDay						= function()
	local RegOpen				= {Day = {}, Hour = {}}
	for i,v in pairs(CTF.Conf.OpenDay) do
		RegOpen.Day[v]			= true
	end
	if (RegOpen.Day[tonumber(os.date("%w"))] == true) then
		return 1
	end
	return 0
end
CTF.OpenHour					= function()
	local RegOpen				= {Day = {}, Hour = {}}
	for i,v in pairs(CTF.Conf.OpenHour) do
		RegOpen.Hour[v]			= true
	end
	if (RegOpen.Hour[tonumber(os.date("%H"))] == true) then
		return 1
	end	
	return 0
end
CTF.Register 										= function(Player)
	local Minute									= tonumber(os.date("%M"))
	local PID										= GetRoleID(Player)
	local OsTime									= os.time()
	local Attempt									= CTF.LeaveTime[PID]
	if GetChaAttr(Player, ATTR_JOB) < 8 then
		BickerNotice(Player, "Only characters that have done 2nd class advancement can participate!")
		return
	end
	if CTF.OpenDay() == 0 then
		BickerNotice(Player, "Registering for "..CTF.Conf.MapName.." is unavailable today, please come back again tommorow.")
		return
	end
	if CTF.OpenHour() == 0 and Minute > CTF.Conf.CloseMin then
		BickerNotice(Player, "Registering for "..CTF.Conf.MapName.." is unavailable at this hour, please come back later.")
		return
	end	
	-- Not registered and battle arealdy started.
	if CTF.Members[PID] == nil and CTF.MapOpened == true then
		BickerNotice(Player, "You can't participate, the battle arealdy started!")
		return
	end
	-- Registered, battle started and didn't DC on map.
	if CTF.Members[PID] ~= nil and CTF.Members[PID].lobby == 1 and CTF.MapOpened == true and Attempt == nil then
		StartPlayerCTF(Player)
		return
	end
	-- Registered, battle started and disconnect attempt time didn't gone.
	if CTF.Members[PID] ~= nil and CTF.Members[PID].lobby == 1 and CTF.MapOpened == true and Attempt ~= nil and OsTime < Attempt then
		StartPlayerCTF(Player)
		return
	end	
	-- Registered, battle started and disconnect attempt time gone.
	if CTF.Members[PID] ~= nil and CTF.Members[PID].lobby == 1 and CTF.MapOpened == true and Attempt ~= nil and OsTime >= Attempt then
		BickerNotice(Player, "You can't participate anymore, your attempt time has gone!")
		return
	end		
	if IsInTeam(Player) == 1 then
		BickerNotice(Player, "You're inside a party. Cannot register!")
		return
	end
	if CTF.Conf.MinLv > GetChaAttr(Player, ATTR_LV) or (CTF.Conf.MaxLv ~= 0 and CTF.Conf.MaxLv < GetChaAttr(Player, ATTR_LV)) then
		BickerNotice(Player, "You can't participate, only players between levels "..CTF.Conf.MinLv.." through "..CTF.Conf.MaxLv.." can participate.")
		return
	end	
	CTF.Members[PID]								= {role = Player, lobby = 1}	
	MoveCity(Player, "Arena Island")	
end

function CTF.Timer(Player, Tick)
	local Hour,Minute,Second 						= tonumber(os.date("%H")),tonumber(os.date("%M")),tonumber(os.date("%S"))
	local Message									= ""
	for i,v in pairs(CTF.Conf.OpenHour) do	
		if Hour == v and Minute < CTF.Conf.CloseMin then
			if (CTF.LobbyOpened == false) then
				CTF.LobbyOpened						= true
			end
		end
		if Hour == v and Minute == 00 and Second == 05 then
			if (CTF.LobbyOpened == true) then
				Message								= Message.."["..CTF.Conf.MapName.."]: Registration is now Open!"
				Message								= Message.." Go to CTF Waiting Room - (2217,2792) Argent City."
				Message								= Message.." You have 5 minute(s) to register for battle.."
				ScrollNotice(Message, 1)
			end
		end
		if Hour == v and Minute == 02 and Second == 05 then
			if (CTF.LobbyOpened == true) then
				Message								= Message.."["..CTF.Conf.MapName.."]: Registration is now Open!"
				Message								= Message.." Go to CTF Waiting Room - (2217,2792) Argent City."
				Message								= Message.." You have 3 minute(s) to register for battle.."
				ScrollNotice(Message, 1)
			end
		end		
		if Hour == v and Minute == 04 and Second == 05 then
			if (CTF.LobbyOpened == true) then
				Message								= Message.."["..CTF.Conf.MapName.."]: Registration is now Open!"
				Message								= Message.." Go to CTF Waiting Room - (2217,2792) Argent City."
				Message								= Message.." You have 1 minute(s) to register for battle.."
				ScrollNotice(Message, 1)
			end
		end	
		if Hour == v and Minute == CTF.Conf.CloseMin and Second == 00 then
			if (CTF.LobbyOpened == true) then
				CTF.LobbyOpened						= false
				CTF.StartMap()
				GMNotice("["..CTF.Conf.MapName.."]: Map started! Red Team Versus Green Team. The team that get 100 point(s) first wins! Teams can get point(s) killing enemies (25% chance) or carry the Flag to Flag Pointer. After the team carries the flag to flag pointer, the flag holder will appear in the middle of the capture the flag. ***** If you are using Skill Tweak you can not see Flag Monster.")
				for i,v in pairs(CTF.Members) do
					if (GetChaMapName(v.role) == "pkmap") then
						StartPlayerCTF(v.role)
					end
				end
			end
		end			
	end
end

function State_None_Add(role, statelv)
end
function State_None_Rem(role, statelv)
end

 

  • Haha 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...