Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [HELP]Checking amount of player Health  (Read 1961 times)

0 Members and 1 Guest are viewing this topic.

Offline Pepsifan04

  • *
  • *
  • +12% chance to make useful post
  • Pepsifan04 might someday be someone...Pepsifan04 might someday be someone...Pepsifan04 might someday be someone...Pepsifan04 might someday be someone...
[HELP]Checking amount of player Health
« on: May 10, 2014, 10:52:51 PM »
Another hard question form me:
Can you check via mapadd or !player ent. how much health player has and fire output when certain amount is reached?
I know that there's an ent for autosaving game when player is below certain amount of health,
But it only allows me to autosave and does not have any other "proper" outputs except "Onuser#"
!player ent.  also does not have any health-related outputs, except "onignite"

I'm asking for SMOD way of doing that, I know I can edit sourcecode of Hl2, but then what's the point of  "modding" SMOD

EDIT: I'll be happy If I could do the same with armour hitpoints
« Last Edit: May 10, 2014, 10:58:14 PM by Pepsifan04 »
Officially Unofficial BSNOOCH Discord:
https://discordapp.com/invite/eBqezeR

Offline Counter-Life™

  • *
  • *
  • +17% chance to make useful post
  • Counter-Life™ is a rising star!Counter-Life™ is a rising star!Counter-Life™ is a rising star!Counter-Life™ is a rising star!Counter-Life™ is a rising star!Counter-Life™ is a rising star!
    • Youtube Channel
Re: [HELP]Checking amount of player Health
« Reply #1 on: May 11, 2014, 08:12:53 AM »
I can confirm that this is somehow possible via mapadd. In my very old SMOD mini-mod (wich as sadly lost when my HDD screwed up) I had a mapadd that slowed the game slightly down when the players health got below 20 HP.

I will try to figure out how I did it, it's ages ago so I can't promise anything.

Offline Pepsifan04

  • *
  • *
  • +12% chance to make useful post
  • Pepsifan04 might someday be someone...Pepsifan04 might someday be someone...Pepsifan04 might someday be someone...Pepsifan04 might someday be someone...
Re: [HELP]Checking amount of player Health
« Reply #2 on: May 11, 2014, 08:22:59 AM »
That's great, thanks in advance.
I've actually wanted to make something similar, except I want to desaturate colours when player is near death.
Officially Unofficial BSNOOCH Discord:
https://discordapp.com/invite/eBqezeR

Offline FreeKill

  • *
  • *
  • +7% chance to make useful post
  • FreeKill is working their way up.FreeKill is working their way up.FreeKill is working their way up.
    • Youtube Channel
Re: [HELP]Checking amount of player Health
« Reply #3 on: May 11, 2014, 04:58:40 PM »
I can confirm that this is somehow possible via mapadd. In my very old SMOD mini-mod (wich as sadly lost when my HDD screwed up) I had a mapadd that slowed the game slightly down when the players health got below 20 HP.

I will try to figure out how I did it, it's ages ago so I can't promise anything.

Sounds like you might have used host_timescale in some way.

Offline Rook

  • *
  • +2% chance to make useful post
  • Rook has no influence.
Re: [HELP]Checking amount of player Health
« Reply #4 on: January 23, 2015, 11:43:15 PM »
Stumbled onto this post a bit late. I first tried to do this through logic_playerproxy but can't get it to function correctly through a mapadd script. It may be one of those entities that don't work when added late, like templates. In any case, I came up with this:

Code: [Select]
// shop.txt
"entities"    {
    "info_player_start"    {
        "origin" "468 -61 10"    "angle" "0 180 0"
    }
    "lua"    {
        "callfunc" "boot"
    }
}

"entities:updatePlayerSpeed"    {
    "lua"    {
        "callfunc" "updatePlayerSpeed"
    }
}

Code: [Select]
// shop.lua
function boot()
    local ents = {
        point_clientcommand = {
            targetname = 'console'
        },
        logic_auto = {
            OnMapSpawn = {
                'console,command,incrementvar sv_cheats 1 1 1,,0,-1',
                'console,command,give item_suit,,0,-1',
                'console,command,give weapon_rpg,,0,-1',
                'console,command,give weapon_frag,,0,-1',
                'console,command,give weapon_anm14,,0,-1'
            }
        },
        player_speedmod = {},
        logic_timer = {
            refireTime = 3,
            OnTimer = 'console,command,instant_trig_run updatePlayerSpeed,0,-1',
        }
    }
    local zero = VECTORZERO
    for entry, settings in pairs(ents) do
        local ent = HL2.CreateEntity(settings.classname or entry, settings.org or zero, settings.ang or zero)
        if ent then
            for k, v in pairs(settings) do
                if type(v) ~= 'table' then
                    HL2.KeyValue(ent, k, v)
                else
                    for _, output in pairs(v) do
                        HL2.KeyValue(ent, k, output)
                    end
                end
            end
            HL2.SpawnEntity(ent)
        end
    end
