Jump to content
Sign in to follow this  
Allanp

Refueling with Jerry can problems. Trigger not attaching to vehicle.

Recommended Posts

Allo allo people,

I'm fairly new to scripting (but made some major strides by dissecting some missions) and I came to small standstill with a mission I've been working on. I've set a trigger up to set fuel on a car to 0. Now what I had planned was the player to find a jerry can and bring it over to the car to fill it up again.

I was thinking on setting up a trigger to check if the jerry can was within the trigger range (but I am not sure how to activate triggers on specialized objects, if this is even possible).

If there are any alternatives to this I am more than happy to hear.

------------

After some trial and error I got it working!

-----

And not so much anymore. I've set up an object and grouped it with a trigger. It shoots off a hint once it is detected in the area, now my problem comes when I attach the trigger to a vehicle, it doesn't want to fire out the OnAct commands for some reason. I'm stumped.

Trigger

Con: this

Onact : u1 setFuel 1; titleText ["Truck refueled","PLAIN"]; gas attachto [u1,[0,0,0]];

that is grouped up with a fuel can.

u1 refers to the vehicle, I also tested making the trigger extremely large. I also suspected that the trigger might not be attaching to the vehicle for some reason (I tried walking towards the vehicle and then walked to where I originally placed the trigger and it shot the onact)

Share this post


Link to post
Share on other sites

I wouldn't do it that way but it does work. I had the same problem until I realised I'd used ul instead of u1 on one item.

I'd use addaction.

Place the addaction in the vehicles init box

u1 addaction ["Refuel truck","fill.sqf","",1,false,true,"","gas distance u1 <= 5   and player distance u1 <= 5"];

code save as fill.sqf

titleText ["refueling","PLAIN"];

u1 removeaction (_this select 2);

sleep 5;

u1 setfuel 0.3;

gas attachto [u1,[0,0,0]];

titleText ["Truck refueled","PLAIN"];


Share this post


Link to post
Share on other sites

Worked like a charm F2k Sel! Cheers mate :D

Share this post


Link to post
Share on other sites

Edit: Figured it out

Edit: Nope!

Edited by Allanp

Share this post


Link to post
Share on other sites

Ok new problem. I made a case switch to attach the jerrycan onto the back of the truck. Problem is that the previous actions found in the carry.sqf still appears ( I used yours F2k Sel). Which causes the add action menu to go crazy and start cluttering the action menu with double or even triple commands of the same thing. I can't seem to figure out how to disable it or how to combine it into one major sqf. I was thinking about using an if statement to check if the player was even closer to the truck or behind (not sure how to get that, perhaps it can check if the player is near the rear wheel or boot of the truck?)

Carry

switch (take) do
{
   case 0:
   {
    _scase = _this select 0;
     _man = _this select 1;
_scase attachto [_man, [-0.23,0,-0.15],"Pelvis"];
      _scase setdir 75;
       _scase removeAction act1;
        act1 = _man addaction ["Drop Jerry Can","carry.sqf","",1,false,true,""];
         take=1;scase = _scase;taken=true;
   }; 

   case 1:
   {
      _man = _this select 0;
        detach scase;
         scase setvelocity[0,0,-.3];
          _man removeAction act1;
           act1 = scase addaction ["Take Jerry Can","carry.sqf","",1,false,true,""];
            take=0;
   };
};

ATTACH

switch (take) do
{


   case 0:
   {
      _truck = u1;
        detach gas;
         gas setvelocity[0,0,-.3];
        titleText ["Fastening Jerry Can to Truck","PLAIN"]; 
        sleep 5;
	gas attachTo [u1,[-0.9,-3.1875,-0.5]]; 
	titleText ["Jerry Can is secured","PLAIN"]; 
          _truck removeAction act2;
           act2 = _truck addaction ["Remove from Truck","attachtruck.sqf","",1,false,true,""];
            take=1;
   };  
     case 1:
   {
_gas = gas;
_truck = u1;
 detach gas;
      _gas setvelocity[0,0,-.3];
_man = player;
    _gas attachto [_man, [-0.23,0,-0.15],"Pelvis"];
       _truck removeAction act2;
        act2 = _truck addaction ["Attach to back of Truck","attachtruck.sqf","",1,false,true,""];
         take=0;taken=true;
   }; 
};

Maybe the player has to drop the jerry can near the truck and use it via the action of the jerry can? (stumped..)

Share this post


Link to post
Share on other sites

The problem is that the script needs redoing using setvariable ect but I just don't have the time.

I did tidy it up a little and it does work, I had to go back to my own previous script and add your bits to it.

First name the fuel can scase, you can change it later.

place this in the truck init and name it u1

act2 = u1 addaction ["attach to truck","attachtruck.sqf",[1],1,false,true,"","player distance u1 < 4"]; 

place this in the fuel can init and name it scase

 act1 = this addaction ["Take Fuel Can","carry.sqf",[0],1,false,true,"","player distance scase < 2"]

save as carry.sqf

//act1 = this addaction ["Take Case","carry.sqf",[0],1,false,true,"",""]

