Fortress Forever

Fortress Forever (https://forums.fortress-forever.com/index.php)
-   Lua (https://forums.fortress-forever.com/forumdisplay.php?f=44)
-   -   Flag Specific Trigger (https://forums.fortress-forever.com/showthread.php?t=18884)

Entigren 02-02-2009 05:14 PM

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.

squeek. 02-02-2009 05:22 PM

Not possible at the moment, but it is high on the lua-priority list.

Entigren 02-02-2009 06:02 PM

Thanks, how about a script that would constantly check the flag origin and compare it to the location where its suppose to respawn.

squeek. 02-02-2009 09:54 PM

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.

Entigren 02-03-2009 02:05 AM

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.

squeek. 02-03-2009 04:09 AM

Quote:

Originally Posted by Entigren (Post 424541)
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 (Post 424541)
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


Entigren 02-03-2009 02:33 PM

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.

Crazycarl 02-03-2009 03:07 PM

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.

Entigren 02-03-2009 03:14 PM

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.

Ender 02-03-2009 05:07 PM

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.

squeek. 02-03-2009 07:21 PM

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.

Entigren 02-04-2009 12:17 AM

Squeek, you rock its working great so far. Thanks to you and crazycarl my friend can now move on with his map.

Entigren 02-04-2009 02:12 AM

One last question and I promise I'm done for now. :mrgreen: Is it possible to parent something through the lua.

squeek. 02-04-2009 02:34 AM

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" )

Entigren 02-04-2009 02:36 AM

Thanks again squeek, I actually just figured it out and was about to edit my question.


All times are GMT. The time now is 08:26 AM.

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