Home   Help Search Login Register  

Author Topic: Vehicle repair  (Read 815 times)

0 Members and 1 Guest are viewing this topic.

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Vehicle repair
« on: 17 Sep 2005, 03:58:43 »
Here's the thing.

I want a mechanic in my squad who can fix my transport if it breaks down.
I have the theory set down but I don't know how I'm going to do it.

Check the damage of the jeep. If it's undrivable add an action "Repair Jeep". Then checks if designated AI unit in player's group is alive. If he's not, message comes up, "Mechanic is dead".

If he is alive then he moves to the wheel for argument's sake, then does the medic animation. After say 30 seconds, he finishes the animation and the vehicle is repaired.

If the dammage is over, say, 0.7 then he reports that he can't fix the problem. If you've already repaired the vehicle once then he also reports that he can't fix the problem.

I really would like to be able to do this but as I said, I don't know how to go about it. Any help or input of any kind would be greatly appreciated.

Cheers.
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline The-Architect

  • Former Staff
  • ****
  • Bite my shiny metal...
    • Bob's Un-official Flashpoint Page
Re:Vehicle repair
« Reply #1 on: 17 Sep 2005, 04:25:45 »
Ok I found one. It was in the Ed depot.

Trouble is that it only seems to work for one vehicle.

Is there any way I can make it work for two or more?

_fixer = _this select 0
_ride = _this select 1
pack = [_fixer, _ride]



#loop1
?(!canmove _ride): goto "loop2"
goto "loop1"

#loop2
me1 sidechat "Our Landrover is damaged."

#loop3
?(_fixer in _ride): goto "loop3"
?(_fixer distance _ride < 3): goto "actionactivator"
goto "loop3"

#actionactivator
? not (alive jeep) : Goto "Exit"
repair = _fixer addaction ["Repair Landrover", "repair2.sqs"]

#loop4
?(_fixer in _ride): goto "actionremoval"
?(_fixer distance _ride > 3): goto "actionremoval"
?(canmove _ride): goto "lastcheck"
goto "loop4"

#actionremoval
_fixer removeaction repair
goto "loop3"

#lastcheck
?(alldone): goto "finalrun"
goto "lastcheck"

#finalrun
me1 sidechat "Sorted."
goto "loop1"


#Exit
me1 sidechat "It's beyond repair."
Exit
« Last Edit: 17 Sep 2005, 04:26:14 by The-Architect »
James Andrew Wilkinson 1977 - 2005 R.I.P.
"If it ain't the friggin' incoming it's the friggin' outgoing. Only difference is who gets the friggin' grease, and that ain't no friggin' difference at all."

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Vehicle repair
« Reply #2 on: 17 Sep 2005, 10:28:54 »
Should work fine for dozens of vehicles as it uses local variables...
You just call the script with [mechanic,vehicle]...

But, that script is quite cumbersomely written (IMO ::) )...
Too much gotos (no need for goto "actionremoval" for example), and those checking if the vehicle is damaged loops are insane (IMO) as they don't have any delay in them...

It also deals with distances, so when the _fixer closer than 3 meters from the vehicle the action appears, instead of according to damage like you wanted it...

Here's a raw sample how you could do it...
NOTE that this is completely untested and probably won't work as it is (just wrote it 'from the top of my hat') and is most likely infested with bugs...
And doesn't have than anim part in it etc...

And I'm not claiming that this would be any better than the one you posted :)

repair_monitor.sqs (exec with [mechanic,vehicle])
Code: [Select]
goto "init"
#for
; check for conditions
~.5
? !(alive _veh): exit
? !(alive _mec): hint "The mechanic is dead."; exit
? canMove _veh: goto "for"

;add the action to the mechanic if he/she is in the vehicle or close to it..
? _mec in _veh || _mec distance _veh<4: _mec addAction ["Repair Vehicle","repair.sqs"]

#wait
; wait until the vehicle is repaired and the re-start monitoring
~.5
? !(yourtag_repairing): goto "wait"
goto "for"

#init
_mec = _this select 0
_veh = _this select 1

