Home   Help Search Login Register  

Author Topic: Stamina script...possible?  (Read 3766 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?