Fortress Forever

Go Back   Fortress Forever > Editing > Mapping > Lua

Reply
 
Thread Tools Display Modes
Old 02-02-2009, 06:14 PM   #1
Entigren
 
Join Date: Feb 2009
Gametype: Capture the Flag
Posts Rated Helpful 0 Times
Flag Specific Trigger

Hi, I've been helping a friend with a map for a couple of days now. We are trying to go about the flag security in a new and somewhat unique way. However I need certain outputs to take place on whether the flag is in its respawn position or not. So I was thinking making a trigger that is activated by the set team flag. I have messed with the lua a bit but dont have much knowledge on it. I got it to a point where the flag can trigger it however a player had to be present in the trigger also. I would like it to be able to trigger with just the flag in it. If anyone could help me figure this out I would appreciate it. Thanks.
Entigren is offline   Reply With Quote


Old 02-02-2009, 06:22 PM   #2
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter
Gametype: Conc tag (you just wait)
Affiliations: Mustache Brigade
Posts Rated Helpful 352 Times
Send a message via AIM to squeek.
Not possible at the moment, but it is high on the lua-priority list.
__________________
#FF.Pickup ¤ Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington
squeek. is offline   Reply With Quote


Old 02-02-2009, 07:02 PM   #3
Entigren
 
Join Date: Feb 2009
Gametype: Capture the Flag
Posts Rated Helpful 0 Times
Thanks, how about a script that would constantly check the flag origin and compare it to the location where its suppose to respawn.
Entigren is offline   Reply With Quote


Old 02-02-2009, 10:54 PM   #4
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter
Gametype: Conc tag (you just wait)
Affiliations: Mustache Brigade
Posts Rated Helpful 352 Times
Send a message via AIM to squeek.
Well, you can definitely check to see if it's off its origin. In base_ctf, the flag info_ff_script definitions have a status property that starts at 0 and changes to 1/2 after it gets touched initially. Detecting if it's within a certain trigger, though, is impossible.

You may be able to hack a crazy workaround using GetOrigin(), but I'd just wait until we get a real implementation of this.
__________________
#FF.Pickup ¤ Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington
squeek. is offline   Reply With Quote


Old 02-03-2009, 03:05 AM   #5
Entigren
 
Join Date: Feb 2009
Gametype: Capture the Flag
Posts Rated Helpful 0 Times
Would you have any kind of time frame for this feature. Also could you explain to me how the GetOrigin() works just in case I choose to be crazy as you put it.

Last edited by Entigren; 02-03-2009 at 03:23 AM.
Entigren is offline   Reply With Quote


Old 02-03-2009, 05:09 AM   #6
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter
Gametype: Conc tag (you just wait)
Affiliations: Mustache Brigade
Posts Rated Helpful 352 Times
Send a message via AIM to squeek.
Quote:
Originally Posted by Entigren View Post
Would you have any kind of time frame for this feature.
Hopefully soon, though nothing definite. It's been on our to-do list forever.

Quote:
Originally Posted by Entigren View Post
Also could you explain to me how the GetOrigin() works just in case I choose to be crazy as you put it.
I believe you can do:

Code:
local flag = GetInfoScriptByName( "flag_name" )
local pos = flag:GetOrigin()
pos will then be a vector with properties x, y, and z that you can access using:

Code:
pos.x
pos.y
pos.z
__________________
#FF.Pickup ¤ Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington
squeek. is offline   Reply With Quote


Old 02-03-2009, 03:33 PM   #7
Entigren
 
Join Date: Feb 2009
Gametype: Capture the Flag
Posts Rated Helpful 0 Times
Thanks for the help squeek. However, I guess I just don't understand enough about the lua to get this to work. What I am trying to do is mainly use that getorigin to compare the position of the flag at any given moment to where the flag spawns at. If the flag is there I would like a switch to become usable, and if it is not obviously make the switch unusable. Since I didn't know how to tell the switch to lock or unlock through the lua I tried just changing it to only work for a team that isn't in that map (kGreen or kYellow). However as much as I try I can not get this to work.