switch (take) do
{
   case 0:
   {
    scase = _this select 0;
     _man = _this select 1;
       scase attachto [man, [-0.23,0,-0.15],"Pelvis"];
        scase setdir 75;
         scase removeAction act1;
         act1 = _man addaction ["Drop Jerry Can","carry.sqf",[1],1,false,true,"",""];
          _man addEventHandler ["killed", "detach scase;_man removeeventHandler [""killed"",0]"];
   }; 

   case 1:
   {
      _man = _this select 0;
        detach scase;
         scase setvelocity[0,0,-.3];
          _man removeAction act1;
           act1 = scase addaction ["Take Jerry Can","carry.sqf",[0],1,false,true,"","player distance scase < 3"];
            _man removeeventHandler ["killed",0];
   };
};

//act2 = u1 addaction ["attach to truck","attachtruck.sqf",[1],1,false,true,"","player distance u1 < 4"]

player removeAction act1;


switch (take) do
{
  case 0:
   {
     detach scase;
      titleText ["Fastening Jerry Can to Truck","PLAIN"]; 
       u1 removeAction act2;
        sleep 5;
         scase attachTo [u1,[-0.9,-3.1875,-0.5]]; 
          titleText ["Jerry Can is secured","PLAIN"]; 
          u1 removeAction act2;
           act2 = scase addaction ["Remove from Truck","attachtruck.sqf","",1,false,true,"","player distance scase < 2"];
            take=1;
   };  

  case 1:
   {
    detach scase;
     _man = player;
       scase attachto [_man, [-0.23,0,-0.15],"Pelvis"];
         scase setdir 75;
           scase removeAction act2;
            act2 = u1 addaction ["Attach to back of Truck","attachtruck.sqf","",1,false,true,"player distance u1 < 2"];
             act1 = _man addaction ["Drop Jerry Can","carry.sqf",[1],1,false,true,"",""];
              take=0;
   }; 
};  

Known problems obviously the global variables and poor names of items.

There is also a problem where the second time around you can attach the can from a great distance, I can't see why this happens as it's set to less than 2meters.

Share this post


Link to post
Share on other sites

F2k Sel: Fixed being able to attach from a long distance. Only problem I am facing now is that sometimes act1 in act2 doesn't initialize and I end up sticking the jerry can with the player attached to it to the truck.

I also changed the names and added a few comments. I also want to say thanks for being such a big help, any contribution is fine and you have gone far beyond what I expected to be contributed.

Carry

//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: TODO: Author Name
//////////////////////////////////////////////////////////////////


//init: take=0;  act1 = this addaction ["Take Fuel Can","carry.sqf",[0],1,false,true,"","player distance scase < 2"]  
//Jerry Can starts at case 0 so first the player can pick it up
switch (take) do
{
//pick up jerry can
   case 0:
   {
    _scase = _this select 0;
     _man = _this select 1;
_scase attachto [_man, [-0.23,0,-0.15],"Pelvis"];
     _scase setdir 75;
     _scase removeAction act1;
      act1 = _man addaction ["Drop Jerry Can","carry.sqf","",1,false,true,""];
      take=1;scase = _scase;taken=true;
   }; 

   case 1:
   {
      _man = _this select 0;
       detach scase;
       scase setvelocity[0,0,-.3];
      _man removeAction act1;
       act1 = scase addaction ["Take Jerry Can","carry.sqf","",1,false,true,""];
       take=0;
   };
};

Attach

//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: TODO: Author Name
//////////////////////////////////////////////////////////////////

//init: truck_start addaction ["Refuel truck","fill.sqf","",1,false,true,"","scase distance truck_start <= 5  and player distance truck_start <= 5"]; 
//act2 = truck_start addaction ["Attach Options","attachtruck.sqf",[1],1,false,true,"","player distance truck_start < 4 and player distance scase < 4"];

player removeAction act1;

switch (take) do
{
//Fasten jerry can to back of truck
  case 0:
   {
     titleText ["Fastening Fuel Can to Truck","PLAIN"]; 
     truck_start removeAction act2;
     detach scase;
     sleep 5;
     scase attachTo [truck_start,[-0.9,-3.1875,-0.5]]; 
     titleText ["Jerry Can is secured","PLAIN"]; 
     truck_start removeAction act2;//remove action so that player doesn't select it again
     act2 = scase addaction ["Remove from Truck","attachtruck.sqf","",1,false,true,"","player distance scase < 2"]; //change action for next case
     take=1;
   };  
   //Attach Jerry Can to hip after removing jerry can from back of truck
  case 1:
   {
    _man = player
titleText ["Unfastening Fuel Can","PLAIN"];
sleep 5;
     detach scase;
     sleep 1;
     act2 = truck_start addaction ["Attach to back of Truck","attachtruck.sqf","",1,false,true,"player distance truck_start < 2 and player distance scase < 2"];
     act1 = _man addaction ["Drop Jerry Can","carry.sqf",[1],1,false,true,"",""];
     take=0;
   };
};  


Share this post


Link to post
Share on other sites

OK I've had a run through it and it seems better now.

I've changed a fair bit, a part from at the start there are no actions on the truck. Now they are on the man and Jerry can. I'm using take==0 to stop actions when you don't have the can.

See how you go.

//act3 = truck_start addaction ["Refuel truck","fill.sqf","",1,false,true,"","scase distance truck_start <= 5  and player distance truck_start <= 5 and take==0"]; 
//act2 = truck_start addaction ["Attach Options","attachtruck.sqf",[1],1,false,true,"","player distance truck_start < 4 and player distance scase < 4  and take==0"]; 

player removeAction act1;
truck_start removeAction act2;// remove initial action on truck.
_man = player;

