[B]Last Prop Standing script[/B]

I’m looking for a code for prop hunt that gives the last prop a weapon. I’ve tried creating my own but nothing works.
I’ve only seen a few servers that had this feature, so finding a code is next to impossible.

Here is a code that might be helpful, its the class_hunter.lua

[lua]// Called by spawn and sets loadout
function CLASS:Loadout(pl)
pl:Give(“weapon_crowbar”)
pl:GiveAmmo(64, “Buckshot”)
pl:GiveAmmo(255, “SMG1”)
pl:Give(“weapon_shotgun”)
pl:Give(“weapon_smg1”)

if GetConVar("WEAPONS_ALLOW_GRENADE"):GetBool() then
	pl:Give("item_ar2_grenade")
end

local cl_defaultweapon = pl:GetInfo("cl_defaultweapon") 
 
if pl:HasWeapon(cl_defaultweapon) then 
	pl:SelectWeapon(cl_defaultweapon)
end 

end[/lua]

and here is class_prop.lua

[lua]// Called by spawn and sets loadout
function CLASS:Loadout(pl)
// Props dont get weapons.
end[/lua]

Since props don’t gets weapons by default, I’m sure there is some other editing that needs to be done to make it work.
Any help with this would be greatly appreciated.

on player death hook

if num living props == 1

give him wep

that’s the pseudo kode, good luck

Still can’t figure it out. Only death call I have is this
[lua]function GM:CheckPlayerDeathRoundEnd()
if !GAMEMODE.RoundBased || !GAMEMODE:InRound() then
return
end

local Teams = GAMEMODE:GetTeamAliveCounts()



if table.Count(Teams) == 0 then
	GAMEMODE:RoundEndWithResult(1001, "Draw, everyone loses!")
	return
end

if table.Count(Teams) == 1 then
	local TeamID = table.GetFirstKey(Teams)
	GAMEMODE:RoundEndWithResult(TeamID, team.GetName(TeamID).." win!")
	return
end

end[/lua]

I’ve tried many different things but got nothing.
I’m kinda new to lua so I’m probably missing something simple.
Anyway, I’d appreciate a little more details on this.

The function GM:PlayerDeath isn’t what I’m having trouble with, its what comes after it.

[lua]function CheckLastProp()
local prop_alive = {}
for k,ply in pairs( team.GetPlayers(TEAM_PROP) ) do
if ply:Alive() then table.insert( prop_alive, ply ) end
end
if #prop_alive == 1 then prop_alive[1]:Give(“weapon_shotgun”) end
end
hook.Add(“PlayerDeath”, “KillOneGetGun”, CheckLastProp())
[/lua]
Pseudocode, didn’t tested it and could be totaly wrong

Nah doesnt work. I edited it around but still nothing. Thanks for trying to help though.

maybe linkin the prop hunt version would help.
also what did u edit speficly?

I know the prop hunt version I work with, the PlayerDeath hook doesn’t get called for props, because they are silently killed on death.

I don’t remember what I tried changing. But I am pretty sure its TEAM_PROPS, not PROP
Either way, I dont know much about lua/pseudo. I’ve just customized some basic codes is all.

This one is kicking my ass though cause I want it but cant figure it out.

and what do you mean linkin the prop hunt version?

the link. as Blasteh mentioned, you could try PlayerSilentDeath insteed of PlayerDeat in the hook.Add

Nah, still nothing.

Alright so I still cant get this one working. I’ve got it down to this.

[lua]
function CheckLastProp()
local prop_alive = {}
for k,ply in pairs( team.GetPlayers(TEAM_PROPS) ) do
if ply:Alive() then table.insert( prop_alive, ply ) end
end
if #prop_alive == “1” then prop_alive[1]:Give(“weapon_shotgun”) end
end
hook.Add(“CheckPlayerDeathRoundEnd”, “KillOneGetGun”, CheckLastProp())[/lua]

Please help if you know what the problem is. oh and I think CheckPlayerDeathRoundEnd is the only one prop hunt uses for deaths. Anyway, please help me figure this out.

PlayerDeath should still be called… But, because I don’t know much of anything at all about prop-hunt, consider this pseudo-code, albeit should work. If you know how many “props” you have at round start, save the number somewhere. On game-event player_disconnect, if player was prop, subtract 1 from our number. On hook PlayerDeath, if victim was prop, subtract 1 from our number.

Then, your CheckPlayerDeathRoundEnd would only need to see if the number is !( x > 0 ) or you can use ( x < 1 ) for round end; == 1 for your shotgun…

If you want to easily be able to target the last prop without going through a list, do this… On round start, grab all valid props. Add them to a table.

_table[ SteamID ] = PlayerObject;

On hook PlayerDeath, or game-event player_disconnect, if _table[ SteamID ] then _table[ SteamID ] = nil;
I’d also recommend having a counter variable too; saves time on table.Count… So subtract 1 in that case too…

If counter == 1 then _table[ table.GetFirstKey( _table ) ] is our player object… Give that prop the weapon.

#prop_alive == “1” is your problem. It shouldn’t be a string.

I think you made it way more complicated than it needs to be lol

In terms of “cost” and taking into consideration the small overhead ( references to player, plus storing steamid in a table; Lua is a language of tables so they’re very optimized… ), it’d be cheaper.

I scanned the thread, didn’t see any solution to the initial question ( of how to give last player weapon ) which is why I answered with making the counter / table system.

Looking at Disseminates’ post, he’s right but it is still more expensive.

I don’t know what you’re even talking about. What I’m saying is if the code that I already have can be fixed to work right then why would I go about doing that other jibbity jabbity stuff? I barely know what the hell I’m doing with basic coding, let alone all that other crap.

If we took my pseudocode for example, then we don’t need to check for disconnects, since it will empty the table everytime someone dies, then fill it up with all Players, if they are in the Team Props.
And only if the tablecount is 1, then it should give him the weapon. Maybe i’m wrong with #prop_alive == 1 and we should use if table.count(prop_alive) == 1 then

I just get an error with that

[ERROR] gamemodes/prop_hunt/gamemode/player_class/class_prop.lua:21: attempt to call field ‘count’ (a nil value)

  1. CheckLastProp - gamemodes/prop_hunt/gamemode/player_class/class_prop.lua:21
  2. unknown - gamemodes/prop_hunt/gamemode/player_class/class_prop.lua:23
    3. include - [C]:-1
    4. IncludePlayerClasses - gamemodes/prop_hunt/gamemode/fretta/gamemode/shared.lua:291
    5. unknown - gamemodes/prop_hunt/gamemode/sh_init.lua:14
    6. include - [C]:-1
    7. unknown - gamemodes/prop_hunt/gamemode/cl_init.lua:2