Here is my lua code to do this. If any one could take a look and tell me what I am doing wrong. I am sure there are a lot of mistakes to it. So don't hold back on ripping it apart.
Code:
button_common = func_button:new({ team = Team.kUnassigned }) 

function button_common:allowed( allowed_entity ) 
	if IsPlayer( allowed_entity ) then
		local player = CastToPlayer( allowed_entity )
		if player:GetTeamId() == self.team then
			return EVENT_ALLOWED
		end
	end

	return EVENT_DISALLOWED
end

-- TODO this doesn't work
function button_common:onfailuse( use_entity )
	if IsPlayer( use_entity ) then
		local player = CastToPlayer( use_entity )
		BroadCastMessageToPlayer( player, "#FF_NOTALLOWEDBUTTON" )
	end
end



AddSchedule("CheckFlag", 1, getflagorigin)

function getflagorigin()

local flag = GetInfoScriptByName( "red_flag")
local pos = flag:GetOrigin()

if pos.x == 319 then
	if pos.y == -297 then
		if pos.z == 237 then
			red_button_lower = button_common:new({ team = Team.kBlue })
		else
			
			red_button_lower = button_common:new({ team = Team.kGreen })
		end
	else
		red_button_lower = button_common:new({ team = Team.kGreen })
	end
else
	red_button_lower = button_common:new({ team = Team.kGreen })
end

end
As of right now I am just hard coding the original location of where the flag is suppose to spawn. If I can get this to work I will have it find the cordinates on map startup and set them to a variable and compare it to that. That way the flag can be moved in hammer without having to edit the lua everytime. Again thank you for any help you guys can give me.
Entigren is offline   Reply With Quote


Old 02-03-2009, 04:07 PM   #8
Crazycarl
D&A Member
Wiki Team
Fortress Forever Staff
 
Crazycarl's Avatar
 
Join Date: Apr 2007
Posts Rated Helpful 31 Times
This doesn't make sense. It's extremely unlikely that a flag will land exactly where it spawns, unless you will cause it to return there. In that case, just use a variable to keep track of whether the flag has been returned or whather it has been picked up (the default CTF flags already do this).

But if for some reason you need to do it this way, I would have the origin check function return a boolean (true/false), and call it from within the :allowed() function. And instead of checking for an exact coordinate, test for a max/min range of x, y, and z. Otherwise it would almost never return true.
__________________
Support FF:
Crazycarl is offline   Reply With Quote


Old 02-03-2009, 04:14 PM   #9
Entigren
 
Join Date: Feb 2009
Gametype: Capture the Flag
Posts Rated Helpful 0 Times
The flag returned or picked up would work perfectly. How would I go about telling it to check this. I am new to lua and it was just a shot in the dark. Thanks.
Entigren is offline   Reply With Quote


Old 02-03-2009, 06:07 PM   #10
Ender
[ gr. Cloud ]
 