//Fasten jerry can to back of truck 
switch (take) do
{
  case 0:
   {
     detach scase;
      titleText ["Fastening Jerry Can to Truck","PLAIN"]; 
       player removeAction act2;
        sleep 5;
         scase attachTo [truck_start,[-0.9,-3.1875,-0.5]]; // attach to vehicle
          titleText ["Jerry Can is secured","PLAIN"];          
            act2 = scase addaction ["Remove from Truck","attachtruck.sqf","",1,false,true,"","player distance scase < 2"];//change action for next case 
             take=1;
   };  

 //Attach Jerry Can to hip after removing jerry can from back of truck     

  case 1:
   {
    detach scase;
      titleText ["Unfastening Fuel Can","PLAIN"]; 
       scase removeAction act2;
        sleep 5;
         scase attachto [_man, [-0.23,0,-0.15],"Pelvis"]; // attach to player
          scase setdir 75;           
            act2 = _man addaction ["Attach to back of Truck","attachtruck.sqf","",1,false,true,"","player distance truck_start < 5 and scase distance truck_start < 5 and take==0"];
             act1 = _man addaction ["Drop Case","carry.sqf",[1],1,false,true,"",""];
              take=0;
   }; 
};  

Share this post


Link to post
Share on other sites

Fiddled around with it some more, but for some reason the scripterror is showing that line 20 ( the if statement) is missing a ")" but it is clearly there, unless I am missing something else.

A problem I found is that when I have attached the Jerry Can to the truck the "Take Jerry Can" option is still present and it can really mess up the player by creating multiple instances in the action menu. I think it is the init when on the Fuel Can. I'll have to play around with it some more, but I'll post what I have here for anyone else interested in taking a crack at this code for themselves or for their missions. These few days have been a blast trying to get this thing to work, even though it is a hair puller I am learning loads. Gathering more ideas on making a simple mission...

//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: TODO: Author Name
//////////////////////////////////////////////////////////////////

//Init for Vehicle below
//act3 = truck_start addaction ["Refuel truck","fill.sqf","",1,false,true,"","scase distance truck_start <= 5  and player distance truck_start <= 5 and take==0"]; 
//act4 = truck_start addaction ["Attach Options","attachtruck.sqf",[1],1,false,true,"","player distance truck_start < 4 and player distance scase < 4  and take==0"]; 

player removeAction act1;
truck_start removeAction act2;// remove initial action on truck.
_man = player;
_removeAttachOption = 0;


switch (take) do
{  
//Remove the "Attach Option".
case 0:
   {
    	if ( _removeAttachOption = 1 ) then
      {
       act2 = _man addaction ["Attach to back of Truck","attachtruck.sqf","",1,false,true,"","player distance truck_start < 5 and scase distance truck_start < 5 "];
       take=1;
      }
      else
      {
  _removeAttachOption =1;
  player removeAction act4;
  titleText ["Seems like you can attach the Jerry Can to the Truck","PLAIN"];
};

   };
   //Fasten jerry can to back of truck 
  case 1:
   {
     detach scase;
      titleText ["Fastening Jerry Can to Truck","PLAIN"]; 
       player removeAction act2;
        sleep 5;
         scase attachTo [truck_start,[-0.9,-3.1875,-0.5]]; // attach to vehicle
          titleText ["Jerry Can is secured","PLAIN"];          
            act2 = scase addaction ["Remove from Truck","attachtruck.sqf","",1,false,true,"","player distance scase < 2"];//change action for next case 
             take=2;
   };  

 //Attach Jerry Can to hip after removing jerry can from back of truck     

  case 2:
   {
    detach scase;
      titleText ["Unfastening Jerry Can","PLAIN"]; 
       scase removeAction act2;
        sleep 5;
        titleText ["You place the Jerry Can by your side","PLAIN"];
         scase attachto [_man, [-0.23,0,-0.15],"Pelvis"]; // attach to player
          scase setdir 75;           
            act2 = _man addaction ["Attach to back of Truck","attachtruck.sqf","",1,false,true,"","player distance truck_start < 5 and scase distance truck_start < 5 and take==0"];
             act1 = _man addaction ["Drop Jerry Can","carry.sqf",[1],1,false,true,"",""];
              take=1;
   }; 

};  

Share this post


Link to post
Share on other sites

OK I changed the approach I was using, I was attaching and detaching the Can directly to the truck and palyer.

I've changed this now to where you drop it close then the option to attach to truck action shows.

Really needs a sound effect of can hitting the ground.

//act3 = truck_start addaction ["Refuel truck","fill.sqf","",1,false,true,"","scase distance truck_start <= 5  and player distance truck_start <= 5 and take==0"]; 
//act2 = truck_start addaction ["Attach Options","attachtruck.sqf",[1],1,false,true,"","player distance truck_start < 4 and player distance scase < 4  and take==0"]; 

player removeAction act1;
truck_start removeAction act2;// remove initial action on truck.
_man = player;

