Home   Help Search Login Register  

Author Topic: empty tank  (Read 1798 times)

0 Members and 1 Guest are viewing this topic.

Offline Seven

  • Members
  • *
  • Am I a llama?
empty tank
« on: 15 Jun 2006, 11:26:15 »
Hi,

I wrote this little "tank.sqs" so empty tanks cannot be destroyed.
Afterwards this will be for MP purpose but thought it would fit better in the general part of the scripting forum.

Can anybody tell me why this doesn't work?
I call it with [this] exec "tank.sqs" / get no errors but the empty tank does take dammage :s

Code: [Select]
_tank = _this select 0
#loop
? (count crew _tank)>=1 : goto "wait"

_damtank = getdammage _tank
~0.5
? (getdammage _tank) > _damtank : _tank setdammage _damtank
~1
goto "loop"

#wait
? (count crew _tank)<=0 : goto "loop"
~1
goto "wait"

Offline Seven

  • Members
  • *
  • Am I a llama?
Re: empty tank
« Reply #1 on: 15 Jun 2006, 11:51:03 »
Ok nm  but thx anyway got solution

Code: [Select]
_tank = _this select 0   
#loop 
_damtank = getdammage _tank   
#innerloop   
? (count crew _tank)>=1 : goto "wait"   
~0.5   
? (getdammage _tank) > _damtank : _tank setdammage _damtank   
~1   
goto "innerloop"   
   
#wait   
? (count crew _tank)<=0 : goto "loop"   
~1   
goto "wait"   

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: empty tank
« Reply #2 on: 15 Jun 2006, 11:57:19 »
you are setting the damage of the tank to the damage of the tank. no wonder it gets damaged.

Code: [Select]
#loop
? (count crew _tank)>=1 : goto "wait"

_damtank = getdammage _tank
~0.5
? (getdammage _tank) > _damtank : _tank setdammage _damtank
~1
goto "loop"

right. there are no crew, so _damtank is set to the tank's damage. half a second later the tank isn't any more damaged, so the script waits a second and loops. if within that second the tank is hit by an rpg, its damage increases. the script loops, gets the tank's damage (which has increased) and uses that new value. say the tank is then hit with another rpg, same thing happens, and so on until >boom<.

my suggestion - use event handlers.

in the tank's init

Code: [Select]
this exec "protect_tank.sqs"
protect_tank.sqs

Code: [Select]
_tank = _this

#start

_tank addeventhandler ["hit",{(_this select 0) setdamage 0}]

#crew_in
~1
?not ((count crew _tank) == 0):_tank removeeventhandler 0; goto "crew_out"
goto "crew_in"

#crew_out
~1
?((count crew _tank) == 0):goto "start"
goto "crew_out"



Offline Seven

  • Members
  • *
  • Am I a llama?
Re: empty tank
« Reply #3 on: 15 Jun 2006, 21:15:55 »
Thx,

I get an error though: ?not ((count crew _tank) == 0):_tank removeeventhandler 0; goto "crew_out"   Error removeeventhandler: Type Number, expected Array

Also this is not the absolute thing I want, maybe a little tuning could do but I dunno how since the script is not called with [this] but with this

If I would drive this tank arround and take some dammage, I could get out of it & blow it up myself with an RPG to have a whole new tank...
So would it be possible get the dammage of the tank first & then give the tank on hit the registered dammage?

Thx in advance!  ::)

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re: empty tank
« Reply #4 on: 15 Jun 2006, 21:49:21 »
Code: [Select]
_tank = _this
_tankdam = 0

#start

_tank addeventhandler ["hit",{(_this select 0) setdamage _tankdam; hint "ouch"} ]

#crew_in
~1
?not ((count crew _tank) == 0):_tank removeeventhandler ["hit",0]; goto "crew_out"
goto "crew_in"

#crew_out
~1
?((count crew _tank) == 0):_tankdam = (getdammage _tank);goto "start"
goto "crew_out"

Offline Seven

  • Members
  • *
  • Am I a llama?
Re: empty tank
« Reply #5 on: 16 Jun 2006, 08:59:04 »
Hi Bedges,

Thx for the reply but that simply doesn't seem to work :s
I get the hint alright, but it takes dammage as if there were no script in it all.
Also tried to start with _tankdam = getdammage _tank    which results in the same

Got more ideas for this?  :-\

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: empty tank
« Reply #6 on: 17 Jun 2006, 00:02:22 »
Hi

Event handlers will do.

Put to initialization field of your vehicle:

Code: [Select]
this exec "initVehicle.sqs"
Then initVehicle.sqs looks like this:

Code: [Select]
_this addEventHandler ["Hit", { if ( count crew (_this select 0) < 1 ) then { _this select 0 setDamage 0 } }]
_this addEventHandler ["Dammaged", { if ( count crew (_this select 0) < 1) then { _this select 0 setDamage 0 } }]

Immortality in Operation Flashpoint can be achieved by combining "Hit" and "Dammaged" event handlers.

Works in single player, multiplayer not tested. Doesn't keep track of the damage level so shooting your own empty damaged tank will give you a tank with zero damage. The problem with keeping track of the damage level is that the damage value must be read before your empty tank has been hit, if you want to maintain the damage level of the moment when the crew got out. So you'll end up having something not so simple as this as a solution.

I think that keeping track of damage level could also be done inside the event handler code blocks so no looping scripts would be required. You could possibly use a "GetOut" event handler to notice the moment when the tank becomes empty, then grab the damage value into a global variable and then in the event handlers written above you would use that global variable with setDamage. A "GetIn" event handler could possibly be used to define the global variable with a dynamically created variable name so that you could get the vehicle stored somewhere (no way to reach at the vehicle from a "GetOut" event handler AFAIK). By creating variable names dynamically you could have many vehicles using the same method and all would have their own global variables for storing the damage values. This would probably require that the "GetOut" event handler be defined inside the "GetIn" event handler to be able to use the dynamically created variable name in there more easily. Oh well there could be easier methods too but there you go, think about it.