;global variables
yourtag_repairing = false
;-- the vehicle assigned to global variable so that it can be used elsewhere
yourtag_veh = _veh

goto "for"

repair.sqs
Code: [Select]
; get the variables passed in by addAction
; -action attached to
; -action index number
_mec = _this select 0
_inx = _this select 2

; change ###_repairing global varib to true (for the monitoring script use)
yourtag_repairing=true

;remove the action
_mec removeAction _inx

;make the mechanic leave the vehicle
unassignVehicle _mec
_mec action ["eject",yourtag_veh]

;make the mechanic to walk to the vehicle and do a fixing anim
; TODO

;if the vehicle is too damaged, no attempt to repair
? damage yourtag_veh >= 0.7: _mec groupChat "THE VEHICLE IS TOO DAMAGED. I CAN'T FIX IT."; goto "skiprepair"

_i = 0
_a = abs((damage yourtag_veh)/10)
#wait
; play the fixin' anim and wait
yourtag_veh setDamage ((damage yourtag_veh)-0.05)
~.5
_i=_i+0.05
? _i < _a: goto "wait"

_mec groupChat "VEHICLE IS FIXED."

yourtag_veh setDamage 1
yourtag_repairing = false
exit

#skiprepair
; make the mechanic stop the fixing anim
;TODO

yourtag_repairing = false
exit
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:Vehicle repair
« Reply #3 on: 17 Sep 2005, 10:31:49 »
A couple of points:

I would replace the constructs of the type:

Code: [Select]
#loop3
?(_fixer in _ride): goto "loop3"

with

Code: [Select]
@ not (_fixer in _ride)It causes less lag.

Also this line seems to refer to a specific vehicle.

Code: [Select]
? not (alive jeep) : Goto "Exit"

I see you have had a detailed post while I writting so I will stop here.
« Last Edit: 17 Sep 2005, 10:34:49 by THobson »

Offline Terox

  • Former Staff
  • ****
  • Follow the Sappers!
    • zeus-community.net
Re:Vehicle repair
« Reply #4 on: 17 Sep 2005, 11:45:01 »
heres a system i am working on for a private mod


its unfinished, has some bugs but gives you a general idea to get a decent mp system up and running


MISSION EDITOR

Place the following line in the init field of your repair unit
this addaction ["Assess Damage","repair.sqs"]


INIT.sqs
Quote
tx_Repairing = []
tx_RepairOFF = []
tx_RepairON = []



REPAIR.sqs
Quote
goto "INIT"
#DECISION
~2
if ((_u in tx_RepairOFF)||(_time >60))then{goto "Abort"}
if !(_U in tx_RepairON)then{goto "DECISION"}
_weps = (nearestobject[_pos,"weaponholder"])
#REPAIR
~1
_count = _count + 1
if (_u in tx_RepairOFF)then{goto "Abort"}
if(_u distance _obj > 8)then{_u groupchat "Repair terminated.....Reason: too far away"; goto "ABORT"}
if(_count == 5)then{_u playmove "CrouchToWeapon"}else{if(_count == 10)then{_u playmove "CombatReloadMortarEnd"; _count = 0}}
_dam = getdammage _obj
_obj setdammage (_dam -_rpower)
if((_u distance _weps)>1.5)then{_u setpos (getpos _weps)}
if!(vehicle _u == _u)then{hint format["Repair aborted.....Reason: %1 in a vehicle",name _u]; goto "ABORT"}
if (getdammage _obj == 0)then{_u groupchat "Repair Sucessful"}else{goto "REPAIR"}

#ABORT
_u domove _pos
tx_repairing = tx_repairing - [_u]
tx_repairON = tx_repairON - [_u]
tx_repairOFF = tx_repairOFF - [_u]
{_u removeaction _x} foreach[_W0,_w1]
~4
_u groupchat format ["Repair terminated on %1..... Reporting  %2 damage remaining",(typeof _obj),(getdammage _obj)]

