Fortress Forever

Go Back   Fortress Forever > Editing > Mapping > Lua

Reply
 
Thread Tools Display Modes
Old 03-08-2008, 06:42 PM   #1
Doughnut-4|4-
 
Join Date: May 2007
Posts Rated Helpful 0 Times
How does a Capture Flag trigger Outputs?

I'm trying to make a map where Capping will result in doors opening and closing. Can someone help? I tried using the output on the trigger_ff_script cap point with no results.
Doughnut-4|4- is offline   Reply With Quote


Old 03-10-2008, 01:43 AM   #2
Sidd
Lua Team
 
Join Date: Mar 2007
Posts Rated Helpful 1 Times
You need to override the function basecap : oncapture(player, item)
Code:
my_cap = basecap:new({})

function my_cap:oncapture(player, item)
    if player:GetTeamId() == Team.kBlue then
      -- open doors and stuff for blue capture here
    elseif player:GetTeamId() == Team.kRed then
      -- opend doors and stuff for Red capture here
    end

    -- let the teams know that a capture occured
    SmartSound(player, "yourteam.flagcap", "yourteam.flagcap", "otherteam.flagcap")
    SmartSpeak(player, "CTF_YOUCAP", "CTF_TEAMCAP", "CTF_THEYCAP")
    SmartMessage(player, "#FF_YOUCAP", "#FF_TEAMCAP", "#FF_OTHERTEAMCAP")

end

red_my_cap = my_cap:new({team = Team.kRed,
			 item = {"blue_flag","yellow_flag","green_flag"}})

blue_my_cap = my_cap:new({team = Team.kBlue,
			  item = {"red_flag","yellow_flag","green_flag"}})
then use red_my_cap in place of red_cap in your map.
Hope this helps.

The above code is totally untested, as usual.
Sidd is offline   Reply With Quote


Old 03-10-2008, 03:53 PM   #3
public_slots_free
 
Join Date: Sep 2007
Posts Rated Helpful 0 Times
Sidd has it right
public_slots_free is offline   Reply With Quote


Old 03-10-2008, 08:09 PM   #4
Doughnut-4|4-
 
Join Date: May 2007
Posts Rated Helpful 0 Times
I'm going need a little more help. I renamed my 4 colored caps "blue_my_cap"...etc. And first I tried to see if the outputs on the caps would respond without any altercations to the LUA but I knew my luck wouldn't be that good. Next I tried to alter the code so it'd activate a logic_relay which would then Output what I needed... that didn't work either. So now I guess I want to have the LUA trigger all the doors, but I'm not sure how to add multiple outputs in an LUA. So please help me clean up my LUA based on your original.

Code:
my_cap = basecap:new({})

function my_cap:oncapture(player, item)
    if player:GetTeamId() == Team.kBlue then
      -- OutputEvent( alpha_door1, "Open" )
      -- OutputEvent( alpha_door2, "Open" )
      -- OutputEvent( alpha_door3, "Open" )
      -- OutputEvent( alpha_door4, "Open" )
      -- OutputEvent( alpha_maingate, "Open" )
      -- OutputEvent( alphaspecialdoor, "Disable" )
      -- OutputEvent( beta_door1, "Close" )
      -- OutputEvent( beta_door2, "Close" )
      -- OutputEvent( beta_door3, "Close" )
      -- OutputEvent( beta_door4, "Close" )
      -- OutputEvent( beta_maingate, "Close" )
      -- OutputEvent( betaspecialdoor, "Enable" )
    elseif player:GetTeamId() == Team.kGreen then
      -- OutputEvent( alpha_door1, "Open" )
      -- OutputEvent( alpha_door2, "Open" )
      -- OutputEvent( alpha_door3, "Open" )
      -- OutputEvent( alpha_door4, "Open" )
      -- OutputEvent( alpha_maingate, "Open" )
      -- OutputEvent( alphaspecialdoor, "Disable" )
      -- OutputEvent( beta_door1, "Close" )
      -- OutputEvent( beta_door2, "Close" )
      -- OutputEvent( beta_door3, "Close" )
      -- OutputEvent( beta_door4, "Close" )
      -- OutputEvent( beta_maingate, "Close" )
      -- OutputEvent( betaspecialdoor, "Enable" )
    elseif player:GetTeamId() == Team.kYellow then
      -- OutputEvent( alpha_door1, "Close" )
      -- OutputEvent( alpha_door2, "Close" )
      -- OutputEvent( alpha_door3, "Close" )
      -- OutputEvent( alpha_door4, "Close" )
      -- OutputEvent( alpha_maingate, "Close" )
      -- OutputEvent( alphaspecialdoor, "Enable" )
      -- OutputEvent( beta_door1, "Open" )
      -- OutputEvent( beta_door2, "Open" )
      -- OutputEvent( beta_door3, "Open" )
      -- OutputEvent( beta_door4, "Open" )
      -- OutputEvent( beta_maingate, "Open" )
      -- OutputEvent( betaspecialdoor, "Disable" )
    elseif player:GetTeamId() == Team.kRed then
      -- OutputEvent( alpha_door1, "Close" )
      -- OutputEvent( alpha_door2, "Close" )
      -- OutputEvent( alpha_door3, "Close" )
      -- OutputEvent( alpha_door4, "Close" )
      -- OutputEvent( alpha_maingate, "Close" )
      -- OutputEvent( alphaspecialdoor, "Enable" )
      -- OutputEvent( beta_door1, "Open" )
      -- OutputEvent( beta_door2, "Open" )
      -- OutputEvent( beta_door3, "Open" )
      -- OutputEvent( beta_door4, "Open" )
      -- OutputEvent( beta_maingate, "Open" )
      -- OutputEvent( betaspecialdoor, "Disable" )
    end

    -- let the teams know that a capture occured
    SmartSound(player, "yourteam.flagcap", "yourteam.flagcap", "otherteam.flagcap")
    SmartSpeak(player, "CTF_YOUCAP", "CTF_TEAMCAP", "CTF_THEYCAP")
    SmartMessage(player, "#FF_YOUCAP", "#FF_TEAMCAP", "#FF_OTHERTEAMCAP")

end

blue_my_cap = my_cap:new({team = Team.kBlue,
			  item = {"green_flag"}})

red_my_cap = my_cap:new({team = Team.kRed,
			 item = {"yellow_flag"}})

yellow_my_cap = my_cap:new({team = Team.kYellow,
			  item = {"red_flag"}})

green_my_cap = my_cap:new({team = Team.kGreen,
			  item = {"blue_flag"}})
Doughnut-4|4- is offline   Reply With Quote


Old 03-10-2008, 08:51 PM   #5
public_slots_free
 
Join Date: Sep 2007
Posts Rated Helpful 0 Times
i am pretty sure you need quotes around the first parameter of outputevent

OutputEvent( "betaspecialdoor", "Disable" )
not
OutputEvent( betaspecialdoor, "Disable" )
public_slots_free is offline   Reply With Quote


Old 03-10-2008, 09:34 PM   #6
Sidd
Lua Team
 
Join Date: Mar 2007
Posts Rated Helpful 1 Times
Code:
function open_the_doors()
    OutputEvent( "alpha_door1", "Open" )
    OutputEvent( "alpha_door2", "Open" )
    OutputEvent( "alpha_door3", "Open" )
    OutputEvent( "alpha_door4", "Open" )
    OutputEvent( "alpha_maingate", "Open" )
    OutputEvent( "alphaspecialdoor", "Disable" )
    OutputEvent( "beta_door1", "Close" )
    OutputEvent( "beta_door2", "Close" )
    OutputEvent( "beta_door3", "Close" )
    OutputEvent( "beta_door4", "Close" )
    OutputEvent( "beta_maingate", "Close" )
    OutputEvent( "betaspecialdoor", "Enable" )
end

my_cap = basecap:new({})

function my_cap:oncapture(player, item)
    if player:GetTeamId() == Team.kBlue then
        open_the_doors()
    elseif player:GetTeamId() == Team.kGreen then
        open_the_doors()
    elseif player:GetTeamId() == Team.kYellow then
        open_the_doors()
    elseif player:GetTeamId() == Team.kRed then
        open_the_doors()
    end

    -- let the teams know that a capture occured
    SmartSound(player, "yourteam.flagcap", "yourteam.flagcap", "otherteam.flagcap")
    SmartSpeak(player, "CTF_YOUCAP", "CTF_TEAMCAP", "CTF_THEYCAP")
    SmartMessage(player, "#FF_YOUCAP", "#FF_TEAMCAP", "#FF_OTHERTEAMCAP")

end

blue_my_cap = my_cap:new({team = Team.kBlue,
			  item = {"green_flag"}})
-- This only lets blue capture the green flag
-- perhaps instead you want :
-- item = {"blue_flag","yellow_flag","green_flag"}})

red_my_cap = my_cap:new({team = Team.kRed,
			 item = {"yellow_flag"}})

yellow_my_cap = my_cap:new({team = Team.kYellow,
			  item = {"red_flag"}})

green_my_cap = my_cap:new({team = Team.kGreen,
			  item = {"blue_flag"}})
Sidd is offline   Reply With Quote


Old 03-10-2008, 09:35 PM   #7
Doughnut-4|4-
 
Join Date: May 2007
Posts Rated Helpful 0 Times
OMG I think it works!
Thanks so much for the help. I'm really happy cause I think the LUA is perfect now. I just need to work on texturing the map and stuff but I might be able to post pics soon.
Thanks again!
Doughnut-4|4- is offline   Reply With Quote


Old 03-10-2008, 09:48 PM   #8
public_slots_free
 
Join Date: Sep 2007
Posts Rated Helpful 0 Times
I dont think it works right. Sidd, you would need a second function because your current one doesn't cover all the output events he listed in his 2nd post. Plus, after the first capture, it isnt really doing anything to the doors.
public_slots_free is offline   Reply With Quote


Old 03-10-2008, 09:57 PM   #9
public_slots_free
 
Join Date: Sep 2007
Posts Rated Helpful 0 Times
Code:
function open_the_doors()
    OutputEvent( "alpha_door1", "Open" )
    OutputEvent( "alpha_door2", "Open" )
    OutputEvent( "alpha_door3", "Open" )
    OutputEvent( "alpha_door4", "Open" )
    OutputEvent( "alpha_maingate", "Open" )
    OutputEvent( "alphaspecialdoor", "Disable" )
    OutputEvent( "beta_door1", "Close" )
    OutputEvent( "beta_door2", "Close" )
    OutputEvent( "beta_door3", "Close" )
    OutputEvent( "beta_door4", "Close" )
    OutputEvent( "beta_maingate", "Close" )
    OutputEvent( "betaspecialdoor", "Enable" )
end

function open_the_doors2()
    OutputEvent( "alpha_door1", "Close" )
    OutputEvent( "alpha_door2", "Close" )
    OutputEvent( "alpha_door3", "Close" )
    OutputEvent( "alpha_door4", "Close" )
    OutputEvent( "alpha_maingate", "Close" )
    OutputEvent( "alphaspecialdoor", "Enable" )
    OutputEvent( "beta_door1", "Open" )
    OutputEvent( "beta_door2", "Open" )
    OutputEvent( "beta_door3", "Open" )
    OutputEvent( "beta_door4", "Open" )
    OutputEvent( "beta_maingate", "Open" )
    OutputEvent( "betaspecialdoor", "Disable" )
end

my_cap = basecap:new({})

function my_cap:oncapture(player, item)
    if player:GetTeamId() == Team.kBlue then
        open_the_doors()
    elseif player:GetTeamId() == Team.kGreen then
        open_the_doors()
    elseif player:GetTeamId() == Team.kYellow then
        open_the_doors2()
    elseif player:GetTeamId() == Team.kRed then
        open_the_doors2()
    end

    -- let the teams know that a capture occured
    SmartSound(player, "yourteam.flagcap", "yourteam.flagcap", "otherteam.flagcap")
    SmartSpeak(player, "CTF_YOUCAP", "CTF_TEAMCAP", "CTF_THEYCAP")
    SmartMessage(player, "#FF_YOUCAP", "#FF_TEAMCAP", "#FF_OTHERTEAMCAP")

end

blue_my_cap = my_cap:new({team = Team.kBlue,
			  item = {"green_flag"}})
-- This only lets blue capture the green flag
-- perhaps instead you want :
-- item = {"blue_flag","yellow_flag","green_flag"}})

red_my_cap = my_cap:new({team = Team.kRed,
			 item = {"yellow_flag"}})

yellow_my_cap = my_cap:new({team = Team.kYellow,
			  item = {"red_flag"}})

green_my_cap = my_cap:new({team = Team.kGreen,
			  item = {"blue_flag"}})
public_slots_free is offline   Reply With Quote


Old 03-10-2008, 10:12 PM   #10
Sidd
Lua Team
 
Join Date: Mar 2007
Posts Rated Helpful 1 Times
yeah, I didn't realise he wanted 2 different things doing depending on who captures.

Which is one example why you should use small functions to group even a few lines of code.
Sidd 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 01:52 AM.


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