Claim Vehicle Script, Problem with Trigger

kikyou2

Valued Member!
Hi there,

I'm currently facing problems with a trigger.

I want that everytime any vehicle enters a special area a Script is executed and the vehicle is passed to the script.

At the moment I'm using this trigger

Code:
class Item7
        {
            position[]={11460.791,317.30573,11351.464};
            angle=310;
            rectangular=1;
            activationBy="ANY";
            repeating=1;
            interruptable=1;
            age="UNKNOWN";
            text="Vehicle1";
            name="Vehicle1";
            expCond="{_x iskindof 'AllVehicles'} count thisList > 0";
            expActiv="{[Vehicle1,_x] execVM ""vehicle.sqf""} forEach thislist";
            class Effects
            {
            };
        };

The Script looks like the following

Code:
private ["_Basis","_vehicle","_ownerid","_driver","_ownerID","_playeruid","_claimer"];
 
_Basis = _this select 0;
_vehicle = _this select 1;
_ownerid = _vehicle getVariable ["characterID","0"];
 
if (_vehicle iskindof "Car" or _vehicle iskindof "Motorcycle" or _vehicle iskindof "Helicopter" or _vehicle iskindof "Plane")
then {
while {true} do {
    waitUntil {vehicle _vehicle in list _Basis};
       
        if (_ownerID == "0") then {
            _claimer = _vehicle getVariable ["Claimed","0"];
                if (_claimer == "0") then {
                    _driver = driver _vehicle;
                        if (!(isnull _driver)) then {
                            _playeruid = getPlayerUID _driver;
                            _vehicle setVariable ["Claimed",_playeruid,true];
                            _claimer = _vehicle getVariable ["Claimed","0"];
                        };
                };   
        };
               
    waitUntil {! (vehicle _vehicle in list _Basis)};
       
        if (_ownerID == "0") then {
        _vehicle setVariable ["Claimed",nil];
        if (locked _vehicle) then {
            dayzLockVehicle = [_vehicle,false];
                    if (local _vehicle) then {
                        dayzLockVehicle spawn local_lockUnlock
                    } else {
                    publicVariable "dayzLockVehicle";
                };
        };
    };
       
};
};

So what the script and the trigger should do is the following:

If a vehicle enters the trigger the trigger should fire and pass the vehicle and the triggername to the script vehicles.sqf.
The script should then select the trigger and the vehicle from the passed array.

Then it reads the ownerID via the getvariable command cause it should only do the things if the vehicle has no ownerID (in this case the default value of "0").

Then it checks whether _vehicle is a real vehicle cause AllVehicles is passing much other things too. If its a vehicle the script should recheck with the first wait until if the vehicle is in the trigger.

If it is and the ownerID is 0 then it should check whether there is already a variable claimed set at the vehicle, if not it should get the driver of the vehicle (if there is one) and get the playeruid of the driver and then add the claimed variable via setvariable (sets the playerUID of the driver).

The only problem I'm facing to is that sometimes the trigger fires for the vehicle and passes it to the script and sometimes not. And I can't figure out WHY, this is really frustrating :(

Hope someone has the right direction to show me where the error is..

Thanks
 
Here are some examples what kind things fires the trigger and which things are passed to the script. The only thing what is not in there is a vehicle >.<

Code:
"KIKYOU DEBUG: Value of _vehicle Select: B 1-1-B:1 (kikyou)"
"KIKYOU DEBUG: Value of _vehicle Select: 38366b00# 1055208: cluttercutter_small_ep1.p3d REMOTE"
"KIKYOU DEBUG: Value of _vehicle Select: 38364f00# 1055209: cluttercutter_small_ep1.p3d REMOTE"
"KIKYOU DEBUG: Value of _vehicle Select: 2888b900# 1055215: barrel_water.p3d REMOTE"
"KIKYOU DEBUG: Value of _vehicle Select: 42102b00# 1055223: smalltable.p3d REMOTE"
"KIKYOU DEBUG: Value of _vehicle Select: C 1-1-A:11 REMOTE"
"KIKYOU DEBUG: Value of _vehicle Select: 38365d00# 1055206: cluttercutter_ep1.p3d REMOTE"
"KIKYOU DEBUG: Value of _vehicle Select: 38364100# 1055207: cluttercutter_ep1.p3d REMOTE"
"KIKYOU DEBUG: Value of _vehicle Select: C 1-1-A:1 REMOTE"
"KIKYOU DEBUG: Value of _vehicle Select: C 1-1-A:10 REMOTE"
"KIKYOU DEBUG: Value of _vehicle Select: C 1-1-A:12 REMOTE"
"KIKYOU DEBUG: Value of _vehicle Select: C 1-1-A:13 REMOTE"
"KIKYOU DEBUG: Value of _vehicle Select: C 1-1-A:14 REMOTE"
 
It seems that the trigger only fires on things which are already in the triggerzone when the server starts.... very strange
 
Not nearly skilled enough to be messing around with this stuff, but wouldn't you need something along the lines of
Code:
setTriggerArea [5,5,0,false];
? Sorry if this is entirely incorrect xD
 
Thanks for trying to help me out :)

