AdmiralKarlDonuts 0 Posted January 20, 2004 Hi all, I posted this at OFPEC verbatim but I figured it's worth putting up here too... 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 whine 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 Share this post Link to post Share on other sites
OmniMax 0 Posted January 20, 2004 Yes it would be possible. A few problems, though. 1. All those variables to keep track off, all the scripts... not very CPU\Network friendly. 2. A few minutes? I understand thats how it is in real life (I have ashma and I'm a weenie, I can't even run a mile, well, I can but it takes me 8 MINUTES! and I end up weezing and my saliva glands make all this crap, okay too much info ) 3. BIS has already implemented something like this, although it doesn't prevent you from running forever, it effects your aim (run around a bit, you'll hear your guy weezing like me ) 4. BUT! You should make yours unique by detecting ALL the characters gear! The more gear he has, the more easily he gets tired! You would be the unsung hero (because this won't be implemented till OFP2!) Honeslty though, it's going to prove a little tricky. How to do it? I'd try testing GETVELOCITY on the player (wasn't there a built in getSPEED?) because we don't care of his velocity, just his general speed in one direction. If you found the speed different from walking and running and made a looping script some how restricting speed (is there a command to restrict speed? Take away their fuel or something? lol.) then it's really possible. I'm sure RED, BN880, Kegetys, Doolittle, more experienced guys will give this topic a look. But it seems simple enough as long a you have a way to restrict speed and aim. I'd recommend browsing the command ref in the meantime. Share this post Link to post Share on other sites
Spinor 0 Posted January 20, 2004 It's absolutely possible and for eight or so men it shouldn't put much strain on the CPU. My suggestion is to reduce the stamina according to Combat mode, Behaviour and/or SpeedMode. E.g. the men tire much more in COMBAT/RED than in AWARE/GREEN. If in SAFE mode, you can even slowly increase the stamina again. This way you could automatically take into account resting without having to introduce a special action menu command (although this would still be nice for making them sit down). In script terms it can be implemented via a looping script that repeatedly the group parameters and adjusts the stamina accordingly: ;parameters passed: group name and toughness (=max/start stamina) _group = _this select 0 _toughness = _this select 1 _stamina = _toughness _change = 0 #Loop _behaviour = behaviour (leader _group) _combatmode = combatMode _group _speedmode = speedMode _group ;some algorithm to calculate _stamina change, e.g. if(_behaviour == "SAFE") then {_change = 1.0} if(_behaviour == "AWARE") then {_change = -0.5} if(_behaviour == "COMBAT") then {_change = -1.5} if(_behaviour == "STEALTH") then {_change = -1.0} if(_behaviour == "CARELESS") then {_change = 0.0} ;adjust stamina _stamina = _stamina + _change if(_stamina > _toughness) then {_stamina = _toughness} ;apply skill changes ;only pseudo code here, in reality it will be a little more difficult, ;one somehow has to store the initial skill of all men so it can ;be reset again if(_stamina < 0) then {makeComplaints; reduceSkill} if(_stamina > 0.9 * _toughness) then {increaseSkillUpToInitial} ~30 goto "Loop" OmniMax suggestion to take into account the gear is great. The simplest way to do this is simply to count the items in the arrays (weapons _unit) and (magazines _unit) and adjust the stamina change accordingly. Apparently ,this does not take into account the different weights of gear items. EDIT: Besides combat mode, behaviour, speed mode and gear there is another parameter that obviously affects fatigue, i.e. the marching speed (as OmniMax already said). I wouldn't use the speed command though as it only returns the current speed which can vary alot (e.g. if by chance a unit is static it will be zero). Instead one can calculate the distance to the previous position (thirty seconds ago) and from this the average speed. Share this post Link to post Share on other sites
OmniMax 0 Posted January 20, 2004 Yes. In addition, detect if they're in the sitting animation to heal stamina faster! and don't forget to calculate weight! ohoohoohoohoohohohoo! Share this post Link to post Share on other sites
AdmiralKarlDonuts 0 Posted January 20, 2004 Couple of things... First, wow, that was fast Counting the actual gear would make it much more realistic, I agree, but I think it might be better to see if someone can whip up a basic script first...if that works, the actual gear counting part can be added. About the action command - I think it would be a little easier for the player (who is the squad leader BTW) to just select an action and have everyone put in SAFE and sit. Â This way it's clear to the player what he needs to do to solve his men's problem, rather than have to guess and put them in SAFE manually. Â Maybe it would be easier, maybe not Skill levels - what about manually setting them in the INIT file so you already know what the "base" skill level is? Â Then in the script you just punch in that number again and you're set. I'll play around with that a bit later and see if I can fill in the blanks (probably not; I'm no scripter ) Share this post Link to post Share on other sites
Spinor 0 Posted January 20, 2004 Quote[/b] ]About the action command - I think it would be a little easier for the player (who is the squad leader BTW) to just select an action and have everyone put in SAFE and sit. This way it's clear to the player what he needs to do to solve his men's problem, rather than have to guess and put them in SAFE manually. Maybe it would be easier, maybe not Yes, I would implement such an action command, especially for the sitting animation. On the other hand I would also implement a behaviour dependent fatigue as it can have quite an impact on gameplay. E.g. your group won't endure COMBAT as long as AWARE, thus you have to be careful when to switch to COMBAT. Quote[/b] ]Skill levels - what about manually setting them in the INIT file so you already know what the "base" skill level is? Then in the script you just punch in that number again and you're set. The problem is that different men in the group have different skill levels. I think its quite tedious to insert them for each man manually. If you see the script only within the scope of one mission thats not a problem, but such a stamina script will surely be useful for many other mission designers. It can be solved via scripting by storing the initial values in an array: _units = units _group _initialskills = [] {_initialskills = _initialskills + [skill _x]} forEach _units _units will then store all units like [unit1, unit2, unit3] and _initialskills the skill at startup [0.66,0.5,0.5] Share this post Link to post Share on other sites
Blanco 0 Posted January 20, 2004 <post deleted> Sorry Share this post Link to post Share on other sites
AdmiralKarlDonuts 0 Posted January 20, 2004 Good point about the skill - hadn't thought of that. The behaviour should definitely play a part in the script. Â Regarding the speed, Spinor suggested checking the unit's average speed over the last 30 seconds and using that to determine the stamina decrease. Â Makes sense - using the values you just gave, the script could include a speed range of sorts - if the guy's average speed fell between X and Y, he takes this decuction, if it fell between A and B, he'd take that deduction... Sounds better and better every time Share this post Link to post Share on other sites
OmniMax 0 Posted January 20, 2004 I thought of a variation on the idea for resting to get stamina back faster. Perhaps have when their mode is safe or whatever (on radio the voice says "#(s), At ease!" make them all sit down, then have the stamina script detect whom is sitting down and heal accordlingly. Maybe detection if you're inside a vehicle or something... on a later version script, of course. Don't expect you all to bang it out at once, things like scripting are best done is small doses. (addons for example) Hoohoohoohohohohoh! Share this post Link to post Share on other sites
AdmiralKarlDonuts 0 Posted January 20, 2004 Quote[/b] ]Perhaps have when their mode is safe or whatever (on radio the voice says "#(s), At ease!" make them all sit down, then have the stamina script detect whom is sitting down and heal accordlingly. Yes, they will only regain strength if they're put in SAFE mode. Â I think it's agreed that the best way to do that is with an action menu command labeled "Rest" or something. Â That would put everyone in SAFE and have them sit. Â At that point they begin recharging. I suppose that for every length of time "X" that they remain resting, they regain Y stamina points. Â Of course, when they're rested, they'll get up and go AWARE again. Â Plus if you get them up prematurely they'll do the same, but only with as many points as they were able to accrue during that time. As for vehicle detection, yeah, I'll save that for later I have a feeling this could take me a while Share this post Link to post Share on other sites
TakanoFukada 0 Posted January 21, 2004 pls post a beta script if it's available... i'd love to try this out... Share this post Link to post Share on other sites
Spinor 0 Posted January 22, 2004 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: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_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 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_group = group(_this select 0) _group setBehaviour "SAFE" Share this post Link to post Share on other sites
AdmiralKarlDonuts 0 Posted January 24, 2004 Damn, I haven't checked this thread in a couple of days...I'm going to have to check this out and report back. Thanks! Share this post Link to post Share on other sites
snYpir 0 Posted January 27, 2004 An excellent idea, and an excellent script! Definite potential for inclusion in the ECP as an optional extra. Does skill effect players at all? Or does it only effect AI behaviour? Share this post Link to post Share on other sites
AdmiralKarlDonuts 0 Posted January 27, 2004 I haven't noticed any impact on the player...I think any skill settings are overridden by your natural OFP talent It seems at the moment that AI-controlled groups are affected by the script, but the loon in charge won't know enough to rest his buddies. Maybe there's a way around that, but hey, you know me....I was never a scripter Perhaps Spinor can pull something out of his big bag of tricks Share this post Link to post Share on other sites
snYpir 0 Posted January 27, 2004 An idea that jumps to mind is to flash the screen black at a rate dependant on fatigue. Share this post Link to post Share on other sites
Spinor 0 Posted January 27, 2004 Quote[/b] ]It seems at the moment that AI-controlled groups are affected by the script, but the loon in charge won't know enough to rest his buddies. Maybe there's a way around that, but hey, you know me....I was never a scripter The script itself makes no difference between player or AI controlled. Inserting an automatic REST-modus for AI groups is no problem. I only wonder if this would not create a bag of further problems: Imagine in a fire fight all the enemies sit down and rest just because their leader decided "My guys had enough for now" Share this post Link to post Share on other sites
AdmiralKarlDonuts 0 Posted January 27, 2004 Yeah, that was the first thing that came to mind, actually Share this post Link to post Share on other sites
wi77ard 0 Posted April 10, 2005 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 ..... Share this post Link to post Share on other sites