Fortress Forever

Go Back   Fortress Forever > Editing > Mapping

Reply
 
Thread Tools Display Modes
Old 02-01-2011, 04:05 PM   #1
Hammock
D&A Member
 
Join Date: Sep 2007
Posts Rated Helpful 13 Times
Slay on Flag touch

I'm looking for a lua that would make it so, until a certain number of players on the server is reached if the red team touched the blue flag they will be slain.

Once the server has like 10 people playing, the blue flag becomes available to touch again.

If the player count drops below 10 anyone who touches the blue flag will again be slain.

These are just arbitrary numbers but I imagine it would be simple enough to just modify the given number in the script.

I would also like to send a message to the player's screen that was just slain by touching the flag. And a message to all players when the specified player count is reached, or fallen below

Also since i'm not too familiar with lua's I was wondering if it's possible to set this up for all maps without edititing each individual lua file (like some sort of master lua file?), if not, it wouldn't be too tough to write a program that would inject it into every lua, so i'm not really too worried about this part.
Hammock is offline   Reply With Quote


Old 02-01-2011, 05:07 PM   #2
Elmo
Gets tickled by FF
Fortress Forever Staff
 
Elmo's Avatar
 
Join Date: Jun 2007
Location: UK
Class/Position: Med Solly HW
Gametype: Any/CTF
Posts Rated Helpful 41 Times
or to disallow item pickup and just display the message. Don't like killing people for no reason. Alternatively prompt those that are offensive classes to change also. Nice idea
__________________
Support FF:
Done: ff_monkey
Done: ff_bases
Done: ff_warpath
Forever Doing: ff_medieval (beta#99999999)
Elmo is offline   Reply With Quote


Old 02-01-2011, 05:35 PM   #3
Bridget
Banned
 
Bridget's Avatar
 
Join Date: Sep 2008
Class/Position: Soldier
Gametype: AVD
Affiliations: TALOS
Posts Rated Helpful 5 Times
Code:
-- Assuming this overrides the base_flag functions.
-- Also assuming the blue flag is named 'blue flag'.
-- Also assuming info_ff_script has an allowed() return function.

function GetNumAllPlayers() return GetTeam(Team.kRed):GetNumPlayers() + GetTeam(Team.kBlue):GetNumPlayers() end

function baseflag:allowed() if GetNumAllPlayers() >= 10 then return true else return false end

function player_ondisconnect()
	-- Game still counts the player during this function's execution, I think?
	if (GetNumAllPlayers() - 1) < 10 then
		GetInfoScriptByName('blue flag'):Return()
		BroadCastMessage('The Blue Flag has returned due to player limit being under ten.')
	end
end
dunno

Last edited by Bridget; 02-01-2011 at 05:36 PM. Reason: forgot an end
Bridget is offline   Reply With Quote


Old 02-01-2011, 05:56 PM   #4
Hammock
D&A Member
 
Join Date: Sep 2007
Posts Rated Helpful 13 Times
Ya elmo dissallowing flag touch with a message to the user would be fine too.

I'll have to test the script out later as I am at work atm, thanks bridget
Hammock is offline   Reply With Quote


Old 02-01-2011, 07:34 PM   #5
Hammock
D&A Member
 
Join Date: Sep 2007
Posts Rated Helpful 13 Times
Quote:
Originally Posted by Bridget View Post
Code:
-- Assuming this overrides the base_flag functions.
-- Also assuming the blue flag is named 'blue flag'.
-- Also assuming info_ff_script has an allowed() return function.

function GetNumAllPlayers() return GetTeam(Team.kRed):GetNumPlayers() + GetTeam(Team.kBlue):GetNumPlayers() end

function baseflag:allowed() if GetNumAllPlayers() >= 10 then return true else return false end

function player_ondisconnect()
	-- Game still counts the player during this function's execution, I think?
	if (GetNumAllPlayers() - 1) < 10 then
		GetInfoScriptByName('blue flag'):Return()
		BroadCastMessage('The Blue Flag has returned due to player limit being under ten.')
	end
end
dunno
Did a quick test on this at lunch, and it messed up team/class selection, all 4 teams became available, and no classes were available
Hammock is offline   Reply With Quote


Old 02-02-2011, 02:01 PM   #6
Bridget
Banned
 
Bridget's Avatar
 
Join Date: Sep 2008
Class/Position: Soldier
Gametype: AVD
Affiliations: TALOS
Posts Rated Helpful 5 Times
Change

Code:
function baseflag:allowed() if GetNumAllPlayers() >= 10 then return true else return false end
To:

Code:
function baseflag:allowed() if GetNumAllPlayers() >= 10 then return true else return false end end
Also, check the console for any LUA errors. Report them here.
Bridget is offline   Reply With Quote


Old 02-02-2011, 07:31 PM   #7
Hammock
D&A Member
 
Join Date: Sep 2007
Posts Rated Helpful 13 Times
Okay, no more errors, map starts fine, can select team and classes.

But I'm still capable of being able to touch the blue flag, so it's not quite accomplishing what's intended.

As the only person in the server I should not be able to touch the blue flag until the player count reaches 10.
Hammock is offline   Reply With Quote


Old 02-02-2011, 07:47 PM   #8
Bridget
Banned
 
Bridget's Avatar
 
Join Date: Sep 2008
Class/Position: Soldier
Gametype: AVD
Affiliations: TALOS
Posts Rated Helpful 5 Times
The flag probably has no allowed() function. You probably have to override baseflag's touch function. Try this:

Code:
function baseflag:touch( touch_entity )
	if self.name == 'Blue Flag' and GetNumAllPlayers() < 10 then return false end
	
	local player = CastToPlayer( touch_entity )
	-- pickup if they can
	if self.notouch[player:GetId()] then return; end
	
	if player:GetTeamId() ~= self.team then
		-- let the teams know that the flag was picked up
		SmartSound(player, "yourteam.flagstolen", "yourteam.flagstolen", "otherteam.flagstolen")
		RandomFlagTouchSpeak( player )
		SmartMessage(player, "#FF_YOUPICKUP", "#FF_TEAMPICKUP", "#FF_OTHERTEAMPICKUP", Color.kGreen, Color.kGreen, Color.kRed)
		
		-- if the player is a spy, then force him to lose his disguise
		player:SetDisguisable( false )
		-- if the player is a spy, then force him to lose his cloak
		player:SetCloakable( false )
		
		-- note: this seems a bit backwards (Pickup verb fits Player better)
		local flag = CastToInfoScript(entity)
		flag:Pickup(player)
		AddHudIcon( player, self.hudicon, flag:GetName(), self.hudx, self.hudy, self.hudwidth, self.hudheight, self.hudalign )

		-- log action in stats
		LogLuaEvent(player:GetId(), 0, "flag_touch", "flag_name", flag:GetName(), "player_origin", (string.format("%0.2f",player:GetOrigin().x) .. ", " .. string.format("%0.2f",player:GetOrigin().y) .. ", " .. string.format("%0.1f",player:GetOrigin().z) ), "player_health", "" .. player:GetHealth());	

		local team = nil
		-- get team as a lowercase string
		if player:GetTeamId() == Team.kBlue then team = "blue" end
		if player:GetTeamId() == Team.kRed then team = "red" end
		if player:GetTeamId() == Team.kGreen then team = "green" end  
		if player:GetTeamId() == Team.kYellow then team = "yellow" end
		
		-- objective icon pointing to the cap
		UpdateObjectiveIcon( player, GetEntityByName( team.."_cap" ) )

		-- 100 points for initial touch on flag
		if self.status == 0 then player:AddFortPoints(FORTPOINTS_PER_INITIALTOUCH, "#FF_FORTPOINTS_INITIALTOUCH") end
		self.status = 1
		self.carriedby = player:GetName()
		self:refreshStatusIcons(flag:GetName())

	end
end
Bridget is offline   Reply With Quote


Old 02-03-2011, 04:29 AM   #9
Hammock
D&A Member
 
Join Date: Sep 2007
Posts Rated Helpful 13 Times
Thanks, that worked
Hammock is offline   Reply With Quote


Old 02-04-2011, 08:22 PM   #10
zE
Pew pew ze beams
 
zE's Avatar
 
Join Date: Jan 2008
Gametype: Gathers
Affiliations: pew pew
Posts Rated Helpful 11 Times
So im kinda interested on this to my server, but what to edit base_ctf lua ? and can someone post full workinfg lua plz : D
zE is offline   Reply With Quote


Old 02-04-2011, 08:30 PM   #11
Hammock
D&A Member
 
Join Date: Sep 2007
Posts Rated Helpful 13 Times
This is what I ended up using, and I put it into my base_ctf.lua

The number 10 near the top is what you change to suit your needs for your server, say if you want a full game to be enabled at 18 players you'd change it to 18

Code:
function GetNumAllPlayers() return GetTeam(Team.kRed):GetNumPlayers() + GetTeam(Team.kBlue):GetNumPlayers() end

function baseflag:touch( touch_entity )
	if self.name == 'Blue Flag' and GetNumAllPlayers() < 10 then return false end
	
	local player = CastToPlayer( touch_entity )
	-- pickup if they can
	if self.notouch[player:GetId()] then return; end
	
	if player:GetTeamId() ~= self.team then
		-- let the teams know that the flag was picked up
		SmartSound(player, "yourteam.flagstolen", "yourteam.flagstolen", "otherteam.flagstolen")
		RandomFlagTouchSpeak( player )
		SmartMessage(player, "#FF_YOUPICKUP", "#FF_TEAMPICKUP", "#FF_OTHERTEAMPICKUP", Color.kGreen, Color.kGreen, Color.kRed)
		
		-- if the player is a spy, then force him to lose his disguise
		player:SetDisguisable( false )
		-- if the player is a spy, then force him to lose his cloak
		player:SetCloakable( false )
		
		-- note: this seems a bit backwards (Pickup verb fits Player better)
		local flag = CastToInfoScript(entity)
		flag:Pickup(player)
		AddHudIcon( player, self.hudicon, flag:GetName(), self.hudx, self.hudy, self.hudwidth, self.hudheight, self.hudalign )

		-- log action in stats
		LogLuaEvent(player:GetId(), 0, "flag_touch", "flag_name", flag:GetName(), "player_origin", (string.format("%0.2f",player:GetOrigin().x) .. ", " .. string.format("%0.2f",player:GetOrigin().y) .. ", " .. string.format("%0.1f",player:GetOrigin().z) ), "player_health", "" .. player:GetHealth());	

		local team = nil
		-- get team as a lowercase string
		if player:GetTeamId() == Team.kBlue then team = "blue" end
		if player:GetTeamId() == Team.kRed then team = "red" end
		if player:GetTeamId() == Team.kGreen then team = "green" end  
		if player:GetTeamId() == Team.kYellow then team = "yellow" end
		
		-- objective icon pointing to the cap
		UpdateObjectiveIcon( player, GetEntityByName( team.."_cap" ) )

		-- 100 points for initial touch on flag
		if self.status == 0 then player:AddFortPoints(FORTPOINTS_PER_INITIALTOUCH, "#FF_FORTPOINTS_INITIALTOUCH") end
		self.status = 1
		self.carriedby = player:GetName()
		self:refreshStatusIcons(flag:GetName())

	end
end
Hammock is offline   Reply With Quote


Old 02-05-2011, 06:19 PM   #12
zE
Pew pew ze beams
 
zE's Avatar
 
Join Date: Jan 2008
Gametype: Gathers
Affiliations: pew pew
Posts Rated Helpful 11 Times
yo bri is it possible with this lua limit certain classes, when theres <= 10 players and display message when theres 11 players to warn that blue flag is avaible D: that would be leet
zE is offline   Reply With Quote


Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:03 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.