Home   Help Search Login Register  

Author Topic: Stamina script...possible?  (Read 3760 times)

0 Members and 1 Guest are viewing this topic.

Offline SEAL84

  • Members
  • *
  • Always lurking
Stamina script...possible?
« on: 20 Jan 2004, 02:47:32 »
Would it be possible to make a stamina script for your squad?

Each man is assigned a variable at the beginning of the mission - this is his "toughness" rating.  It should range from 30 min to 60 min.

When the mission starts, start a timer.  When each man hits his variable limit, another script is called - this one reduces his skill dramatically and makes him bitch at you over the radio that he's tired and his feet hurt.  He'll still be part of the squad and can still fight, but he'll be annoying and less effective.

To remedy this, you need to choose "rest" from your action menu - everyone is set to "safe" mode and sits down for a few minutes.  At the end of this short time, the timer is reset to zero for all of them and begins to count up again.  They regain their default skill rating.  

Of course, you should be able to cancel the rest period with an action if you need to move, but they remain tired.

Is this possible with eight or so men?  If it is, I have a very clever use for it ;D

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:Stamina script...possible?
« Reply #1 on: 20 Jan 2004, 07:25:36 »
Why do you think the player gets tired when he runs fast?

The important Q is, how do you get AI to sprint instead of just running so they won't drop behind the player. That'll automaticly get your stamina script to work(I think).

:beat: *Gets Shot* :beat:

Offline SEAL84

  • Members
  • *
  • Always lurking
Re:Stamina script...possible?
« Reply #2 on: 20 Jan 2004, 16:32:25 »
I'm talking about something far more detailed than that.

I'm looking for a drastic effect after moving around for long periods of time...IRL you don't just sprint and recover, eventually you need to take a longer break.

There's some progress on this on the official boards...looks like it's possible :)

Offline SEAL84

  • Members
  • *
  • Always lurking

Offline Pathy

  • Former Staff
  • ****
  • I'm not a F***in llama!
    • Volcbat.
Re:Stamina script...possible?
« Reply #4 on: 20 Jan 2004, 19:45:55 »
We already tried doing that, i threw the idea around between me, m21man and andersgrim, none of us came up with anything that would convincingly work, so we dismissed it as impossible.

If you do find away, ill be interested to hear it. (and help you extensively with it (my mod would want to script it into our units 8))

HuNtA

  • Guest
Re:Stamina script...possible?
« Reply #5 on: 21 Jan 2004, 21:55:21 »
hmm, I know how!  :D

take a guess at how fast the man goes when he sprints, then use teh speed command so when U go at that speed, it takes numbers off a counter every second/half second/ 0.01 seconds and make a script called rest that uses disableUserInput and makes it so the counter is refilled and U r givven control after 10 seconds

Offline SEAL84

  • Members
  • *
  • Always lurking
Re:Stamina script...possible?
« Reply #6 on: 25 Jan 2004, 02:10:56 »
Check that flashpoint1985 thread for Spinor's first shot at the script ;D

m21man

  • Guest
Re:Stamina script...possible?
« Reply #7 on: 26 Jan 2004, 00:45:18 »
Quote
We already tried doing that, i threw the idea around between me, m21man and andersgrim, none of us came up with anything that would convincingly work, so we dismissed it as impossible.
Sure, it could be done. Could it be done simultaneously with 40 units in thick jungle? No.

Homefry31464

  • Guest
Re:Stamina script...possible?
« Reply #8 on: 26 Jan 2004, 02:07:12 »
I think this is intended for the player's group.  

Offline SEAL84

  • Members
  • *
  • Always lurking
Re:Stamina script...possible?
« Reply #9 on: 26 Jan 2004, 05:37:53 »
Sure, it could be done. Could it be done simultaneously with 40 units in thick jungle? No.

Note the phrase "for your squad" in the initial post ;)

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:Stamina script...possible?
« Reply #10 on: 26 Jan 2004, 15:00:44 »
Quote
Sure, it could be done. Could it be done simultaneously with 40 units in thick jungle? No.
I would say that even that is also possible. CPU-wise it is not very demanding as you donÂ't have to check every 0.5s or so, a cycle of 30 seconds is more than enough. With some clever scripting, the workload can be nicely distributed.
The real problem when applying such a stamina script to an AI squad is that the AI does not have a chance to recover itself.

Offline SEAL84

  • Members
  • *
  • Always lurking
Re:Stamina script...possible?
« Reply #11 on: 26 Jan 2004, 16:29:49 »
Yeah, I figured getting the AI to cooperate would be a problem.  

