Jump to content
Nutscript
Odderino

Set a faction's health

Recommended Posts

Go into your schema's plugin and add a lua file called factionhealth.lua or something like that.

 

To set a faction's health do this:

 

function PLUGIN:PlayerSpawn(client)
    if (client:Team() == FACTION_WHATEVER) then
        client:SetMaxHealth(1000)
        client:SetHealth(1000)
    end
end

 

Change FACTION_WHATEVER to whatever you put for the faction's FACTION.index, if you didn't didn't define the FACTION.index in the faction's lua file, you should.

 

If you want to do multiple just do this:

 

function PLUGIN:PlayerSpawn(client)
    if (client:Team() == FACTION_1) then
        client:SetMaxHealth(1000)
        client:SetHealth(1000)
    elseif (client:Team() == FACTION_2) then 
        client:SetMaxHealth(200)
        client:SetHealth(200)
    elseif (client:Team() == FACTION_3 then
        client:SetMaxHealth(50)
        client:SetHealth(50)
    elseif (client:Team() == FACTION_4) then
        client:SetMaxHealth(250)
        client:SetHealth(250)
    end
end

 

If for some reason you want the spawn health and the max HP they can have at one time to be different, SetMaxHealth is the max HP they can have, and SetHealth is what they spawn with.

 

A file with the code inside is attached. Just put it in your schema's plugins folder.

 

factionhealth.lua

Edited by Odderino
clarity
  • Like 1

Share this post


Link to post
Share on other sites

This can be done a little better:

-- [UniqueID] = health
SCHEMA.FactionHealth =
{
	[FACTION_CP] = 120,
	[FACTION_OW] = 500
}

function SCHEMA:PlayerSpawn(client)
	for k, v in pairs(self.FactionHealth) do
		if (client:Team() == k) then
			client:SetMaxHealth(v)
			client:SetHealth(v)
		end
	end
end

 

  • Like 1

Share this post


Link to post
Share on other sites

or even better

 

-- [UniqueID] = health
SCHEMA.FactionHealth =
{
    [FACTION_CP] = 120,
    [FACTION_OW] = 500
}

function SCHEMA:PlayerSpawn(client)

    local nFactionHealth = self.FactionHealth[client:Team()];
    if( !nFactionHealth ) then return end;
    
    client:SetMaxHealth( nFactionHealth );
    client:SetHealth( nFactionHealth );
    
end

 

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×