Results 1 to 5 of 5

Thread: Vehicle repairing itself script, need help

  1. #1
    Master Sergeant
    Join Date
    Jan 15 2002
    Location
    The Netherlands
    Posts
    674
    Right, so I tried making some sort of health regeneration script for vehicles.

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">; We are an armored vehicle
    _vehicle = _this select 0

    ; check our health
    _damage = getDammage _vehicle

    ; start damage control, start repair when damage is sufficient
    #loopcheck
    ?&#40;0.4 &#60; _damage&#41; &#58; goto &#34;repair&#34;

    goto &#34;loopcheck&#34;

    ; start repairing
    #repair
    ?&#40;0 == _damage&#41; &#58; goto &#34;ending1&#34;

    ~1.5
    _damage = _damage - 0.2
    goto &#34;repair&#34;

    #ending1
    ~0.5
    _vehicle vehicleChat &#34;Hull repaired&#34;
    Exit[/QUOTE]

    And the relevant eventhandler for this:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">class EventHandlers &#58; ECP_EventHandlers
    {
    incomingMissile=&#34;_this call &#40;ECP_resources select 44&#41;; if&#40;&#40;_this select 0&#41;==&#40;_this select 0&#41;&#41; then {&#91;_this&#93; exec &#34;&#34;&#92;TerranTank&#92;scripts&#92;spoofmis sile.sqs&#34;&#34;}&#34;;
    hit=&#34;if&#40;&#40;_this select 0&#41;==&#40;_this select 0&#41;&#41; then {&#91;_this&#93; exec &#34;&#34;&#92;TerranTank&#92;scripts&#92;nanobots .sqs&#34;&#34;}&#34;;
    };[/QUOTE]

    And, this gives me an error...
    Look at my signature, LOOK&#33;&#33;&#33; LOOK YOU MAGGOT&#33;&#33;&#33;&#33;

  2. #2
    _damage is not a pointer to the vehicles damage but a new variable with its value, you need to use setDammage in the script to repair the vehicle.

    It would help if you told what the error message says, but I think the problem is that you assume the "hit" &#39;s _this is the unit, but it&#39;s an array:

    _this=[unit, causedBy, damage]

    http://community.bistudio.com/wiki....ist#Hit

    So change the hit handler to:
    _this exec ""&#92;TerranTank&#92;scripts&#92;nanobots.sqs "";

    NOT:
    [_this] exec...

    Also, does the array ECP_resources exist?

  3. #3
    Master Sergeant
    Join Date
    Jan 15 2002
    Location
    The Netherlands
    Posts
    674
    Author of the Thread
    Ok, I tried the setDammage commands, now the script looks like this:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">; Right, we are an armored vehicle
    _vehicle = _this select 0

    ; check our health
    _damage = getDammage _vehicle

    ; start damage control, start repair when damage is sufficient
    #loopcheck
    ?&#40;0.1 &#60; _damage&#41; &#58; goto &#34;repair&#34;

    goto &#34;loopcheck&#34;

    ; start repairing
    #repair
    _vehicle vehicleChat &#34;Hull damage detected, activating nanobots&#34;

    ~1
    _vehicle setDammage 0.2

    ~1
    _vehicle setDammage 0.1

    ~1
    _vehicle setDammage 0

    ~0.7
    _vehicle vehicleChat &#34;Hull repaired&#34;

    Exit[/QUOTE]
    The good news is, the error is gone. The bad news is, the script won&#39;t activate (afaik), I keep on receiving damage untill I die.

    Correct me if I&#39;m wrong but this part:
    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?&#40;0.1 &#60; _damage&#41; &#58; goto &#34;repair&#34;[/QUOTE]
    Stands for when the vehicle has received 10% damage, then go to repair, right?

  4. #4
    Hey Mr.Duck,

    That script works very well for me.
    I took a few hits,it reported the damage
    and repaired it.

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">
    Hit= &#34;if&#40;&#40;_this select 0&#41;==&#40;_this select 0&#41;&#41; then {_this exec &#34;&#34;&#92;PJTA_UD4L&#92;S&#92;Heal.sqs&#34;&# 34;}&#34;;
    [/QUOTE]

    Does your hit EH differ much from this one?
    Apart from the obvious.

    I made no changes in the script.
    So could it be something to do with the
    Ecp EHs?


  5. #5
    Master Sergeant
    Join Date
    Jan 15 2002
    Location
    The Netherlands
    Posts
    674
    Author of the Thread
    It works now, nope my EH did not differ from yours. The problem was that I put the script on the wrong tank...

    Thanks all&#33;

    Here&#39;s a reworked version in case anybody might be interested for future use:

    <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">; Right, we are an armored vehicle
    _vehicle = _this select 0

    ; check our health
    _damage = getDammage _vehicle

    ; start damage control, start repair when damage is sufficient
    #loopcheck
    ?&#40;0.25 &#60; _damage&#41; &#58; goto &#34;repair&#34;

    goto &#34;loopcheck&#34;

    ; start repairing
    #repair
    _vehicle vehicleChat &#34;Hull damage detected, activating nanobots&#34;

    #repairing
    ?&#40;0 == _damage&#41; goto &#34;end1&#34;
    _damage = getDammage _vehicle

    ~1
    _damage = _damage - 0.1
    _vehicle setDammage _damage

    goto &#34;repairing&#34;

    #end1
    _vehicle vehicleChat &#34;Hull repaired, nanobots deactivated&#34;
    Exit
    [/QUOTE]




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •