Scripts / Healing player smoothly

Author
Message
boilingpoint2
10
Years of Service
User Offline
Joined: 9th Jun 2014
Location:
Posted: 26th Aug 2023 11:00
Hi

I'm trying to heal smoothly the player by adding point by point the heal of the med box

It works but if i place let's say 10 med kit, all med kit are consumed !
I tried a lot of thing but nothing works
I even tried to verify the id of the entity the hard way but no luck

Can someone help ?

CODE :

function health_grad_init(e)
StartTimer(e)
medkitpoints = 10
PointsToAdd = 0
AddingHealth = false
PickupCollected = false
id = e
end

function health_grad_main(e)
PlayerDist = GetPlayerDistance(e)

if not PickupCollected and PlayerDist < 70 and id == 16 then
PickupCollected = true
PlaySound(e, 0)
Hide(e)
end

if PickupCollected and g_PlayerHealth > 0 and id == 16 then
if not AddingHealth then
AddingHealth = true
PointsToAdd = medkitpoints
StartTimer(e)
end

if AddingHealth and PointsToAdd > 0 and GetTimer(e) > 100 and id == 16 then
AddPlayerHealth(e)
PointsToAdd = PointsToAdd - 1
StartTimer(e)
end

if PointsToAdd == 0 and id == 16 then
AddingHealth = false
ActivateIfUsed(e)
PromptDuration("Med kit caught : +"..medkitpoints.." id:"..e, 2000)
Destroy(e)
end
end
end
http://francoismorin460.wix.com/specialagents

My fpsc x9 game : action-survival/horror, 12 levels, free

A suite will be made on FPSCR
PM
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 26th Aug 2023 17:34 Edited at: 26th Aug 2023 17:34
What do you want to do with the other nine medkits?
In my video, I just can grab/consume the desired medkit (16 in your case, 1 in mine), the other one is being ignored.
If you want to grab the other nine medkits without consuming them, just control the start player health and hold it in a var, let's say:
oldHealth = g_PlayerHealth in the _init(e) function.

Then compare g_PlayerHealth against oldHealth if g_PlayerHealth < oldHealth then add player health otherwise don't.

https://youtu.be/IAGdGWzelP4
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

Attachments

Login to view attachments
PM
boilingpoint2
10
Years of Service
User Offline
Joined: 9th Jun 2014
Location:
Posted: 27th Aug 2023 09:51
Hi ! thank you for your quick reply

So I will summarize my need:

I want medkits to heal the player smoothly
Currently if I place kits in my level they are all consumed at the same time even if I take only one.

My script was a simple test to see if I could do a check on the ID to prevent this behavior of the kit but it's buggy

The technique with oldHealth = g_PlayerHealth seems interesting but for the moment I don't see how to implement it.

sfmbe
http://francoismorin460.wix.com/specialagents

My fpsc x9 game : action-survival/horror, 12 levels, free

A suite will be made on FPSCR
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 5th Sep 2023 17:00
he already attached the script - the key change is moving the logic to arrays/lists where each medkit is handled using it's own ID which means rather than 1 toggle flipping on all of your medkits at once, they now have their own toggles.
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Login to post a reply

Server time is: 2024-12-21 16:23:39
Your offset time is: 2024-12-21 16:23:39