Fortress Forever

Go Back   Fortress Forever > Editing > Mapping > Lua

Reply
 
Thread Tools Display Modes
Old 06-15-2013, 01:42 AM   #1
Agent Buckshot Moose
Wiki Standards Team
Wiki Team
 
Agent Buckshot Moose's Avatar
 
Join Date: Mar 2007
Location: Geokill's closet
Class/Position: Sniper/Demoman
Gametype: CTF
Affiliations: :e0: Co-leader
Posts Rated Helpful 6 Times
LUA server "plugins"

Is it possible to:

1. Make a lua file that affects all maps of a certain game mode, either by a specially recognized filename, a symbolic link, etc?
2. Make a plugin that does things based on number of players in the server, e.g. if number of player is >= X, do action Y. If number of players is < X, do action Z?
Agent Buckshot Moose is offline   Reply With Quote


Old 06-15-2013, 05:41 AM   #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.
1. A few possibilities:
  • map .cfg files (cfg/ff_dustbowl.cfg, cfg/ff_ksour.cfg, etc) that set sv_globalluascript and a server.cfg that resets it to blank or something else
  • add an IncludeScript() line to the gametype's base include (base_ad, etc) that includes your file
  • maybe more than I can't think of right now
2. Absolutely. This will count only players on a playable team (blue through green):
Code:
local numplayers = 0
for team_id = Team.kBlue, Team.kGreen do
	numplayers += GetTeam( team_id ):GetNumPlayers()
end
Including spectators:
Code:
local numplayers = 0
for team_id = Team.kSpectator, Team.kGreen do
	numplayers += GetTeam( team_id ):GetNumPlayers()
end
Including spectators and unassigned:
Code:
local numplayers = 0
for team_id = Team.kUnassigned, Team.kGreen do
	numplayers += GetTeam( team_id ):GetNumPlayers()
end
EDIT: To react to changes in player number immediately, you can use the callback functions player_disconnected( player ) and player_switchteam( player, old_team_id, new_team_id )
__________________
#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

Last edited by squeek.; 06-15-2013 at 05:43 AM.
squeek. is offline   Reply With Quote


Old 06-15-2013, 03:05 PM   #3
Agent Buckshot Moose
Wiki Standards Team
Wiki Team
 
Agent Buckshot Moose's Avatar
 
Join Date: Mar 2007
Location: Geokill's closet
Class/Position: Sniper/Demoman
Gametype: CTF
Affiliations: :e0: Co-leader
Posts Rated Helpful 6 Times
Next question: looking at the documentation for SetTeamClassLimit and SetSmartClassLimit, it says those must go in the startup() function. Is it possible to change class limits via the callback?

Edit: like a simple function that sets a server-side cvar. I see one that sets player cvar, but not one that sets server cvars.

Last edited by Agent Buckshot Moose; 06-15-2013 at 03:10 PM.
Agent Buckshot Moose is offline   Reply With Quote


Old 06-15-2013, 07: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.
Class limits can be changed anytime using those functions. The "must be in startup" thing is just for setting up the initial class limits.

To set a server cvar, you can use SetConvar( convar, value )

EDIT: Changing class limits won't immediately enforce those limits (it'll just make it so players wouldn't be able to choose/switch to that class afterwards). To enforce the limit immediately, you'd have to manually switch players playing the now-forbidden class(es) using ApplyToPlayer( player, { AT.kChangeClassSolder, AT.kRespawnPlayers } ) or something like that.

This sort of thing is done in ff_ksour to disable scouts on Defense.

EDIT#2: The ksour code:
in player_spawn:
Code:
	-- wtf, scout or med on d? are you mental?
	if (player:GetClass() == Player.kScout or player:GetClass() == Player.kMedic) and (player:GetTeamId() == defenders) then
		local classt = "Scout"
		if player:GetClass() == Player.kMedic then classt = "Medic" end
		local id = player:GetId()
		AddSchedule("force_changemessage"..id, 2, schedulechangemessage, player, "No "..classt.."s on defense. Autoswitching to Soldier." )
		AddSchedule("force_change"..id, 2.5, forcechange, player)
	end
The scheduled forcechange function:
Code:
-- force a scout/med to switch to soli if they haven't
function forcechange( player )
	if (player:GetClass() == Player.kScout or player:GetClass() == Player.kMedic) and (player:GetTeamId() == defenders) then
		ApplyToPlayer( player, { AT.kChangeClassSoldier, AT.kRespawnPlayers } )
	end
end
__________________
#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

Last edited by squeek.; 06-15-2013 at 08:04 PM.
squeek. is offline   Reply With Quote


Old 06-15-2013, 08:08 PM   #5
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.
By the way, for this sort of thing, understanding and using the concepts in this thread: Altering functions without overwriting them is quite important.

If done right, it'll allow you to use the Lua on any map without breaking anything. If you overwrite an important function like startup, though, things could really break (or if you copy+paste a specific startup function then it'll only work for some maps).

It's still not a perfect system, and the base includes should be restructured to allow for easier/more robust manipulating, but that hasn't happened yet.
__________________
#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

Last edited by squeek.; 06-15-2013 at 08:08 PM.
squeek. 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 07:11 AM.


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