This should be only necessary if you define the trigger via the script. But I defined it via the mission.sqm so I should'nt need to define the area script side.

I think the problem is here

expCond="{_x iskindof 'AllVehicles'} count thisList > 0";

But I didn't found any other Condition yet to get the vehicles triggered. The only other thing is

(vehicle player) in thislist

But the problem with the thing above is that it only fires on targets which have a driver and I use the trigger for some other things which I didn't mentioned in the script above too. Also it has nearly the same problems that it isn't reliable to fire.

The only other method which I could think of is to use nearestObjects. But it would cost much more performance cause for every single vehicle the script would have to calculate the distance to a point every x seconds. Additionally I use a rectangular trigger which wouldn't be possible with nearestObjects cause it would only use a distance (so it would be a circle).
 
i'm not sure if i understood correctly what you wanna do and i am not that scripting experienced,
but if you want to fire the script only for _vehicle or whatever you could define it as null
and then onAct of the trigger do something like this?
expActiv="nul = [thislist] execVM ""fire.sqf""; ";


or maybe
[_vehicle,nil,rEXECVM,yourcript.sqf] call RE;

trigger:
"nul = [thislist] execVM ""yourscript.sqf""; ";
 
Try
Code:
expActiv="{[this,_x] execVM ""vehicle.sqf""} forEach thislist";
or
Code:
expActiv="{[Vehicle,_x] execVM ""vehicle.sqf""} forEach thislist";
instead of
Code:
expActiv="{[Vehicle1,_x] execVM ""vehicle.sqf""} forEach thislist";
Worked for something I tried the other day :)
 
i'm not sure if i understood correctly what you wanna do and i am not that scripting experienced,
but if you want to fire the script only for _vehicle or whatever you could define it as null
and then onAct of the trigger do something like this?
expActiv="nul = [thislist] execVM ""fire.sqf""; ";


or maybe
[_vehicle,nil,rEXECVM,yourcript.sqf] call RE;

trigger:
"nul = [thislist] execVM ""yourscript.sqf""; ";

As said I want to use _vehicle setvariable at every vehicle which enters the trigger or is inside the trigger. If it leaves it should be removed.

The reason why I need this: it's a safezone addition. The claimed variable will be set on every vehicle which has no owner (Epoch) if it enters the safezone. The variable which will be set is the PlayerUID of the driver.

I modified the trader scripts so you can only sell vehicles if you have the key or if its claimed that only the claimer can sell the vehicle.

The variable will also add 2 new buttons (inside the safezone only) that the claimer is able to lock the vehicle inside the safezone (so nobody can steal it) and is able to unclaim the vehicle so that everybody else could sell it.

This is a part of my safezone improvements I'm currently developing and everything works fine except the trigger for the vehicles.

but if you want to fire the script only for _vehicle or whatever you could define it as null
and then onAct of the trigger do something like this?

How do you mean this? The variable _vehicle doesn't exist for the trigger, I want that if there is a vehicle inside the trigger or enters it the trigger fires and execute my script and pass the vehicle to it. When I select it from the passed array I save it in the _vehicle variable at the script and then work with the _vehicle variable.

Maybe try to use the trigger via a script ?

Sorry but there is no difference :/

Try
Code:
expActiv="{[this,_x] execVM ""vehicle.sqf""} forEach thislist";
or
Code:
expActiv="{[Vehicle,_x] execVM ""vehicle.sqf""} forEach thislist";
instead of
Code:
expActiv="{[Vehicle1,_x] execVM ""vehicle.sqf""} forEach thislist";
Worked for something I tried the other day :)

Vehicle1 is inteded to be there cause its the triggername. If I change it to Vehicle or this the waituntil part will not work cause the _Basis select wouldn't be the triggername.

Thanks for your helping attempts :)
 
Back
Top