Fortress Forever

Go Back   Fortress Forever > Editing > Mapping > Lua

Reply
 
Thread Tools Display Modes
Old 10-19-2013, 07:07 PM   #1
rdrt
Beta Tester
 
Join Date: Sep 2008
Gametype: Capture the Flag
Posts Rated Helpful 9 Times
4 team Last Man Standing LUA

Got it. Thx.

Last edited by rdrt; 10-19-2013 at 07:34 PM.
rdrt is offline   Reply With Quote


Old 10-19-2013, 07:57 PM   #2
Dexter
internet user
Fortress Forever Staff
 
Dexter's Avatar
 
Join Date: Jun 2007
Posts Rated Helpful 42 Times
can you post what you've got so far and what exactly isnt working/any error messages? i'll give it a shot
__________________
9:17 PM - DEXTER: can you teach me how to play o
9:17 PM - squeek.: you jump a lot
9:18 PM - squeek.: and do sweet moves

8:55 PM - FDA: fart in you fridge and blame it on wild animals
Dexter is offline   Reply With Quote


Old 10-19-2013, 08:01 PM   #3
rdrt
Beta Tester
 
Join Date: Sep 2008
Gametype: Capture the Flag
Posts Rated Helpful 9 Times
Thanks a lot Dexter. Fortunately I did figure it out using the available LMS LUA for 2 teams. I also removed the zero-self-damage. This is what works below.

IncludeScript("base_teamplay");


---------------------------------
-- Global Variables (these can be changed to whatever you want)
---------------------------------

TEAM_POINTS_PER_WIN = 1
BLUE_TEAM_NAME = "Blue team"
RED_TEAM_NAME = "Red team"
GREEN_TEAM_NAME = "Green team"
YELLOW_TEAM_NAME = "Yellow team"


---------------------------------
-- Functions
---------------------------------

function startup()
-- set up team limits
SetPlayerLimit( Team.kBlue, 0 )
SetPlayerLimit( Team.kRed, 0 )
SetPlayerLimit( Team.kYellow, 0 )
SetPlayerLimit( Team.kGreen, 0 )

SetTeamName( Team.kRed, RED_TEAM_NAME )
SetTeamName( Team.kBlue, BLUE_TEAM_NAME )
SetTeamName( Team.kGreen, GREEN_TEAM_NAME )
SetTeamName( Team.kYellow, YELLOW_TEAM_NAME )

-- Blue Team Class limits
local team = GetTeam( Team.kBlue )
team:SetClassLimit( Player.kSoldier, 0 )
team:SetClassLimit( Player.kDemoman, 0 )
team:SetClassLimit( Player.kCivilian, 0 )
team:SetClassLimit( Player.kPyro, 0 )
team:SetClassLimit( Player.kScout, 0 )
team:SetClassLimit( Player.kMedic, 0 )
team:SetClassLimit( Player.kSniper, 0 )
team:SetClassLimit( Player.kHwguy, 0 )
team:SetClassLimit( Player.kSpy, 0 )
team:SetClassLimit( Player.kEngineer, 0 )
team:SetClassLimit( Player.kCivilian, 0 )

-- Red Team class limits
team = GetTeam( Team.kRed )
team:SetClassLimit( Player.kSoldier, 0 )
team:SetClassLimit( Player.kDemoman, 0 )
team:SetClassLimit( Player.kCivilian, 0 )
team:SetClassLimit( Player.kPyro, 0 )
team:SetClassLimit( Player.kScout, 0 )
team:SetClassLimit( Player.kMedic, 0 )
team:SetClassLimit( Player.kSniper, 0 )
team:SetClassLimit( Player.kHwguy, 0 )
team:SetClassLimit( Player.kSpy, 0 )
team:SetClassLimit( Player.kEngineer, 0 )
team:SetClassLimit( Player.kCivilian, 0 )

-- Green Team class limits
team = GetTeam( Team.kGreen )
team:SetClassLimit( Player.kSoldier, 0 )
team:SetClassLimit( Player.kDemoman, 0 )
team:SetClassLimit( Player.kCivilian, 0 )
team:SetClassLimit( Player.kPyro, 0 )
team:SetClassLimit( Player.kScout, 0 )
team:SetClassLimit( Player.kMedic, 0 )
team:SetClassLimit( Player.kSniper, 0 )
team:SetClassLimit( Player.kHwguy, 0 )
team:SetClassLimit( Player.kSpy, 0 )
team:SetClassLimit( Player.kEngineer, 0 )
team:SetClassLimit( Player.kCivilian, 0 )