So far the script is working pretty well - I've got to try a few more things but it looks good.

wi77ard

  • Guest
Re:Stamina script...possible?
« Reply #12 on: 12 Apr 2005, 14:31:28 »
Quote
Here is a first try. Actually it is quite bloated as I already tried to implement all the ideas that appeared yet. I even take into account the possible fatigue of crew vehicles.

Usage: Put both scripts "stamina.sqs" and "rest.sqs" in your mission folder. "stamina.sqs" is called like
[group, toughness] exec "stamina.sqs"
e.g. in the init field of the player:
[group this, 30] exec "stamina.sqs"

Following SEAL84, stamina and toughness(=initial stamina) are measured in minutes, which is quite intuitive.

"Rest.sqs" will be automatically added to the action menu and puts all men in the group into SAFE mode (no sitting yet)

The algorithm to calculate stamina/skill change used is quite contrived but takes into account all factors mentioned (behaviour, combat mode, average speed, weight/#items, on foot/crew/passenger).
The stamina change is calculated from all factors. Once stamina falls below zero, the skill is slowly reduced. Once the stamina rises again above a certain value (now 0.8*toughness), the skill slowly recovers again to its original value. At some stamina level (0.2*toughness) there is a warning of the impending fatigue.

All the factors/parameters can be tuned and everyone is invited to do so in order to get a reasonable result.

Have fun,
Spinor

Stamina.sqs:
Code Sample
_group = _this select 0
_toughness = _this select 1

_units = units _group
_N = count _units

_initskills = []; _staminas = []; _pos = []
{_initskills = _initskills + [skill _x]; _staminas = _staminas + [_toughness]; _pos = _pos + [getPos(vehicle _x)]} forEach _units

;values for tuning------------------------------------------

;loop update interval in seconds
_period = 20

;speed thresholds [v1,v2] for foot soldiers in meters/minute, 0 - slow - v1 - medium - v2 - fast
_speed1 = [50,100]

;speed thresholds [v1,v2] for vehicles in meters/minute, 0 - slow - v1 - medium - v2 - fast
_speed2 = [200,400]

;weight thresholds [w1, w2], w = #Weapons + 0.5*#Magazines, 0 - light - w1 - medium - w2 - heavy
_weight1 = [3,6]

;Behaviour/Combat mode lookup table for stamina change (per minute)
;          AWARE                 COMBAT           STEALTH          SAFE              CARELESS
;          GR,BL,WH,YE,RE
_table1 = [[-0.75,-1,-1,-1,-1.5],[-2,-2,-3,-3,-4],[-3,-3,-3,-3,-3],[2,2,1.5,1.5,1.5],[0,0,0,0,0]]

;Speed/Weight lookup table for stamina change (per minute)
;          SLOW    MEDIUM      FAST
;          LI,ME,HE
_table2 = [[1,1,1],[0,-0.5,-1],[-0.5,-1,-2]]

;Speed table for stamina change of vehicle crews,[SLOW,MEDIUM,FAST]
_table3 = [1,0,-1]

;stamina recovery rate per minute of vehicle passengers
_passenger = 2

;stamina level for warning messages
_warn = 0.2*_toughness

;stamina level for skill recovery
_recov = 0.8*_toughness

;skill recovery rate (per minute)
_increase = 0.15

;skill fatigue rate
_decrease = 0.1

;-----------------------------------------------------------

_norm = _period/60

_getIndex ={private ["_e","_a","_i","_j"];_e = _this select 0;_a = _this select 1;_j = -1;_i = (count _a)-1;while{_i >= 0} do{if(_e == (_a select _i)) then {_j = _i; _i = -1;} else {_i = _i-1;};};_j};

(leader _group) addAction["Rest","rest.sqs"]

#Loop
?("alive _x" count (units _group) == 0): exit

_debug = ""

_i = 0
#UnitLoop
_unit = _units select _i
?!(alive _unit) OR !(_unit in (units _group)) OR player == _unit: _i = _i+1; goto "UnitLoop"

_behaviour = behaviour _unit
_cmode = combatMode _unit

goto "GroupStamina"
#ReturnGroupStamina

_vehicle = vehicle _unit
_stamina = _staminas select _i
_initskill = _initskills select _i
_pos1 = _pos select _i; _pos2 = getPos _vehicle
_speed = sqrt(((_pos2 select 0) - (_pos1 select 0))^2 + ((_pos2 select 1) - (_pos1 select 1))^2)/_norm

?_vehicle == _unit: goto "FootStamina"
?_unit in [driver _vehicle, commander _vehicle, gunner _vehicle]: goto "CrewStamina"
goto "PassengerStamina"
#ReturnUnitStamina

_newstamina = _stamina + _change*_norm
if(_newstamina > _toughness) then {_newstamina = _toughness}
if(_newstamina > _recov) then {goto "Recovery"}
if(_newstamina < 0) then {goto "Fatigue"}
               if(_newstamina < _warn AND _stamina > _warn) then {goto "Warning"}
#ReturnAdjustSkill

_debug = _debug + format["%1: %2,%3\n-->St=%4+%5\n-->Sk=%6\n",_i+1,_cmode,_behaviour,_stamina,_change,skill _unit]

_staminas set[_i, _newstamina]; _pos set[_i,_pos2]

_i = _i + 1
?(_i < _N): goto "UnitLoop"

hint _debug

~_period
goto "Loop"

#GroupStamina
_j = [_behaviour,["AWARE","COMBAT","STEALTH","SAFE","CARELESS"]] call _getIndex
_k = [_cmode,["GREEN","BLUE","WHITE","YELLOW","RED"]] call _getIndex
_groupchange = (_table1 select _j) select _k
goto "ReturnGroupStamina"

#FootStamina
if(_speed < _speed1 select 0) then {_speed = 0} else {if(_speed < _speed1 select 1) then {_speed = 1} else {_speed = 2}}
_weight= count(weapons _unit) + 0.5*count(magazines _unit)
if(_weight < _weight1 select 0) then {_weight = 0} else {if(_weight < _weight1 select 1) then {_weight = 1} else {_weight = 2}}
_change = (_table2 select _speed) select _weight
_change = _groupchange + _change
goto "ReturnUnitStamina"

#CrewStamina
if(_speed < 100) then {_speed = 0} else {if(_speed < 200) then {_speed = 1} else {_speed = 2}}
_change = _table3 select _speed
_change = _groupchange + _change
goto "ReturnUnitStamina"

#PassengerStamina
_change = _passenger
goto "ReturnUnitStamina"

#Recovery
if(_stamina < _recov) then {_unit groupChat "I'm recovering."}
_skill = (skill _unit)*(1+_increase*_norm)
if(_skill >= _initskill) then {_skill = _initskill}
_unit setSkill _skill
goto "ReturnAdjustSkill"

#Warning
_unit groupChat "I'm getting exhausted."
goto "ReturnAdjustSkill"

#Fatigue
if(_stamina > 0) then {_unit groupChat "I'm out of breath."}
_skill = (skill _unit)*(1-_decrease*_norm)
_unit setSkill _skill
goto "ReturnAdjustSkill"


rest.sqs
Code Sample
_group = group(_this select 0)

_group setBehaviour "SAFE"


--------------

this script is great, i have used it in SP lots and it makes for a much better mission. I am trying to get it working in MP, it works to an extent, but only shows the stamina and skill of other members of your squad, but does work for all players including the leader of the group.

Is there some way someone could make this work for a single unit? i would like it to simply do exactly the same thing, but also the addition of when the stamina is right down it slowly reduces the health of the player, and it would then detect when the player is stopped and / or sitting down and then slowly recover the stamina, but not the health. Is this possible???

Thanks for help in advance .....

Offline Roni

  • Members
  • *
  • Play the Game !
Re:Stamina script...possible?
« Reply #13 on: 13 Apr 2005, 03:25:34 »
Hey All

I do a lot of MP scripting and make a lot of "group effect" scripts.  I haven't work through all the details of your script but here's a few ideas FWIW.    :P

First off, write the script so that it only needs to be called ONCE for an entire group, no matter how big or small the group is.  Second, make sure that the script runs continuously until the group is entirely wiped out.  The best way to do meet of these objectives is to run the script from (say) the group leader's init field and have it loop endlessly until the last man dies (count units group this = 0).

Now have the script start by pausing for a random period, say ~ random 10.  This will "desync" multiple copies of the script running on different groups.  Now have the script loop reasonably slowly, say, every 20 seconds or so.  The net effect of these two bits will ensure that there is no big lag hit and no "skip" as all group scripts get actioned at once.

Now have the script get the list of all current members, then action the fatigue handler for each member in turn.  Sort of like this -


~ (random 10)

#loop

_squadMembers = count units group _this
? _squadMembers == 0 then exit

#nextLoon
< do all your fatigue handling stuff for each member>
? _ squadMembers > 0 : _ squadMembers - 1, goto "nextLoon"

~20
goto "loop"



Now another idea is to use the setDammage command to represent your fatigue.  A strange quirk of OFP is that if unit's damage rating is less than zero (eg _this setDammage -0.5) then it's aim becomes screwed up - the higher negative rating the lower the accuracy.

So all you have to do is work out the fatigue effect on your unit, then use that to set his damage to some lower value (unless it's more than zero ?).  You might also use the resulting value for some other effect, such as a sound, a sidechat or a playAnimation.

The above schema should allow you to run this script on any number of units.  There won't be that many variables for the system to keep track of (it already keeps track of the units damage) and the slow pace of the desynched loops should result in minimal lag.

I hope that this helps.



roni

wi77ard

  • Guest
Re:Stamina script...possible?
« Reply #14 on: 13 Apr 2005, 09:05:42 »
yeah this sounds good, but how do i make the actual stimina script for each unit?


Offline Blanco

  • Former Staff
  • ****
Re:Stamina script...possible?
« Reply #15 on: 13 Apr 2005, 09:40:38 »
What about traveldistance (only when he's on foot) to define his fatigue?  The distance can be updated every 20m so it won't take much CPU resources and it only counts distance in x,y coords not in z
There is a mileagecalculator script in the editordepot from pablo123. You can make a pedometer... (is that a word?  :) )
And I should slightly reduce his skill instead of his damage to simulate fatigue.

Just my 2 cents.

« Last Edit: 13 Apr 2005, 14:34:58 by Blanco »
Search or search or search before you ask.

wi77ard

  • Guest
Re:Stamina script...possible?
« Reply #16 on: 13 Apr 2005, 11:51:38 »
the script looks good, and easy way to tell the distance each guy has travelled, should working in MP too, I hope :)

but how do i add some sort of stamina value to this, it would be great to have it so if the guy has travelled ..... distance he begins to loose health and needs to be sitting down to restore his stamina. How do add this to the script??

cheers for help

Offline Roni

  • Members
  • *
  • Play the Game !
Re:Stamina script...possible?
« Reply #17 on: 13 Apr 2005, 15:16:08 »
Hi wiz

I hate to butt in but once again I think that the idea should be to set up some sort of stamina rating for each unit at start, then reduce this rating each step of the cycle according to distance moved, magazines carried (a piss poor but passable approximation of weight carried) and alert status (an approximation of mental fatigue).

To determine the appropriate distance covered effect a simple test is to create a one man mission with a single script that records the man's position at start, then his position at the end of each cycle then works out his distance moved.  Like this -

; pedometer.sqs

#loop
_startPos = getPos loon1
~20
_endPos = getPos loon1

_distanceCovered = sqrt ((startPos * startPos) + (endPos * _endPos))
hint format ["Distance covered = %1", _distanceCovered]

goto "loop"



Try running, sprinting and walking your man with weapon slung to get a rough average of the distances covered.  Now use these values as your "benchmark" for your stamina loss or gain rates.

Example - Pretend that you discover that every 20 second cycle your man can sprint 80m, run 50m or walk 20m.  All you do is set your stamina variation rate to something like

_distanceFatigue = 30 - _distanceCovered

This means that if you walk you will gain back stamina VERY slowly, if you run you will lose it over time and if you sprint then you fatigue like a fatiguing thing with a degree in fatiguing from Fatigue University.

Chuck in a magazine effect, like so -

_weightFatigue = 10 * (count magazines _this)

and an Alert Status effect like so -

_alertFatigue = -20
? behaviour _this == "Safe" : _alertFatigue = -10
? behaviour _this == "Aware" : _alertFatigue = 0
? behaviour _this == "Combat" : _alertFatigue = 10
? behaviour _this == "Stealth" : _alertFatigue = 20



Then you simply bring it all together like so -

_stamina = _stamina + _ distanceFatigue + _weightFatigue + _alertFatigue


Of course, if you use the above group stamina script then you need to use an array of staminas for each group member and set up the starting values accordingly.

I think that the basic idea is to create a simple script regime that loops once for each and every man in the group.  It may be a bit of coding, but the end result is that the script should be simply point and shoot, ie - put in to init field of group leader and fuggedaboutit !

Hope that this helps !



roni

wi77ard

  • Guest
Re:Stamina script...possible?
« Reply #18 on: 13 Apr 2005, 16:00:08 »
again looking great, seems to be the kinda thing i want.

adding it all together looks hard though. could you get it to check for a weapon like a law launcher or backpack and make the unit loose stamina faster if they have one of these. also would it still decrease the stamina say if i have a dude who had a backpack but wasnt moving, coz in reality you would still get tired from just having it on your back.

thanks for help, this thing is drving me mad!  ???

wi77ard

  • Guest
Re:Stamina script...possible?
« Reply #19 on: 13 Apr 2005, 16:02:17 »
oh and i dont want it to work on a group, just each single player. hopefully so i can add a stats hint, to let each person know what their stamina and health is. I dont have the players linked in groups in multiplayer mission.

Offline SEAL84

  • Members
  • *
  • Always lurking
Re:Stamina script...possible?
« Reply #20 on: 14 Apr 2005, 16:02:43 »
Roni, I'm pretty sure the script (which was created by Spinor, btw) already accounts for distance and combat state.  Those two determine how much of a deduction the man's stamina rating will take - the stamina rating is set at the beginning and measured in minutes.

When a team is running around - depending on how fast and in what combat mode - their skill levels are slowly decreased as their stamina drops.  They are not actually being injured.

The problem with running the script on players is that there really is nothing that you can to do a human-controlled player to achieve the same thing.  Injuring the player is certainly not analagous to being fatigued...being fatigued should have no effect on how much damage you can take.  Your best bet is to use the reverse-setdammage trick - negative dammage makes the crosshairs extremely wobbly.  Perhaps also some audio files could be played.

Your best bet is to talk to Spinor.

wi77ard

  • Guest
Re:Stamina script...possible?
« Reply #21 on: 14 Apr 2005, 17:01:01 »
thanks for reply

yeh something like making aiming harder and possibly blackouts for extreme fatigue.
All i'm really trying to achieve is something that will make gaming more realistic, like the need to have a LUP during misisons. And also removing the ability to lug a heavy bergen 60k and not feel any effect. I want people to know they have carried their bergen, and this also gives rise to the fact when a contact does happen, dumping the bergen might be a good idea, though it might not too. lol

anyhow, enough about me babbling. .............. i love the script that spinor wrote, i really want to use that if possible. It works fab in single player. i just need it adapting to fit multiplayer, so that each player can keep watch of his own levels, not relying upon a group leader.

I've sent a pm to spinor in the hope he will read this and be able to help out. I've tried to remove the group side of things, but to be honest it is too complex a script for me to mess about with ......... :D

wi77ard

  • Guest
Re:Stamina script...possible?
« Reply #22 on: 17 Apr 2005, 22:42:30 »
*bump*

please can anyone help

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:Stamina script...possible?
« Reply #23 on: 24 Apr 2005, 13:04:16 »
Hello, I have attached the stamina script you requested, i.e. it works on a single unit rather than a group. It is executed analogously:

[ unit,toughness ] exec "stamina_unit.sqs"

It is a straightforward conversion and, as pointed out by SEAL, it is currently rather useless on a player, as fatigue is modelled by reducing the (AI) skill. If you want to properly convert it to use it on players, you would have to implement something like a wobbly crosshair or blackouts.

As for the influences on stamina, the script takes into account:
- combat mode and behaviour
- speed (travelled distance)
- role of unit: on foot, vehicle crew, vehicle passenger (crews will also suffer fatigue)
- weight, in a crude way; total "weight" is measured as #weapons + 0.5*#magazines

wi77ard

  • Guest
Re:Stamina script...possible?
« Reply #24 on: 26 Apr 2005, 00:16:18 »
thanks so much for that

how do i implement blackouts and crosshar effects?


Offline Roni

  • Members
  • *
  • Play the Game !
Re:Stamina script...possible?
« Reply #25 on: 26 Apr 2005, 01:13:40 »
Hi Wiz

Wobbly crosshairs can be done via a negative setDammage rating or a very fast loop implementing a tiny random setDir change.  Blackouts can be simulated using a black fadeout titleCut.

If you'd like I could throw something together tonight - I'm working on a mission which needs a fatigue type script and I already have a script that works like this but that needs updating.  It won't be as good as Spinor's  :-\ but it should do what you want.

Cheers



Roni


wi77ard

  • Guest
Re:Stamina script...possible?
« Reply #26 on: 26 Apr 2005, 08:47:00 »
anything would be good

when i used blackout in multiplayer it made everyone blackout not just the one dude, might have been coz the script was running on the group instead of the single unit.