//Fasten jerry can to back of truck 
switch (take) do
{
  case 0:
   {
     detach scase;
      titleText ["Fastening Jerry Can to Truck","PLAIN"]; 
       player removeAction act2;
       scase removeaction act1;
        sleep 5;
         scase attachTo [truck_start,[-0.9,-3.1875,-0.5]]; // attach to vehicle
          titleText ["Jerry Can is secured","PLAIN"];          
            act2 = scase addaction ["Remove from Truck","attachtruck.sqf","",1,false,true,"","player distance scase < 4"];//change action for next case 
             take=1;
   };  

 //Attach Jerry Can to hip after removing jerry can from back of truck     

  case 1:
   {
    detach scase;
      titleText ["Unfastening Fuel Can","PLAIN"]; 
        sleep 5;
         scase removeAction act2;
           scase setvelocity[0,0,-.3];
        // scase attachto [_man, [-0.23,0,-0.15],"Pelvis"]; // attach to player
        //  scase setdir 75;           
            act2 = _man addaction ["Attach to back of Truck","attachtruck.sqf","",1,false,true,"","player distance truck_start < 5 and scase distance truck_start < 5 and take==0"];
            act1 = scase addaction ["Take Jerry Can","carry.sqf","",1,false,true,""];
              take=0;
   }; 
};  

Edited by F2k Sel

Share this post


Link to post
Share on other sites

I think we've nearly got this perfected. I played around with it a bit more and I really didn't like how Attach Options was still available and it would activate case 0 of attachtruck.sqf so I made it a seperate .sqf.

Posting all the code for anyone who wants to try this out,modify it or perfect it.

AttachOption

//int for jerrycan 
//take=0;  act1 = this addaction ["Take Fuel Can","carry.sqf",[0],1,false,true,"","player distance scase < 2"];
//act3 = this addaction ["Refuel truck","fill.sqf","",1,false,true,"","scase distance truck_start <= 5  and player distance truck_start <= 5 and take==0"]; 
//act4 = this addaction ["Attach Options","attachoption.sqf",[1],1,false,true,"","player distance truck_start < 4 and player distance scase < 4  and take==0"]; 

titleText ["Seems like you can attach this to the Truck","PLAIN"]; //Initial message when player chooses Attach Option on addaction menu

scase removeaction act4; //Removes Attach Option from addaction menu

sleep 2; 

titleText ["You figured out how to attach it.","PLAIN"]; // Joyest Message given to player

sleep 3; 

[]execVM "attachtruck.sqf"; // executes attachment to truck

Attach Truck

//Script created with major help from  F2k Sel
//act3 = truck_start addaction ["Refuel truck","fill.sqf","",1,false,true,"","scase distance truck_start <= 5  and player distance truck_start <= 5 and take==0"]; 
//act2 = truck_start addaction ["Attach Options","attachtruck.sqf",[1],1,false,true,"","player distance truck_start < 4 and player distance scase < 4  and take==0"]; 
// (These inits I placed on the Jerry Can instead of the Truck, not sure if it changes the effectiveness of the script, check AttachOption.sqf for full attachment on Jerry Can)


player removeAction act1;
truck_start removeAction act2;// remove initial action on truck.
_man = player;

//Fasten jerry can to back of truck 
switch (take) do
{
  case 0:
   {
     detach scase;
      titleText ["Fastening Jerry Can to Truck","PLAIN"]; 
       player removeAction act2;
       scase removeaction act1;
        sleep 5;
         scase attachTo [truck_start,[-0.9,-3.1875,-0.5]]; // attach to vehicle
          titleText ["Jerry Can is secured","PLAIN"];          
            act2 = scase addaction ["Remove from Truck","attachtruck.sqf","",1,false,true,"","player distance scase < 4"];//change action for next case 
             take=1;
   };  

 //Attach Jerry Can to hip after removing jerry can from back of truck     

  case 1:
   {
    detach scase;
      titleText ["Unfastening Fuel Can","PLAIN"]; 
        sleep 5;
         scase removeAction act2;
           scase setvelocity[0,0,-.3];
        // scase attachto [_man, [-0.23,0,-0.15],"Pelvis"]; // attach to player
        //  scase setdir 75;           
            act2 = _man addaction ["Attach to back of Truck","attachtruck.sqf","",1,false,true,"","player distance truck_start < 5 and scase distance truck_start < 5 and take==0"];
            act1 = scase addaction ["Take Jerry Can","carry.sqf","",1,false,true,""];
              take=0;
   }; 
}; 

Carry

//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: TODO: Author Name
//////////////////////////////////////////////////////////////////

//Script pulled from  F2k Sel
//init: take=0;  act1 = this addaction ["Take Fuel Can","carry.sqf",[0],1,false,true,"","player distance scase < 2"]  
//Jerry Can starts at case 0 so first the player can pick it up

switch (take) do
{
//pick up jerry can
   case 0:
   {
    _scase = _this select 0;
     _man = _this select 1;
_scase attachto [_man, [-0.23,0,-0.15],"Pelvis"];
     _scase setdir 75;
     _scase removeAction act1;
      act1 = _man addaction ["Drop Jerry Can","carry.sqf","",1,false,true,""];
      take=1;scase = _scase;taken=true;
   }; 

   case 1:
   {
      _man = _this select 0;
       detach scase;
       scase setvelocity[0,0,-.3];
      _man removeAction act1;
       act1 = scase addaction ["Take Jerry Can","carry.sqf","",1,false,true,""];
       take=0;
   };
};

Fill

//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: TODO: Author Name
//////////////////////////////////////////////////////////////////

//Script created with major help from  F2k Sel

titleText ["Refueling","PLAIN"]; 

truck_start removeaction (_this select 2); 

sleep 10; 

truck_start setfuel 0.3; 

titleText ["Truck refueled","PLAIN"];  

Share this post


Link to post
Share on other sites

How do you want the attach to truck to work?

Other things that really need fixing are :-

When you die you need to release the can, I had that working and needs putting back.