end

function updatePlayerSpeed()
    local hp = HL2.GetEntInfo(HL2.GetPlayer()).Health
    local speed = 1.0
    if hp < 40 then
        speed = 0.7
        if hp < 15 then
            speed = 0.4
        end
    end
    HL2.EntFire('player_speedmod', nil, 'ModifySpeed', speed, 0.1)
end

Grabs the player as an entity, queries its health, and tweaks player speed if they're wounded badly enough ala Left 4 Dead.

Mind that player_speedmod's behavior is a bit odd since it doesn't stop at just affecting speed; the player's relationship with deceleration, gravity, friction, and so on is also changed. I figure it works well enough for a demonstration though.

I couldn't find a way to do anything similar with armor.
« Last Edit: January 23, 2015, 11:53:28 PM by Rook »

Offline Pepsifan04

  • *
  • *
  • +12% chance to make useful post
  • Pepsifan04 might someday be someone...Pepsifan04 might someday be someone...Pepsifan04 might someday be someone...Pepsifan04 might someday be someone...
Re: [HELP]Checking amount of player Health
« Reply #5 on: January 24, 2015, 12:14:56 AM »
Stumbled onto this post a bit late. I first tried to do this through logic_playerproxy but can't get it to function correctly through a mapadd script. It may be one of those entities that don't work when added late, like templates. In any case, I came up with this:

Code: [Select]
// shop.txt
"entities"    {
    "info_player_start"    {
        "origin" "468 -61 10"    "angle" "0 180 0"
    }
    "lua"    {
        "callfunc" "boot"
    }
}

"entities:updatePlayerSpeed"    {
    "lua"    {
        "callfunc" "updatePlayerSpeed"
    }
}

Code: [Select]
// shop.lua
function boot()
    local ents = {
        point_clientcommand = {
            targetname = 'console'
        },
        logic_auto = {
            OnMapSpawn = {
                'console,command,incrementvar sv_cheats 1 1 1,,0,-1',
                'console,command,give item_suit,,0,-1',
                'console,command,give weapon_rpg,,0,-1',
                'console,command,give weapon_frag,,0,-1',
                'console,command,give weapon_anm14,,0,-1'
            }
        },
        player_speedmod = {},
        logic_timer = {
            refireTime = 3,
            OnTimer = 'console,command,instant_trig_run updatePlayerSpeed,0,-1',
        }
    }
    local zero = VECTORZERO
    for entry, settings in pairs(ents) do
        local ent = HL2.CreateEntity(settings.classname or entry, settings.org or zero, settings.ang or zero)
        if ent then
            for k, v in pairs(settings) do
                if type(v) ~= 'table' then
                    HL2.KeyValue(ent, k, v)
                else
                    for _, output in pairs(v) do
                        HL2.KeyValue(ent, k, output)
                    end
                end
            end
            HL2.SpawnEntity(ent)
        end
    end
end

function updatePlayerSpeed()
    local hp = HL2.GetEntInfo(HL2.GetPlayer()).Health
    local speed = 1.0
    if hp < 40 then
        speed = 0.7
        if hp < 15 then
            speed = 0.4
        end
    end
    HL2.EntFire('player_speedmod', nil, 'ModifySpeed', speed, 0.1)
end

Grabs the player as an entity, queries its health, and tweaks player speed if they're wounded badly enough ala Left 4 Dead.

Mind that player_speedmod's behavior is a bit odd since it doesn't stop at just affecting speed; the player's relationship with deceleration, gravity, friction, and so on is also changed. I figure it works well enough for a demonstration though.

I couldn't find a way to do anything similar with armor.
That's and old question and I've came up with similar solution to it, but as you said: the solution is not perfect.
And since logic_playerproxy is broken in smod you can't use it.

But thanks anyway :D it might be useful for someone else
Officially Unofficial BSNOOCH Discord:
https://discordapp.com/invite/eBqezeR