Join Date: Sep 2007
Posts Rated Helpful 0 Times
In the base_teamplay.lua, where the base_flag is defined, it seems to have a check for the status of the flag pertaining (i.e., if it's 'home', picked up, or dropped):

Code:
-----------------------------------------------------------------------------
-- Flag
-- status: 0 = home, 1 = carried, 2 = dropped
-----------------------------------------------------------------------------
baseflag = info_ff_script:new({
	name = "base flag",
	team = 0,
	model = "models/flag/flag.mdl",
	tosssound = "Flag.Toss",
	modelskin = 1,
	dropnotouchtime = 2,
	capnotouchtime = 2,
	botgoaltype = Bot.kFlag,
	status = 0,
	hudicon = "",
	hudx = 5,
	hudy = 114,
	hudalign = 1,
	hudstatusiconalign = 2,
	hudstatusicon = "",
	hudstatusiconx = 0,
	hudstatusicony = 0,
	hudstatusiconw = 50,
	hudstatusiconh = 50,
	allowdrop = true,
	touchflags = {AllowFlags.kOnlyPlayers,AllowFlags.kBlue, AllowFlags.kRed, AllowFlags.kYellow, AllowFlags.kGreen}
})
I'm not sure if this is specifically what Crazycarl is referring to, but it seems like it. Now, how you'd access that and implement it is a little beyond me at the moment.
Ender is offline   Reply With Quote


Old 02-03-2009, 08:21 PM   #11
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter
Gametype: Conc tag (you just wait)
Affiliations: Mustache Brigade
Posts Rated Helpful 352 Times
Send a message via AIM to squeek.
Code:
flag_button_common = func_button:new({ team = Team.kUnassigned, flagname = "default_flag_name" }) 

function flag_button_common:allowed( allowed_entity ) 
	if IsPlayer( allowed_entity ) then
		local player = CastToPlayer( allowed_entity )
		-- if player is on the correct team
		if player:GetTeamId() == self.team then
			-- if flag is at its spawn point
			if _G[self.flagname].status == 0 then
				return EVENT_ALLOWED
			end
		end
	end
	return EVENT_DISALLOWED
end

-- if not allowed
function flag_button_common:onfailuse( use_entity )
	if IsPlayer( use_entity ) then
		local player = CastToPlayer( use_entity )
		BroadCastMessageToPlayer( player, "#FF_NOTALLOWEDBUTTON" )
	end
end

red_flag_button = flag_button_common:new({ team = Team.kRed, flagname = "flag_name" }) 
blue_flag_button = flag_button_common:new({ team = Team.kBlue, flagname = "flag_name" })
Hopefully that works for you.
__________________
#FF.Pickup ¤ Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington
squeek. is offline   Reply With Quote


Old 02-04-2009, 01:17 AM   #12
Entigren
 
Join Date: Feb 2009
Gametype: Capture the Flag
Posts Rated Helpful 0 Times
Squeek, you rock its working great so far. Thanks to you and crazycarl my friend can now move on with his map.
Entigren is offline   Reply With Quote


Old 02-04-2009, 03:12 AM   #13
Entigren
 
Join Date: Feb 2009
Gametype: Capture the Flag
Posts Rated Helpful 0 Times
One last question and I promise I'm done for now. Is it possible to parent something through the lua.
Entigren is offline   Reply With Quote


Old 02-04-2009, 03:34 AM   #14
squeek.
Stuff Do-er
Lua Team
Wiki Team
Fortress Forever Staff
 
squeek.'s Avatar
 
Join Date: Mar 2007
Location: Northern California
Class/Position: Rallygun Shooter
Gametype: Conc tag (you just wait)
Affiliations: Mustache Brigade
Posts Rated Helpful 352 Times
Send a message via AIM to squeek.
Quote:
OutputEvent( entity, input, parameter, delay, x )
Triggers any named entity in the map using Source's I/O system.

Returns: nothing

entity(string) the entity as named in Hammer
input(string) the name of a valid input for the entity
parameter(string) OPTIONAL. value override
delay(float) OPTIONAL. number of seconds to wait before firing.
x(unsigned int) OPTIONAL. fire once boolean?
Code:
OutputEvent( "entity_name", "SetParent", "parent_entity" )
__________________
#FF.Pickup ¤ Fortress-Forever pickups

My Non-official Maps
Released FF_DM_Squeek - FF_2Mesa3_Classic - FF_Siege_Classic
Beta FF_Myth - FF_Redlight_Greenlight

Sick of the people on the internet, always moanin'. They just moan.
- Karl Pilkington
squeek. is offline   Reply With Quote


Old 02-04-2009, 03:36 AM   #15
Entigren
 
Join Date: Feb 2009
Gametype: Capture the Flag
Posts Rated Helpful 0 Times
Thanks again squeek, I actually just figured it out and was about to edit my question.
Entigren is offline   Reply With Quote


Reply

Tags
flag, lua, trigger


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 07:53 AM.


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