When you get in a truck while carrying item it sticks out the window. I see two solutions, Auto drop item or try and prevent entry while carrying.

Set variable for full and empty can.

Script need placing in one folder, minor path change.

Share this post


Link to post
Share on other sites

Allo F2k Sel,

After testing it out and having a few runs with a couple of buddies ( I know the code isn't for multiplayer, I just needed a few lab mice to see where an ideal spot was to place the jerry can), they seemed confused on how to attach it (drop and look)I might switch back so that the actions appear on the truck. (I could easily pop in a hint that tells the player to look at the can for more options when near the vehicle).

Edit: I'll keep with the actions on the truck but you have to drop the can. I like this approach.

Edit2: I've added sounds for fueling and attaching to truck that my friend made for me, I'll have to wait till he is online for the dropping sound.

From the things that need fixing

1. Will definitely put that back in.

2. I was thinking about that yesterday, I think a force disembark or eject with a prompt or hint (something witty like "You struggle to get in") would work perfectly

3. I was writing a mini abstraction for that early today. I was trying to figure out if there is a way to have a global variable and then call to check it in another function.

What I had planned was a trigger would be set near a fuel pump, the player would go to the fuel pump with the jerry can, drop it and be able to fill it (I'll pop an animation in)

The amount of fuel (fuelAmount) would be random (between 0.1-1.0) in the fuel pump and would be added to an int var on the Jerry Can (jerryfuelAmount).

I would have a statement to check if it would be over 1.0 and it would set jerryfuelAmount to 1. I also had plans so that the player could check how much fuel was in the jerry can

via nested loops (quarter,half,three thirds and full).

4. Cheers for reminding me about that! I'll get on that right away.

Edited by Allanp

Share this post


Link to post
Share on other sites

Had a big problem today, when I added the killed eventhandler I kept getting multiple actions. I t took forever to sort it out but seems to be working.

I've also added a kick out from vehicle if carrying can.

I used calls for these as I needed to learn how to use them and it saves adding more scripts or adding them to the case statement.

It's better to use setvariable and getvariable. ie

scase setvariable ["fuel",10,true];

hint format ["Jerry Can Has %1 Liters of Fuel",scase getvariable "fuel"];

//Script pulled from  F2k Sel
//init: take=0;  act1 = this addaction ["Take Fuel Can","carry.sqf",[0],1,false,true,"","player distance scase < 2"]  
//Jerry Can starts at case 0 so first the player can pick it up

private ["_In_out","_man"];



////////////// checks for player in or out of car  ////////////////
_in_car = {
_In_out = createTrigger["emptyDetector",[0,0,0]];
_In_out setTriggerArea [0,0,0,false]; 
_In_out setTriggerActivation ["any","present",True]; 
//_In_out setTriggerStatements["(vehicle player) != player and take == 1",";scase hideobject true;","scase hideobject false;"];// hides object
_In_out setTriggerStatements["(vehicle player) != player and take == 1","player action ['getout',nearestObject [player,'car']]; Hint 'Get out you idiot!';",""];// kicks you out if carrying
_return
};



////////// checks if player is dead ///////////////////
_evh_Killed = {
_man removeeventHandler ["killed",0];
_man addEventHandler ["killed", {
detach scase;hint "dead";
scase removeAction act1;
act1 = scase addaction ["Take Jerry Can","carry.sqf","",1,false,true,""];
 take=0;(_this select 0) removeeventHandler ["killed",0];  } ];
 	      _return
     };

switch (take) do
{
   //pick up jerry can
   case 0:
   {
    _scase = _this select 0;
     _man = _this select 1;
   _scase attachto [_man, [-0.23,0,-0.15],"Pelvis"];
     _scase setdir 75;
     _scase removeAction act1;
      act1 = _man addaction ["Drop Jerry Can","carry.sqf","",1,false,true,""];
      take=1;scase = _scase;_man call _in_car; _man call _evh_Killed;
      hint format ["Jerry Can Has %1  Liters of Fuel",scase getvariable "fuel"];
      }; 

   case 1:
   {
      _man = _this select 0;
       detach scase;
       scase setvelocity[0,0,-.3];
      _man removeAction act1;
       act1 = scase addaction ["Take Jerry Can","carry.sqf","",1,false,true,""];
       take=0;deletevehicle _In_out;
        _man removeeventHandler ["killed",0];

   };
};  

Place this in the fuel cans init, you can adjust amount of fuel if you wish. It's not pretty but it worked.

scase setvariable ["fuel",10,true];

//Script created with major help from  F2k Sel


_fuel = scase getvariable "fuel";


if (_fuel == 0)  exitwith {Hint "Your can is empty"};

titleText ["Refueling","PLAIN"]; 

truck_start removeaction (_this select 2); 

while {sleep 0.3 ; _fuel >0 } do {
_fuel=_fuel-0.3;
if (_fuel < 0) then {_fuel=0};


hint format ["Jerry Can Has %1  Liters of Fuel",_fuel];


};

scase setvariable ["fuel",_fuel,true];

truck_start setfuel 0.3; 

titleText ["Truck refueled","PLAIN"];  

Share this post


Link to post
Share on other sites

Cheers F2k Sel!

I got a chance to play with it some more. I changed it so the value put on fuel will determine how full the truck will be. The only problem I have now is in carry (the changes I made) where it still states the Jerry Can as being full, would I have to merge them so that the value is constant or is there a way to call that var from another script? I also found a problem, when I attach the can to the truck and try to enter it kicks me out. but if I detach it from the truck and enter it lets me in.

As always, your help is greatly appreciated.

Carry

//Script pulled from  F2k Sel
//init: take=0;  act1 = this addaction ["Take Fuel Can","carry.sqf",[0],1,false,true,"","player distance scase < 2"]  
//Jerry Can starts at case 0 so first the player can pick it up

private ["_In_out","_man"];



////////////// checks for player in or out of car  ////////////////
_in_car = {
_In_out = createTrigger["emptyDetector",[0,0,0]];
_In_out setTriggerArea [0,0,0,false]; 
_In_out setTriggerActivation ["any","present",True]; 
//_In_out setTriggerStatements["(vehicle player) != player and take == 1",";scase hideobject true;","scase hideobject false;"];// hides object
_In_out setTriggerStatements["(vehicle player) != player and take == 1","player action ['getout',nearestObject [player,'car']]; Hint 'Get out you idiot!';",""];// kicks you out if carrying
_return
};



////////// checks if player is dead ///////////////////
_evh_Killed = {
   _man removeeventHandler ["killed",0];
   _man addEventHandler ["killed", {
   detach scase;hint "dead";
   scase removeAction act1;
   act1 = scase addaction ["Take Jerry Can","scripts\take_fill_attach\carry.sqf","",1,false,true,""];
    take=0;(_this select 0) removeeventHandler ["killed",0];  } ];
     _return
     };

switch (take) do
{
   //pick up jerry can
   case 0:
   {
    _scase = _this select 0;
     _man = _this select 1;
     _fuel = scase getvariable "fuel";
     _fuelCount = _fuel;
if (_fuel >=1) then {_fuelCount=10; _fuel=10; titleText ["This feels full","PLAIN"]};
if (_fuel > 0 and _fuelCount < 1) then {_fuelCount=_fuel*10};
       if (_fuelCount > 5 and _fuelCount < 10) then {titleText ["This  feels somewhat full","PLAIN"]};
       if (_fuelCount >=3 and _fuelCount < 5 ) then {titleText ["This feels half way full","PLAIN"]};
       if (_fuelCount >=1 and _fuelCount < 3 ) then {titleText ["This feels close to empty","PLAIN"]};
       if (_fuel == 0) then {titleText ["This feels empty","PLAIN"]};
     _scase attachto [_man, [-0.23,0,-0.15],"Pelvis"];
     _scase setdir 75;
     _scase removeAction act1;
      act1 = _man addaction ["Drop Jerry Can","scripts\take_fill_attach\carry.sqf","",1,false,true,""];
      take=1;scase = _scase;_man call _in_car; _man call _evh_Killed;
      hintSilent format ["Jerry Can Has %1  Liters of Fuel",_fuelCount];
      }; 

   case 1:
   {
      _man = _this select 0;
       detach scase;
       scase setvelocity[0,0,-.3];
      _man removeAction act1;
       act1 = scase addaction ["Take Jerry Can","scripts\take_fill_attach\carry.sqf","",1,false,true,""];
       take=0;deletevehicle _In_out;
        _man removeeventHandler ["killed",0];

   };
};  

Fill


//Script created with major help from  F2k Sel


_fuel = scase getvariable "fuel";
_fuelCount = _fuel;

if (_fuel >=1) then {_fuelCount=10; _fuel=10};
if (_fuel > 0 and _fuel < 1) then {_fuelCount=_fuel*10};
if (_fuel == 0) exitwith {Hint "Your can is empty"};
_rest = 10-_fuelCount;

titleText ["Refueling","PLAIN"]; 

scase say ["Candecant",5]; // sound for fueling truck (clip is 10secs)


truck_start removeaction act3; 

while {sleep  1; _fuelCount >0 } do {
_fuelCount=_fuelCount-1;
if (_fuelCount < 0) then {_fuelCount=0};


hintsilent format ["Jerry Can Has %1  Liters of Fuel",_fuelCount];


};

sleep _rest;

scase setvariable ["fuel",_fuel,true];

truck_start setfuel _fuel; 

titleText ["Truck refueled","PLAIN"];  

Edited by Allanp

Share this post


Link to post
Share on other sites

Hi Allanp.

Took an age to debug some of these actions.

I've changed the way the take variable works, it now changes to a value which corresponds to what actions are being used.

I'm not going to say it's sorted as there's bound to be something messing up and it needs a major clean up.

What I think I've fixed.

Getting kicked when fuel attached to truck.

All options removed when getting in vehicle.

All options removed when refuelling.

Fuel amounts now work correctly. (you hadn't passed _fuelcount to setvariable)

I've removed the truck startup eventhandlers and they're applied when you drop a can near to the truck.

I've done it as a download, pasting it gets tedious.

See how you go.

http://www.sendspace.com/file/hvqc8x

Share this post


Link to post
Share on other sites

Allo F2k Sel,

Did a really quick run-through after work and I found out if you attach the fuel can and then drop it in range to refuel it starts creating multiple instances of the "Refuel Truck" action if the player hadn't already refueled. I noticed in case 4 there was another instance of refuel truck being created so I removed it (not sure if it was there for testing reasons?) but it seemed to have fixed it. I also fixed the if statements. I forgot proof read over it and left out an = (>=5)sign on feels somewhat full.


_fuelCount = _fuel;
       if (_fuel >=1) then {_fuelCount=10; _fuel=1};
       if (_fuel > 0 and _fuel < 1) then {_fuelCount=_fuel*10};
       if (_fuel == 10) then { titleText ["This feels full","PLAIN",0.3]};
       if (_fuelCount >=5 and _fuelCount < 10) then {titleText ["This  feels somewhat full","PLAIN",0.3]};
       if (_fuelCount >=3 and _fuelCount < 5 ) then {titleText ["This feels half way full","PLAIN",0.3]};
       if (_fuelCount >=1 and _fuelCount < 3 ) then {titleText ["This feels close to empty","PLAIN",0.3]};
       if (_fuel == 0) then {titleText ["This feels empty","PLAIN"]};

I also refined some of the timing and added a few sounds. I'm really enjoying how this script is turning out. I looked through the Arma2 scripting references and jotted down a few more ideas.

Share this post


Link to post
Share on other sites

Cheers Allanp it's hard to test every aspect every time you make a change. I'll take another look, the script is poorly written to be honest that's why we keep getting multiple actions.

I'm trying to come up with a solution for scase and truck_start, I'd rather not use specific names for objects but that will take a while as it needs a complete re-write.

Currently I've re-written carry.sqf where as long as an object type is in the list you can carry it in either hand or on hip.

I'm just stuck on the in out car trigger. It keeps kicking me when I've dropped items.

A few ideas for the current script would be to add damage/hit eventhandler to the can. One shot it starts to leak, two or more it explodes. I have a script for the second it just needs the leak adding to it.

I also thought about a syphon fuel option so you could get it from abandon vehicles.

Only had a quick look today, the refuel action number was incorrect it was act5 it should be act3

Edited by F2k Sel

Share this post


Link to post
Share on other sites

Cheers on the Honesty, I know it is poorly written, I only have a limited knowledge in programming. I know a bit of C# (I had fun making silly text based adventure games hah) and I started looking up on Java. I also found a few articles on cleaning up my code so fingers crossed it soaks in my Brain.

I had that thought run by about not giving specific names to objects so the script can be more general.

Some thoughts I had were:

Being able to fuel a specific amount into the vehicle (1/4 , 1/2 , 3/4 or until vehicle is full (or can is empty)) (I also like your siphon fuel idea, this could go hand in hand with that)

I also like the damage/hit eventhandles. Perhaps if the fuel is empty no explosion happens, but can leak if filled ( a way to repair?)

I took a look at your mission and saw that you had planned a way for the can to be refilled. I think I'll poke at that for a while and see what I can come up with.

Share this post


Link to post
Share on other sites

Well for limiting the amount of fuel you could do a distance check, If you move away to far refuelling stops. It should have that already and the same when filling. Repair would be possible you could drop the can and if it's damaged perform the healing action of the medic to repair it. Then just end the leak script.

I did fuel leak for a jeep.

http://www.sendspace.com/file/801ofn

I'm really stuck on my other idea, I just can't stop a script running every time I fire a new one so I end up with multiple events.

Any way here's my burning barrel script if you want to take a look, it may give you some ideas. It will need scaling down for a fuel can and sound needs to be set up for multiplayer.

http://www.sendspace.com/file/p3lcr7

If you can rip anything from them do so.

Share this post


Link to post
Share on other sites

Added some animations in. Not really a big update but took some browsing around to figure out how to cut an animation short. I always get a laugh when the player unfastens it.

Edit: Just saw your post the code below may be old.

Edit2: I definitely did gather a few ideas, I'll see what I can conjure up.

Attach

//Script created with major help from  F2k Sel
//act3 = truck_start addaction ["Refuel truck","fill.sqf","",1,false,true,"","scase distance truck_start <= 5  and player distance truck_start <= 5 and take==0"]; 
//act2 = truck_start addaction ["Attach Options","attachtruck.sqf",[1],1,false,true,"","player distance truck_start < 4 and player distance scase < 4  and take==0"]; 
// (These inits I placed on the Jerry Can instead of the Truck, not sure if it changes the effectiveness of the script, check AttachOption.sqf for full attachment on Jerry Can)
// take = state of object:0 on ground : 1 carried by player : 2 dropped close to vehicle: 3 refueling : 4 attacehed to truck : 5 dropped close to fuel suppliy.

player removeAction act1;
//truck_start removeAction act2;// remove initial action on truck Attach.
//truck_start removeAction act5;// remove initial action on truck Refuel.
_man = player;

//Fasten jerry can to back of truck 
switch (take) do
{
  case  2 :
   {
     detach scase;
     scase say ["TapeCan",5];
      titleCut ["Fastening Jerry Can to Truck","PLAIN",0.5]; 
        player removeAction act2;
         scase removeaction act1;           
         truck_start removeaction act3;
         player playmove "ActsPercSnonWnonDnon_assembling";
          sleep 10;
          player playMoveNow "AmovPercMstpSlowWrflDnon";
           scase attachTo [truck_start,[-0.9,-3.1875,-0.5]]; // attach to vehicle
            titleText ["Jerry Can is secured","PLAIN"];          
             act2 = scase addaction ["Remove from Truck","scripts\take_fill_attach\attachtruck.sqf","",1,false,true,"","player distance scase < 4"];//change action for next case 
              take=4;
   };  

 //Attach Jerry Can to hip after removing jerry can from back of truck     

  case 4:
   {
    detach scase;

      titleText ["Unfastening Fuel Can","PLAIN"];
       player switchmove "c7a_bravoTOerc_idle1";
         scase removeAction act2;
          sleep 5;
          player switchmove ",";
           scase setvelocity[0,0,-.3];
           // scase attachto [_man, [-0.23,0,-0.15],"Pelvis"]; // attach to player
             //  scase setdir 75;    
              act2 = _man addaction ["Attach to back of Truck","scripts\take_fill_attach\attachtruck.sqf","",1,false,true,"","player distance truck_start < 5 and scase distance truck_start < 5 and take==2"];
              act1 = scase addaction ["Take Jerry Can","scripts\take_fill_attach\carry.sqf","",1,false,true,""];
                take=2; 
   }; 
};  

Carry

//////////////////////////////////////////////////////////////////
// Function file for Armed Assault
// Created by: What's his name.
//////////////////////////////////////////////////////////////////
//Script pulled from  F2k Sel
//init: take=0;  act1 = this addaction ["Take Fuel Can","carry.sqf",[0],1,false,true,"","player distance scase < 2"]  
//Jerry Can starts at case 0 so first the player can pick it up
// take = state of object:0 on ground : 1 carried by player : 2 dropped close to vehicle: 3 refueling : 4 attacehed to truck 

private ["_In_out","_man"];

////////////// checks for player in or out of car  ////////////////
_in_car = {
_In_out = createTrigger["emptyDetector",[0,0,0]];
_In_out setTriggerArea [0,0,0,false]; 
_In_out setTriggerActivation ["any","present",True]; 
//_In_out setTriggerStatements["(vehicle player) != player and take == 1",";scase hideobject true;","scase hideobject false;"];// hides object
_In_out setTriggerStatements["(vehicle player) != player and take == 1","player action ['getout',nearestObject [player,'car']]; Hint 'Get out you idiot!';",""];// kicks you out if carrying
_return
};


////////// checks if player is dead ///////////////////
_evh_Killed = {
   _man removeeventHandler ["killed",0];
   _man addEventHandler ["killed", {
   detach scase;
   scase removeAction act1;
   act1 = scase addaction ["Take Jerry Can","scripts\take_fill_attach\carry.sqf","",1,false,true,""];
    take=0;at=1;(_this select 0) removeeventHandler ["killed",0];  } ];
     _return
     };

switch (true) do
{
   //pick up jerry can
   case (take == 0 or take == 2) :
   {
    _scase = _this select 0;
     _man = _this select 1;
     _fuel = scase getvariable "fuel";
     _fuelCount = _fuel;
       if (_fuel >=1) then {_fuelCount=10; _fuel=1};
       if (_fuel > 0 and _fuel < 1) then {_fuelCount=_fuel*10};
       if (_fuel == 10) then { titleText ["This feels full","PLAIN",0.3]};
       if (_fuelCount >=5 and _fuelCount < 10) then {titleText ["This  feels somewhat full","PLAIN",0.3]};
       if (_fuelCount >=3 and _fuelCount < 5 ) then {titleText ["This feels half way full","PLAIN",0.3]};
       if (_fuelCount >=1 and _fuelCount < 3 ) then {titleText ["This feels close to empty","PLAIN",0.3]};
       if (_fuel == 0) then {titleText ["This feels empty","PLAIN"]};
       _man playmove "AinvPknlMstpSnonWnonDnon_3";
       sleep 2;
      _scase attachto [_man, [-0.23,0,-0.15],"Pelvis"];
      _scase setdir 75;
      _scase removeAction act1;
      _man removeAction act2;
      truck_start removeAction act3;
      act1 = _man addaction ["Drop Jerry Can","scripts\take_fill_attach\carry.sqf","",1,false,true,""];
      take=1;scase = _scase;_man call _in_car; _man call _evh_Killed;
      hintSilent format ["Jerry Can Has %1  Liters of Fuel",_fuelCount];
      }; 

// drop jerry can
   case (take == 1) :
   {

       _man = _this select 0;
       detach scase;
       scase setvelocity[0,0,-.3];
       _man removeAction act1;
       act1 = scase addaction ["Take Jerry Can","scripts\take_fill_attach\carry.sqf","",1,false,true,""];
       _close_veh = nearestObjects [_man,["car"],5];
       take=0;deletevehicle _In_out;
       if (_close_veh select 0 != truck_start) then {take=0} else {
       take = 2;     
       act3=truck_start addaction ["Refuel truck","scripts\take_fill_attach\fill.sqf","",1,false,true,"","(vehicle player) == player and scase distance truck_start <= 5   and player distance truck_start <= 5 and take==2"];
       act2 = _man addaction ["Attach to back of Truck","scripts\take_fill_attach\attachtruck.sqf","",1,false,true,"","player distance truck_start < 5 and scase distance truck_start < 5 and take==2"];    

       };

        _man removeeventHandler ["killed",0];

   };

  };  

Edited by Allanp

Share this post


Link to post
Share on other sites

so i did the names, then the init scripts.then i tried to add both the PHP codes to the carry.sqf file.

it still desnt work for me, i walk up to the jerry can and i cant pick it up?? it comes up with the option "take jerry can" but when i select the option it doesnt pick it up??any help would be nice

Edited by killerzboy234

Share this post


Link to post
Share on other sites

Sorry to revive an old post

I have been looking at this post for hours trying to get this to work on my mission and every time I am getting an error on line 52 of the carry.sqf. Any help would be appreciated. 

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×