Armor/Armour for teams in Dark RP

I have made a module so that it sets armour for certain groups. However it only sets it after they die. This is a bit of a problem. Any way to get past this?
Regards
Adamski0811

It might help to see your code.

Use the hook PlayerSpawn

I’m happy to help you but I can’t help you if I can’t see your previous progress

Soon as I’m home from work ill post the code. Just want the module code?

Use the PlayerLoadout function assuming DarkRP uses the PlayerLoadout hook when people get a job. There’s a huge DarkRP help thread containing answers to many of these questions.

That’s in a module folder in the modification addon. You spawn in as a citizen with no armor. Once you change job you don’t get the armor. You only get it once you have died as that job

hook.Add(“PlayerSpawn”, “SomeUniqueName”, function(ply)
if ply:Team() == TEAM_CP then
ply:SetArmor( 15 )
elseif ply:Team() == TEAM_CHIEF then
ply:SetArmor( 25 )
elseif ply:Team() == TEAM_MAYOR then
ply:SetArmor( 50 )
else
ply:SetArmor( 0 )
end
end)

Posted with phone would not let me use code

The reason you only get the armor when you die is because you get it when you spawn.

Switch it to PlayerLoadout; and next time please use the DarkRP Thread :slight_smile:

According to:

[lua]function meta:ChangeTeam(t, force)[/lua]

It will call:

[lua]GAMEMODE:PlayerLoadout(self)[/lua]

Even though that should be a hook.Call.

If it doesn’t work when you change it to PlayerLoadout, edit the core file which has the meta:ChangeTeam. In the same function, change

[lua]GAMEMODE:PlayerLoadout(self)[/lua]
to
[lua]hook.Call( “PlayerLoadout”, GAMEMODE, self );[/lua]

I have it working on my server as this:


function TeamArmor( ply )
	if ply:Team() == TEAM_POLICE then
		ply:SetArmor( 25 )
	elseif ply:Team() == TEAM_CHIEF then
		ply:SetArmor( 50 )
	elseif ply:Team() == TEAM_SWAT then
		ply:SetArmor( 75 )
	elseif ply:Team() == TEAM_SWATC then
		ply:SetArmor( 100 )
	elseif ply:Team() == TEAM_SWATM then
		ply:SetArmor( 100 )
	elseif ply:Team() == TEAM_SWATS then
		ply:SetArmor( 100 )
	end
end
hook.Add( "PlayerLoadout", "TeamArmor", TeamArmor )

But you have to re spawn? What do I need to change Ace?

Can’t test yet will report back as soon as I can. Hoping that works wanting to open the server soon. Only just started learning LUA

I don’t run DarkRP; but quickly looking at the code, when a team is changed “function meta:ChangeTeam(t, force)” is called in player.lua line 207 on the version I have. In that function “GAMEMODE:PlayerLoadout(self)” is called on line 336, but not as a hook as it should be.

Change this on line 336 of player.lua within meta:ChangeTeam(t, force) function which goes from line 207 to line 341 ( meta for PLAYER )
[lua]GAMEMODE:PlayerLoadout(self)[/lua]
to

this on line 336
[lua]hook.Call( “PlayerLoadout”, GAMEMODE, self );[/lua]

When you change team; the armor will be instant. Now, here’s the next bit, do some testing. If armor is NOT REMOVED when you quit the job, make sure you set the armor to 0 in the ELSE part of the if/else tree, that way only authorized classes gain armor, and unauthorized get reset to 0.

I opened up sv_gamemode_functions.lua and went to the function function GM:PlayerLoadout(ply), then do I change function GM:PlayerLoadout to the hook:


hook.Call( "PlayerLoadout", GAMEMODE, self );

Sorry, im being extra sure, not risking breaking DarkRP again :p.

Shouldn’t edit core files. Ace is just mislead.

Haven’t changed anything yet, what do you suggest?

The core file is wrong;

function meta:ChangeTeam(t, force) in player.lua is the file you change, not sv_gamemode_functions.lua…

I gave exact line numbers. If PlayerLoadout is to be called when the team is changed, when a loadout is to be given, then it should call a hook and not a gamemode function. I looked at the GM function which provides no hook in terms of providing a link in to add additional options.

I agree in terms of not editing core files, unless they are incorrect.

Again, re-read what I posted. It’s player.lua, I provided line numbers. It may be an old version ( a month old at most ). Within the “function meta:ChangeTeam(t, force)” in player.lua, near the bottom of the function there is a call to “GAMEMODE:PlayerLoadout(self)” which needs to be changed to “hook.Call( “PlayerLoadout”, GAMEMODE, self );”

There is no rule saying you can’t override default functions. It’s common for a gamemode to do so. Either way if you want to be able to update in the future, don’t touch any code in the core.

PlayerLoadout should be called every time you spawn (unless other function is overridden and not calling this function). What do you mean by re spawn, is there a difference?
If re spawns are different in darkrp you should make a function for armor assignment. Then call it once in spawn. find a way to hook whatever darkrp is using for special respawns and make that also call the armor function.

I really doubt there would be a separate method for respawning, but I can’t say for sure without knowing.

Where is player.lua located?

darkrp/gamemode/server/player.lua

PlayerLoadout should be called when you switch jobs too, but it isn’t due to it being referenced directly instead of via hook as designed instead of just on spawn.

No such folder as server. You may be thinking of 2.4.3.

Spot on. I guess that shows how much I know about DarkRP. What’s the latest version then?

Basically, OP and whoever else, you have to find out the function for joining / swapping teams. There should be a hook.Call in it, if there isn’t, add one to PlayerLoadout.

If there is a hook.Call, use that.