-- Yellow Team class limits
team = GetTeam( Team.kYellow )
team:SetClassLimit( Player.kSoldier, 0 )
team:SetClassLimit( Player.kDemoman, 0 )
team:SetClassLimit( Player.kCivilian, 0 )
team:SetClassLimit( Player.kPyro, 0 )
team:SetClassLimit( Player.kScout, 0 )
team:SetClassLimit( Player.kMedic, 0 )
team:SetClassLimit( Player.kSniper, 0 )
team:SetClassLimit( Player.kHwguy, 0 )
team:SetClassLimit( Player.kSpy, 0 )
team:SetClassLimit( Player.kEngineer, 0 )
team:SetClassLimit( Player.kCivilian, 0 )

end


-- Everyone to spawn with everything.
function player_spawn( player_entity )
local player = CastToPlayer( player_entity )
player:AddHealth( 400 )
player:AddArmor( 400 )

player:AddAmmo( Ammo.kNails, 400 )
player:AddAmmo( Ammo.kShells, 400 )
player:AddAmmo( Ammo.kRockets, 400 )
player:AddAmmo( Ammo.kCells, 400 )
player:AddAmmo( Ammo.kDetpack, 1 )
player:RemoveAmmo( Ammo.kGren2, 4 )
player:RemoveAmmo( Ammo.kGren1, 4 )
end

function precache()
PrecacheSound("misc.bloop")
end


-- Calls a function to check if a team has won every time someone dies
function player_killed( killed_entity )
local player = CastToPlayer( killed_entity )
player:Spectate ( SpecMode.kRoaming )
player:SetRespawnable( false )
CheckTeamAliveState( killed_entity)
end


function Spectate( player )
player:Spectate( SpecMode.kRoaming )
end


-- Checks to see if people are still alive. If one team is all dead, declare the other team the winners.
function CheckTeamAliveState(killed_player)
ConsoleToAll( "CheckTeamAliveState" )

local blue = Collection()
local red = Collection()
local green = Collection()
local yellow = Collection()

-- Filter players online into seperate teams. Ignore spectators.
blue:GetByFilter({ CF.kPlayers, CF.kTeamBlue })
red:GetByFilter({ CF.kPlayers, CF.kTeamRed })
green:GetByFilter({ CF.kPlayers, CF.kTeamGreen })
yellow:GetByFilter({ CF.kPlayers, CF.kTeamYellow })

-- If either team has no players, then exit. Just one person running about shouldn't get boxed up.
if (blue:Count() == 0) or (red:Count() == 0) or (green:Count() == 0) or (yellow:Count() == 0) then
AddSchedule("respawnall", 1 , respawnall)
end


local bAlive = 0
local rAlive = 0
local gAlive = 0
local yAlive = 0

-- Check all blue team players to see who is still alive
for temp in blue.items do
local player = CastToPlayer( temp )
if player:IsAlive() then
bAlive = bAlive + 1
end
end

-- Same for red
for temp in red.items do
local player = CastToPlayer( temp )
if player:IsAlive() then
rAlive = rAlive + 1
end
end

-- Same for green
for temp in green.items do
local player = CastToPlayer( temp )
if player:IsAlive() then
gAlive = gAlive + 1
end
end

-- Same for yellow
for temp in yellow.items do
local player = CastToPlayer( temp )
if player:IsAlive() then
yAlive = yAlive + 1
end
end

-- checks to see if either team is all dead. If so, declare other team the winner, and start new round. If not, set the killed player to spectate
if (bAlive >= 1) and (rAlive == 0) and (gAlive == 0) and (yAlive == 0) then
BroadCastMessage(BLUE_TEAM_NAME .. " wins!")
BroadCastSound( "misc.bloop" )
local team = GetTeam (Team.kBlue)
team:AddScore(TEAM_POINTS_PER_WIN)
AddSchedule("respawnall", 3 , respawnall)
elseif (rAlive >= 1) and (bAlive == 0) and (gAlive == 0) and (yAlive == 0) then
BroadCastMessage(RED_TEAM_NAME .. " wins!")
BroadCastSound( "misc.bloop" )
local team = GetTeam (Team.kRed)
team:AddScore(TEAM_POINTS_PER_WIN)
AddSchedule("respawnall", 3 , respawnall)
elseif (gAlive >= 1) and (bAlive == 0) and (rAlive == 0) and (yAlive == 0) then
BroadCastMessage(GREEN_TEAM_NAME .. " wins!")
BroadCastSound( "misc.bloop" )
local team = GetTeam (Team.kGreen)
team:AddScore(TEAM_POINTS_PER_WIN)
AddSchedule("respawnall", 3 , respawnall)
elseif (yAlive >= 1) and (bAlive == 0) and (rAlive == 0) and (gAlive == 0) then
BroadCastMessage(YELLOW_TEAM_NAME .. " wins!")
BroadCastSound( "misc.bloop" )
local team = GetTeam (Team.kYellow)
team:AddScore(TEAM_POINTS_PER_WIN)
AddSchedule("respawnall", 3 , respawnall)
else
return
end
end