_u action ["take weapon",nearestobject([_pos,"secondaryweaponholder"]),0,0,_secw]
~4
_u action ["take weapon",nearestobject([_pos,"weaponholder"]),0,0,_prim]
exit



#INIT
_u = _this select 0
if(_U in tx_repairing)then{hint "Mechanic is already repairing a vehicle";exit}
if!(vehicle _u == _u)then{hint format["%1 Repairs not possible when in a vehicle",name _u]; exit}
_dist = 5
_height = 1.8
;; following is amount of repair per loop
_rpower = 0.00071
~ 0.1
_obj = (nearestobject[(getpos _u select 0)+sin(getdir _u)*_dist,(getpos _u select 1)+cos (getdir _u)*_dist,_height])
_count = 0
if(_obj in zm_units)then{exit}
if(_u distance _obj > 6)then{_u groupchat "Get closer to assess the damage"; exit}
_dam = getdammage _obj
if(_dam ==0)then{_u groupchat format["This %1 appears to be ok",typeof _obj]; exit}
if(_dam ==1)then{_u groupchat format["This %1 is beyond repair",typeof _obj]; exit}
tx_repairing = tx_repairing + [_u]

_rep = _dam/_rpower
;;_rep = _dam * 1200
_prim = primaryweapon _u
_u action ["Drop Weapon",_u,0,0,_prim]
_secw = secondaryweapon _u
_u action ["Drop Weapon",_u,0,0,_secw]
_pos = getpos _u
_u playmove "CrouchToWeapon"
_u groupchat format ["Assessing Damage on %1", typeof _obj]
_r = 3 + (random 7)
~ _r
;;_rep = (_dam * 1200)-_r
_rep = _rep -_r
_mins = _rep /60
_secs = mins mod 1
_mins = _mins - (_mins mod 1)

_u groupchat format["This %1 has %2 damage............................It will take approx %3 to %4 mins to fix",(typeof _obj),_dam,_mins,(_mins + 1)]

_w0 =_u addaction ["Abort Repair","repairOFF.sqs"]
_w1 =_u addaction ["Repair Vehicle","repairON.sqs"]
goto "DECISION"
exit

repairOFF.sqs
Quote
_u = _this select 0
_action = _this select 2
tx_RepairOFF = tx_RepairOFF + [_u]
_U removeaction _action
exit

repairON.sqs
Quote
_u = _this select 0
_action = _this select 2
tx_RepairON = tx_RepairON + [_u]
_U removeaction _action
exit



_______NOTES_______
zm_units is an array of all units on the map

This system works for ai or players.
You can access the ai through your normal radio commands

Stage 1
1) The unit puts down his primary and secondary weapon
2) The unit then assesses the damage and reports back via the group chat an estimated time of repair
3) A new set of actions are then added to the unit, whether to repair or abort
4) If abort repair is selected, the unit picks up his weapons and awaits further orders
5)If repair is selected then the unit loops through a series of animations, repairing at a speed of 0.00071 per second loop
This gives a repair time for an almost fully destroyed vehicle of approx 23 minutes

A fully damaged vehicle will, not be repaired
Ammo crates and other static objects that are not fully destroyed can be repaired

Make sure you define an array of units otherwise your vehicle mechanic will repair those too

As i stated previously, this is a development script for a system in a mod, it isnt even halfway through the development stage, so expect some bugs, cant remember what they were, havent worked on it for several weeks now.

The repair unit is intended to be a "vehicle mechanic" class driving a recovery vehicle, his vehicle has the abiliuty to recover an overturned vehicle
So as a driver/vehicle configuration, the system under development is designed as a parralell option to the "Instant Repair" of the BIS vehicle, as well as fixing some mp system bugs caused by the bis repair vehicle


Intended to make the mission commander decide whether to

a) leave a guard while the recovery mechanic repairs the vehicle
or
b) abandon the vehicle complately

The slow repair speed, has been found during our testing to be the optimised speed, not too fast and not too slow
« Last Edit: 18 Sep 2005, 12:21:19 by Terox »
Zeus ARMA2 server IP = 77.74.193.124 :2302
Teamspeak IP = 77.74.193.123