03-30-2009, 10:01 PM | #1 |
get off my lawn
Join Date: Mar 2007
Class/Position: O scout / demo Gametype: killing Posts Rated Helpful 0 Times
|
Remove Weapon and Switch Teams
I need two separate functions for my map:
1] Remove shotgun. Just stripping ammo doesnt help cause it's still got 8 rounds. Code:
function player_spawn( player_entity ) -- 400 for overkill. of course the values -- get clamped in game code --local player = GetPlayer(player_id) local player = CastToPlayer( player_entity ) player:AddHealth( 400 ) player:AddArmor( 400 ) player:RemoveAmmo( Ammo.kNails, 500 ) player:RemoveAmmo( Ammo.kShells, 500 ) player:RemoveAmmo( Ammo.kManCannon, 500 ) player:RemoveAmmo( Ammo.kGren1, 500 ) player:RemoveAmmo( Ammo.kGren2, 500 ) player:RemoveWeapon(ff_weapon_shotgun) end Similarly player:RemoveAllWeapons() works, but if I try to player:GiveWeapon(ff_weapon_crowbar) I crash as soon as I spawn. 2] How do I make players change teams following a kill? I'm looking for Blue player kills Red player. Red respawns as blue, and Blue respawns immediately as red.
__________________
That means that either you are an American, or you are NOT an American. There is no hyphenated exception. -Iggy |
|
03-30-2009, 10:14 PM | #2 |
Stuff Do-er
Lua Team
Wiki Team Fortress Forever Staff |
For RemoveWeapon( weapon ), The weapon name has to be passed as a string.
Code:
player:RemoveWeapon("ff_weapon_shotgun") For teamswitching: Without respawn: Code:
ApplyToPlayer( player, { AT.kChangeTeamBlue } ) Code:
ApplyToPlayer( player, { AT.kChangeTeamBlue, AT.kRespawnPlayers } ) Code:
function player_killed( player, damageinfo ) -- if no damageinfo do nothing if not damageinfo then return end -- Entity that is attacking local attacker = damageinfo:GetAttacker() -- If no attacker do nothing if not attacker then return end local player_attacker = nil -- get the attacking player if IsPlayer(attacker) then attacker = CastToPlayer(attacker) player_attacker = attacker elseif IsSentrygun(attacker) then attacker = CastToSentrygun(attacker) player_attacker = attacker:GetOwner() elseif IsDetpack(attacker) then attacker = CastToDetpack(attacker) player_attacker = attacker:GetOwner() elseif IsDispenser(attacker) then attacker = CastToDispenser(attacker) player_attacker = attacker:GetOwner() else return end -- if still no attacking player after all that, forget about it if not player_attacker then return end -- If player killed self or teammate do nothing if (player:GetId() == player_attacker:GetId()) or (player:GetTeamId() == player_attacker:GetTeamId()) then return end -- If attacker is blue, switch teams accordingly if player_attacker:GetTeamId() == Team.kBlue then -- switch attacker to red ApplyToPlayer( player_attacker, { AT.kChangeTeamRed, AT.kRespawnPlayers } ) -- switch victim to blue ApplyToPlayer( player, { AT.kChangeTeamBlue, AT.kRespawnPlayers } ) -- If attacker is red, switch teams accordingly elseif player_attacker:GetTeamId() == Team.kRed then -- switch attacker to blue ApplyToPlayer( player_attacker, { AT.kChangeTeamBlue, AT.kRespawnPlayers } ) -- switch victim to red ApplyToPlayer( player, { AT.kChangeTeamRed, 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 |
|
03-30-2009, 10:39 PM | #3 |
get off my lawn
Join Date: Mar 2007
Class/Position: O scout / demo Gametype: killing Posts Rated Helpful 0 Times
|
Thanks! the weapon strip works, I'm dl'ing FF on my roommates computer to test the teamswitch.
__________________
That means that either you are an American, or you are NOT an American. There is no hyphenated exception. -Iggy |
|
03-31-2009, 12:57 AM | #4 |
get off my lawn
Join Date: Mar 2007
Class/Position: O scout / demo Gametype: killing Posts Rated Helpful 0 Times
|
Okay I removed the teamchange when red kills blue, and this works great.
Now I'd like to add the following: 1]If red dies by fall damage / trigger hurt, change him to blue. then change random blue player to red. 2]If there are at least 2 blues and no red, auto change one random blue player to red. Here's what I've got now Code:
function player_killed( player, damageinfo ) -- if no damageinfo do nothing if not damageinfo then return end -- Entity that is attacking local attacker = damageinfo:GetAttacker() -- If no attacker do nothing if not attacker then return end local player_attacker = nil -- get the attacking player if IsPlayer(attacker) then attacker = CastToPlayer(attacker) player_attacker = attacker elseif IsSentrygun(attacker) then attacker = CastToSentrygun(attacker) player_attacker = attacker:GetOwner() elseif IsDetpack(attacker) then attacker = CastToDetpack(attacker) player_attacker = attacker:GetOwner() elseif IsDispenser(attacker) then attacker = CastToDispenser(attacker) player_attacker = attacker:GetOwner() else return end -- if still no attacking player after all that, forget about it if not player_attacker then return end -- If player killed self or teammate do nothing if (player:GetId() == player_attacker:GetId()) or (player:GetTeamId() == player_attacker:GetTeamId()) then return end -- If attacker is blue, switch teams accordingly if player_attacker:GetTeamId() == Team.kBlue then -- switch victim to blue ApplyToPlayer( player, { AT.kChangeTeamBlue, AT.kRespawnPlayers } ) -- switch attacker to red ApplyToPlayer( player_attacker, { AT.kChangeTeamRed, AT.kRespawnPlayers } ) -- If attacker is red, switch teams accordingly --elseif player_attacker:GetTeamId() == Team.kRed then -- switch attacker to blue --ApplyToPlayer( player_attacker, { AT.kChangeTeamBlue, AT.kRespawnPlayers } ) -- switch victim to red --ApplyToPlayer( player, { AT.kChangeTeamRed, AT.kRespawnPlayers } ) end end
__________________
That means that either you are an American, or you are NOT an American. There is no hyphenated exception. -Iggy |
|
03-31-2009, 01:19 AM | #5 |
Stuff Do-er
Lua Team
Wiki Team Fortress Forever Staff |
Code:
function player_killed( player, damageinfo ) -- if no damageinfo do nothing if not damageinfo then return end -- if a red player dies from fall damage if damageinfo:GetDamageType() == Damage.kFall and player:GetTeamId() == Team.kRed then -- switch victim to blue ApplyToPlayer( player, { AT.kChangeTeamBlue, AT.kRespawnPlayers } ) random_blue_to_red() end -- Entity that is attacking local attacker = damageinfo:GetAttacker() -- If no attacker do nothing if not attacker then return end local player_attacker = nil -- get the attacking player if IsPlayer(attacker) then attacker = CastToPlayer(attacker) player_attacker = attacker elseif IsSentrygun(attacker) then attacker = CastToSentrygun(attacker) player_attacker = attacker:GetOwner() elseif IsDetpack(attacker) then attacker = CastToDetpack(attacker) player_attacker = attacker:GetOwner() elseif IsDispenser(attacker) then attacker = CastToDispenser(attacker) player_attacker = attacker:GetOwner() else return end -- if still no attacking player after all that, forget about it if not player_attacker then return end -- If player killed self or teammate do nothing if (player:GetId() == player_attacker:GetId()) or (player:GetTeamId() == player_attacker:GetTeamId()) then return end -- If attacker is blue, switch teams accordingly if player_attacker:GetTeamId() == Team.kBlue then -- switch attacker to red ApplyToPlayer( player_attacker, { AT.kChangeTeamRed, AT.kRespawnPlayers } ) -- switch victim to blue ApplyToPlayer( player, { AT.kChangeTeamBlue, AT.kRespawnPlayers } ) end end function random_blue_to_red() local c = Collection() -- get all blue players c:GetByFilter({CF.kPlayers, CF.kTeamBlue}) -- generate random number local i = math.random( c:Count() ) local randomplayer = c:Element( i ) ApplyToPlayer( randomplayer, { AT.kChangeTeamRed, AT.kRespawnPlayers } ) end function check_teams() if GetTeam( Team.kBlue ):GetNumPlayers() >= 2 and GetTeam( Team.kRed ):GetNumPlayers() < 1 then random_blue_to_red() end end Code:
AddScheduleRepeating( "check_teams", 1, check_teams )
__________________
#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.; 03-31-2009 at 02:43 AM. |
|
03-31-2009, 01:48 AM | #6 |
get off my lawn
Join Date: Mar 2007
Class/Position: O scout / demo Gametype: killing Posts Rated Helpful 0 Times
|
It's not working for some reason. It still will change blue killer to red, like before, but it won't auto change a blue when red is empty, and it won't change red to blue if he dies from trigger_hurt.
I get this error in console when red dies from trigger hurt: [SCRIPT] Error calling player_killed (no overload of 'Damage:GetDamageType' matched the arguments (const Damage) candidates are: Damage:GetDamageType() ) ent: NULL Here's the entirety of what I've got. Code:
IncludeScript("base_teamplay"); function startup() -- set up team limits (only red & blue) SetPlayerLimit( Team.kBlue, 0 ) SetPlayerLimit( Team.kRed, 1 ) SetPlayerLimit( Team.kYellow, -1 ) SetPlayerLimit( Team.kGreen, -1 ) local team = GetTeam(Team.kBlue) team:SetClassLimit(Player.kDemoman, -1) team:SetClassLimit(Player.kCivilian, -1) team:SetClassLimit(Player.kSoldier, -1) team:SetClassLimit(Player.kHwguy, -1) team:SetClassLimit(Player.kSpy, -1) team:SetClassLimit(Player.kSniper, -1) team:SetClassLimit(Player.kPyro, -1) team:SetClassLimit(Player.kEngineer, -1) team:SetClassLimit(Player.kMedic, -1) local team = GetTeam(Team.kRed) team:SetClassLimit(Player.kDemoman, -1) team:SetClassLimit(Player.kCivilian, -1) team:SetClassLimit(Player.kSoldier, -1) team:SetClassLimit(Player.kHwguy, -1) team:SetClassLimit(Player.kSpy, -1) team:SetClassLimit(Player.kSniper, -1) team:SetClassLimit(Player.kPyro, -1) team:SetClassLimit(Player.kEngineer, -1) team:SetClassLimit(Player.kMedic, -1) SetTeamName( Team.kBlue, "Feral Daschunds" ) SetTeamName( Team.kRed, "Warrior King" ) AddScheduleRepeating( "check_teams", 1, check_teams ) end -- Everyone to spawns with nothing function player_spawn( player_entity ) -- 400 for overkill. of course the values -- get clamped in game code --local player = GetPlayer(player_id) local player = CastToPlayer( player_entity ) player:AddHealth( 400 ) player:AddArmor( 400 ) player:RemoveAmmo( Ammo.kNails, 500 ) player:RemoveAmmo( Ammo.kShells, 500 ) player:RemoveAmmo( Ammo.kManCannon, 1) player:RemoveAmmo( Ammo.kGren1, 500 ) player:RemoveAmmo( Ammo.kGren2, 500 ) player:RemoveWeapon("ff_weapon_shotgun") end function player_onkill( player ) -- Test, Don't let blue team suicide. if player:GetTeamId() == Team.Red then return false end return true end function player_killed( player, damageinfo ) -- if no damageinfo do nothing if not damageinfo then return end -- if a red player dies from fall damage if damageinfo:GetDamageType() == DamageTypes.kFall and player:GetTeamId() == Team.kRed then -- switch victim to blue ApplyToPlayer( player, { AT.kChangeTeamBlue, AT.kRespawnPlayers } ) random_blue_to_red() end -- Entity that is attacking local attacker = damageinfo:GetAttacker() -- If no attacker do nothing if not attacker then return end local player_attacker = nil -- get the attacking player if IsPlayer(attacker) then attacker = CastToPlayer(attacker) player_attacker = attacker elseif IsSentrygun(attacker) then attacker = CastToSentrygun(attacker) player_attacker = attacker:GetOwner() elseif IsDetpack(attacker) then attacker = CastToDetpack(attacker) player_attacker = attacker:GetOwner() elseif IsDispenser(attacker) then attacker = CastToDispenser(attacker) player_attacker = attacker:GetOwner() else return end -- if still no attacking player after all that, forget about it if not player_attacker then return end -- If player killed self or teammate do nothing if (player:GetId() == player_attacker:GetId()) or (player:GetTeamId() == player_attacker:GetTeamId()) then return end -- If attacker is blue, switch teams accordingly if player_attacker:GetTeamId() == Team.kBlue then -- switch attacker to red ApplyToPlayer( player_attacker, { AT.kChangeTeamRed, AT.kRespawnPlayers } ) -- switch victim to blue ApplyToPlayer( player, { AT.kChangeTeamBlue, AT.kRespawnPlayers } ) end end function random_blue_to_red() local c = Collection() -- get all blue players c:GetByFilter({CF.kPlayers, CF.kTeamBlue}) -- generate random number local i = math.random( c:Count() ) local randomplayer = c:Element( i ) ApplyToPlayer( randomplayer, { AT.kChangeTeamRed, AT.kRespawnPlayers } ) end function check_teams() if GetTeam( Team.kBlue ):GetNumPlayers() >= 2 and GetTeam( Team.kRed ):GetNumPlayers() < 1 then random_blue_to_red() end end -- Just here because function player_ondamage( player_entity, damageinfo ) end
__________________
That means that either you are an American, or you are NOT an American. There is no hyphenated exception. -Iggy Last edited by fishBurger; 03-31-2009 at 02:11 AM. Reason: added |
|
03-31-2009, 02:43 AM | #7 |
Stuff Do-er
Lua Team
Wiki Team Fortress Forever Staff |
Oops. Change
Code:
DamageTypes.kFall Code:
Damage.kFall Code:
if damageinfo:GetDamageType() == DamageTypes.kFall and player:GetTeamId() == Team.kRed then
__________________
#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 |
|
03-31-2009, 03:07 AM | #8 |
get off my lawn
Join Date: Mar 2007
Class/Position: O scout / demo Gametype: killing Posts Rated Helpful 0 Times
|
Unfortunately not the problem. No change as far as I can tell.
I still get Code:
[SCRIPT] Error calling player_killed (no overload of 'Damage:GetDamageType' matched the arguments (const Damage) candidates are: Damage:GetDamageType() ) ent: NULL
__________________
That means that either you are an American, or you are NOT an American. There is no hyphenated exception. -Iggy |
|
03-31-2009, 04:55 AM | #9 |
get off my lawn
Join Date: Mar 2007
Class/Position: O scout / demo Gametype: killing Posts Rated Helpful 0 Times
|
would it be easier LUA-wise to remove the kill from the trigger, and let LUA handle what happens on touch?
Red -> Teamchange to blue. Blue -> Kill. If that's easier to work / troubleshoot / accomplish, I could do that instead.
__________________
That means that either you are an American, or you are NOT an American. There is no hyphenated exception. -Iggy |
|
03-31-2009, 06:01 AM | #10 | |
Stuff Do-er
Lua Team
Wiki Team Fortress Forever Staff |
Quote:
Take this out of player_killed() Code:
-- if a red player dies from fall damage if damageinfo:GetDamageType() == DamageTypes.kFall and player:GetTeamId() == Team.kRed then -- switch victim to blue ApplyToPlayer( player, { AT.kChangeTeamBlue, AT.kRespawnPlayers } ) random_blue_to_red() end Code:
falltrigger = trigger_ff_script:new({ team = Team.kRed }) function falltrigger:ontouch( touch_entity ) if IsPlayer( touch_entity ) then local player = CastToPlayer( touch_entity ) -- if is on right team if player:GetTeamId() == self.team then -- switch victim to blue ApplyToPlayer( player, { AT.kChangeTeamBlue, AT.kKillPlayers } ) -- switch random blue player to red random_blue_to_red() end 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 |
|
|
03-31-2009, 06:15 PM | #11 |
get off my lawn
Join Date: Mar 2007
Class/Position: O scout / demo Gametype: killing Posts Rated Helpful 0 Times
|
Sweet, that works. All that's left is autoswitching a random Blue to Red.
I added a broadcast inside the random_blue_to_red function, and it triggers fine, but doesn't work. if the broadcast calls for the randomplayer the function created, it doesn't find anything. [SCRIPT] Error calling ontouch ([string "maps\ff_crowbarfrenzy_b1.lua"]:131: attempt to concatenate local 'randomplayer' (a nil value)) ent: falltrigger
__________________
That means that either you are an American, or you are NOT an American. There is no hyphenated exception. -Iggy |
|
03-31-2009, 08:36 PM | #12 |
Stuff Do-er
Lua Team
Wiki Team Fortress Forever Staff |
Try this:
Code:
function random_blue_to_red() local c = Collection() -- get all blue players c:GetByFilter({CF.kPlayers, CF.kTeamBlue}) -- generate random number local i = math.random( 0, c:Count() - 1 ) local randomplayer = c:Element( i ) ApplyToPlayer( randomplayer, { AT.kChangeTeamRed, AT.kRespawnPlayers } ) 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 |
|
03-31-2009, 11:28 PM | #13 |
get off my lawn
Join Date: Mar 2007
Class/Position: O scout / demo Gametype: killing Posts Rated Helpful 0 Times
|
no luck. Still triggers, but I dont think randomplayer is getting assigned a player, if that makes sense. I'm getting this message, might be relevant, might not:
[SCRIPT] Error calling ontouch (no match for function call 'ApplyToPlayer' with the parameters (BaseEntity, table) candidates are: ApplyToPlayer(Player*, object)
__________________
That means that either you are an American, or you are NOT an American. There is no hyphenated exception. -Iggy |
|
04-01-2009, 12:55 AM | #14 |
Stuff Do-er
Lua Team
Wiki Team Fortress Forever Staff |
Code:
function random_blue_to_red() local c = Collection() -- get all blue players c:GetByFilter({CF.kPlayers, CF.kTeamBlue}) -- generate random number local i = math.random( 0, c:Count() - 1 ) local randomplayer = CastToPlayer( c:Element( i ) ) ApplyToPlayer( randomplayer, { AT.kChangeTeamRed, AT.kRespawnPlayers } ) 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 |
|
04-01-2009, 03:47 AM | #15 |
get off my lawn
Join Date: Mar 2007
Class/Position: O scout / demo Gametype: killing Posts Rated Helpful 0 Times
|
That did it. Thanks for the help, Lua Wizard.
__________________
That means that either you are an American, or you are NOT an American. There is no hyphenated exception. -Iggy |
|
04-01-2009, 03:57 AM | #16 |
Stuff Do-er
Lua Team
Wiki Team Fortress Forever Staff |
No problem. Now let's see this crazy map of yours.
__________________
#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 |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|