The GetOut and GetIn event handler ideas might sound a bit confusing :) I just threw what I had in mind for you so you can chew on that.
« Last Edit: 17 Jun 2006, 10:26:47 by Baddo »

LooseKannon

  • Guest
Re: empty tank
« Reply #7 on: 17 Jun 2006, 07:31:56 »
Doesn't keep track of the damage level so shooting your own empty damaged tank will give you a tank with zero damage. The problem with keeping track of the damage level is that the damage value must be read before your empty tank has been hit, if you want to maintain the damage level of the moment when the crew got out. So you'll end up having something not so simple as this as a solution.

Possible solution, once the tanks crew is out, lock the tank. Maybe not the best idea, if your planning to get back into it, but it might prove a quick fix to the problem?

Offline Seven

  • Members
  • *
  • Am I a llama?
Re: empty tank
« Reply #8 on: 17 Jun 2006, 08:17:58 »
I will chew on that alright  :)

Got one more question.
If I am to use
Code: [Select]
_tank = _this

#start

_tank addeventhandler ["hit",{(_this select 0) setdamage 0}]

#crew_in
~1
?not ((count crew _tank) == 0):_tank removeeventhandler 0; goto "crew_out"
goto "crew_in"

#crew_out
~1
?((count crew _tank) == 0):goto "start"
goto "crew_out"

How do I launch another script for "this" tank from within this script?
Can I do this with [_tank] exec "anotherscript.sqs" ? since _tank = _this and not _tank = this select 0
or does it have to be _tank exec "anotherscript.sqs"

Offline Baddo

  • Former Staff
  • ****
  • Reservist Jaeger
Re: empty tank
« Reply #9 on: 17 Jun 2006, 10:15:59 »
Doesn't keep track of the damage level so shooting your own empty damaged tank will give you a tank with zero damage. The problem with keeping track of the damage level is that the damage value must be read before your empty tank has been hit, if you want to maintain the damage level of the moment when the crew got out. So you'll end up having something not so simple as this as a solution.

Possible solution, once the tanks crew is out, lock the tank. Maybe not the best idea, if your planning to get back into it, but it might prove a quick fix to the problem?

Oh yeah you mean that once you get out of a vehicle, then you can't enter it never again in the mission. Well that's a solution of some kind, and simple :)

@Seven

You don't need _tank = _this in your script, you can use _this in the whole script if you pass the tank for your script like this exec "script.sqs" from the initialization field. If you do _tank = _this in your script, you will be creating another variable for the same thing. _this is already pointing at your tank and then you go and make _tank point at it too, which is not needed.

In a simple script like this where you are only passing one argument for your script, you don't need to use the brackets [] when you pass arguments. The brackets mean that you are creating an array and giving that array to your script. Then in your script you would need to pick items from that array by using select. As you can understand for sure, that is a bit pointless if you only have one argument to pick from.

As to your question, if you pass the tank for your script with this exec "script.sqs" from the initialization field, then in the script you can use _this all the time to point to the tank. This means that if you want to start a new script and pass the tank to that script, then _this exec "anotherscript.sqs" will do it. Then again, if you had multiple arguments for the first script like [this, "boogie", 700] exec "script.sqs" now you would start the new script from the first script by writing _this select 0 exec "anotherscript.sqs" and that should work ok too.

I suggest you try to do what are you trying to achieve without looping scripts and go for the event handler idea, that way you would get better performance especially if you need this functionality for alot of vehicles in a mission.

Offline Seven

  • Members
  • *
  • Am I a llama?
Re: empty tank
« Reply #10 on: 18 Jun 2006, 00:39:04 »
Thx for these replies,
some things that were written here will be read again & again cause I had no experience with eventhandlers at all!  :)

I came to a solution & want to thank HitmanFF for helping me to it!

Code: [Select]
#start 
~1 
_vcl = _this select 0 
0.5 
_vcldamage = getdammage _vcl
#loop 
~1 
_vclclass = typeOf _vcl 
_vclpos = getpos _vcl 
_vcldir = getdir _vcl 
_vclweapArray = weapons _vcl 
_vclmagArray = magazines _vcl 
_vclfuel = fuel _vcl 
vehiclename = objNull 
   
#innerloop     
? (count crew _vcl) >=1 : goto "wait"     
~0.5
? (getdammage _vcl) >= 0.8 : goto "new"
? (getdammage _vcl) > _vcldamage : _vcl setdammage _vcldamage 
~1     
goto "innerloop" 
#wait
_vcldamage = getdammage _vcl 
? (count crew _vcl) <=0 : goto "innerloop"
~1
goto "wait"

#new
deleteVehicle _vcl
~1

_vcl = _vclclass createVehicle _vclpos
_vclweapArrayFull = weapons _vcl
_vclmagArrayFull = magazines _vcl
_vcl setdir _vcldir
_vcl setfuel _vclfuel
{_vcl RemoveMagazines _x} forEach _vclmagArrayFull
{_vcl RemoveWeapon _x} forEach _vclweapArrayFull
ClearWeaponCargo _vcl
ClearMagazineCargo _vcl
{_vcl addMagazine _x} forEach _vclmagArray
{_vcl addWeapon _x} forEach _vclweapArray
_vcl setdammage _vcldamage
_vcl lock False
~0.5
goto "innerloop"

have an M1A1 & a BMP, fire on them when empty, man them & fire again, make them empty again & check the dammage on the M1, empty it again etc...
This works fine!

Cheers  8)
« Last Edit: 18 Jun 2006, 01:38:54 by Seven »