-- Respawns all players.
function RespawnEveryone()
ApplyToAll({ AT.kRemovePacks, AT.kRemoveProjectiles, AT.kRespawnPlayers, AT.kRemoveBuildables, AT.kRemoveRagdolls, AT.kStopPrimedGrens, AT.kReloadClips, AT.kAllowRespawn, AT.kReturnDroppedItems })
end


---------------------------------
-- Scheduled functions
---------------------------------

function respawnall()
RespawnEveryone()
end



-----------------------------------------------------------------------------
-- spawn validty checking
-----------------------------------------------------------------------------

-- makes sure the VIP can only spawn in their teams base
normal_spawn = info_ff_teamspawn:new({ validspawn = function(self, player)
return EVENT_ALLOWED
end})

-- Ties the map's spawn entities to the above functions
normalspawn = normal_spawn:new()

-- team spawns, if wanted
team_spawn = info_ff_teamspawn:new({ validspawn = function(self, player)
return player:GetTeamId() == self.team
end})

bluespawn = team_spawn:new({ team = Team.kBlue })
redspawn = team_spawn:new({ team = Team.kRed })
greenspawn = team_spawn:new({ team = Team.kGreen })
yellowspawn = team_spawn:new({ team = Team.kYellow })
rdrt is offline   Reply With Quote


Old 10-19-2013, 08:11 PM   #4
Dexter
internet user
Fortress Forever Staff
 
Dexter's Avatar
 
Join Date: Jun 2007
Posts Rated Helpful 42 Times
ah cool
__________________
9:17 PM - DEXTER: can you teach me how to play o
9:17 PM - squeek.: you jump a lot
9:18 PM - squeek.: and do sweet moves

8:55 PM - FDA: fart in you fridge and blame it on wild animals
Dexter is offline   Reply With Quote


Old 10-28-2013, 04:31 AM   #5
rdrt
Beta Tester
 
Join Date: Sep 2008
Gametype: Capture the Flag
Posts Rated Helpful 9 Times
After some playtesting, the above code works if n=2, however after the first kill even if players left are >1 the map will reset. I'm going to work with the code a bit as I think it is just a matter of added green and yellow teams somewhere, but someone with more experience may recognize what to do easily. Thanks in advance.
rdrt is offline   Reply With Quote


Old 11-26-2013, 11:59 PM   #6
rdrt
Beta Tester
 
Join Date: Sep 2008
Gametype: Capture the Flag
Posts Rated Helpful 9 Times
bump

Wanted to see if anyone might be able to help. The above code works correctly when 2 people are playing, however with three or more players, once the first frag occurs, the map resets. The code was originally made for 2 players and I would like to apply it to a 4 player map. The code in the original post has some modification as far as adding in the green and yellow teams, however it's very base and I need help with the nuances. Anyone please? Thanks in advance!
rdrt is offline   Reply With Quote


Old 11-28-2013, 11:09 PM   #7
ddm999
worst ff player eu
 
Join Date: Jun 2012
Location: South Yorks., England
Class/Position: o - no, d - scout
Gametype: IvDZ
Posts Rated Helpful 18 Times
I think you should remove this:
-- If either team has no players, then exit. Just one person running about shouldn't get boxed up.
if (blue:Count() == 0) or (red:Count() == 0) or (green:Count() == 0) or (yellow:Count() == 0) then
AddSchedule("respawnall", 1 , respawnall)
end




It skips game winning if any team has 0 players, meaning it'll only work with 4 players (one per team). That code is part of CheckTeamAliveState, so it is run on a kill.


If I'm right, then with 2 players your game isn't actually working, and neither team will be getting points, messages, etc. It will just reset in 1 second (should reset in 3 with points added, a message onscreen and a bloop sound effect).


-- If there aren't 2 players, speed up respawn and disable points for the 1 person / no-one.
if (blue:Count() + red:Count() + green:Count() + yellow:Count() < 2) then
AddSchedule("respawnall", 1 , respawnall)
end



If everything I've said before works, plonk this in where the old code was. Bear in mind that if there are 2+ players, but they are on the same team, it will causes the team to receive points if one suicides. I may be able to make some code tomorrow that only allows teams with the least players to be picked to be joined.


Hope this works for you.
__________________
gg ff not ded
ff very much alive
ddm999 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 05:24 AM.


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