Jump to content
  • 0

Location Based script


chaingun427

Question

I'm wanting to add a location to a key changer script to make it where the script will only execute within say 15 meters of an object, in this case the "worker4" ai (like a trader)
I'm thinking that it should go after the check for the player

if ((vehicle player) == player) then {

and be something along the lines of

If (player is within 15m of "worker4") then {

But I honestly don't know how to write it. Either that or I'd like to do the same check before the loop runs, and then turn off the loop after you exit the radius since right now it's constantly running the loop. I'm attaching a copy of the key changer script as well hopefully I can get this to work with some help

VehicleKeyChanger.zip

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

Why would you like that function?

Accessing the trader would already be limited by the settings made, but you could do it like this:

 

 

_ct = cursorTarget;

 

if (_ct distance player > 12)

ct is the object in your mouse cursor and the "12" is the distance to it.

 

So for example:

 

 

_ct = cursorTarget;

 

if (_ct distance player > 12) exitWith {cutText [format["%1 is to far away.",typeOf _ct], "PLAIN"];};

 

That would then exit out of the script if he is further away then 12m.  And give him the message:

 

"(Object he is looking at) is to far away."

 

 

Hope I got that right and it helped!

 

Best regards,

Blite

Link to comment
Share on other sites

  • 0

Basically I want to edit the key changer script to only work in the same areas I'm setting up as a service point. I looked at possibly integrating it into Axecop's service point but it's not as simple as just calling it from his script. What you wrote above probably won't work because the key changer requires the player to be looking at the vehicle they wish to rekey. Is it possible to do

if (player distance <15 of location ["1x,1y,1z","2x,2y,2z"])  then {

and just have an array of coordinates where the script is allowed to continue through it's loop?

Link to comment
Share on other sites

  • 0

Sorry i misunderstood your idea...

In that case:

 

 

_nearSP = count nearestObjects [_playerPos, ["your service point object"], your distance away allowed] > 0;
 
if !(_nearSP) exitWith {
cutText [format["You need to be near a service point to use this function."], "PLAIN DOWN"];

 

};

 

Link to comment
Share on other sites

  • 0

So to use it in the following loop could i do

if ([_playerPos, ["worker4"], 15] > 0) then {

before

if ((vehicle player) == player) then {

and adding another

} else {

        [] call ON_fnc_vkcReset;

at the end of the loop ?

/***********************************/     
/* Vehicle Key Changer v1.4        */
/* Written by OtterNas3            */
/* January, 11, 2014               */
/* Last update: 06/15/2014         */
/***********************************/


/////////////////////////////////////////////////
/////////////////////////////////////////////////
// Edit these settings to fit your needs/likes //
/////////////////////////////////////////////////
/////////////////////////////////////////////////
/// Claim Vehicles that does not yet need Key ///
///////// 0 = Not allowed | 1 = Allowed /////////
vkc_claiming = 1;
/////////////////////////////////////////////////
//////// Claim Vehicles costs this Item /////////
/// Any Item can be used here, some examples: ///
//// ItemTinBar, ItemSilverBar, ItemGoldBar, ////
////// ItemSilverBar10oz, ItemGoldBar10oz, //////
///// ItemBriefcase20oz, ItemBriefcase100oz /////
//////// set to "0" to disable the costs ////////
vkc_claimingPrice = "ItemGoldBar10oz";
/////////////////////////////////////////////////
////////// Change Key costs this Item// /////////
////////////// see above examples ///////////////
//////// set to "0" to disable the costs ////////
vkc_Price = "ItemGoldBar10oz";
/////////////////////////////////////////////////
/////// Need KeyKit to use this function ////////
////////// 0 = Not needed | 1 = Needed //////////
vkc_needKeykit = 1;
/////////////////////////////////////////////////
/////////////////////////////////////////////////
/////////////// DONT EDIT BELOW ! ///////////////
/////////////////////////////////////////////////

ON_fnc_vkcReset = {
    player removeAction s_player_claimVehicle;
    s_player_claimVehicle = -1;
    player removeAction s_player_copyToKey;
    s_player_copyToKey = -1;
    lastKeyChangeCursorTarget = [objNull,objNull];
    vkc_cTarget = objNull;
};

/* Wait for player full ingame so we can access the action-menu */
waitUntil {!isNil "dayz_animalCheck"};

/* Initial Reset */
[] call ON_fnc_vkcReset;

/* Start the loop check */
while{true} do {
    sleep 3;

    if ((vehicle player) == player) then {
    
        if (speed player <= 1) then {

            if (!isNull cursorTarget) then {
                _cursorTarget = cursorTarget;
                
                if ((_cursorTarget isKindOf "Motorcycle" || _cursorTarget isKindOf "Car" || _cursorTarget isKindOf "Air" || _cursorTarget isKindOf "Ship")) then {

                    if ((_cursorTarget distance player) <= 10) then {

                        if (!isEngineOn _cursorTarget) then {

                            vkc_carKey = _cursorTarget getVariable ["CharacterID","0"];

                            if (vkc_claiming == 1) then {
                            
                                if (vkc_carKey == "0") then {

                                    if ((lastKeyChangeCursorTarget select 0) != _cursorTarget) then {
                                        player removeAction s_player_claimVehicle;
                                        s_player_claimVehicle = -1;
                                
                                        lastKeyChangeCursorTarget set [0,_cursorTarget];
                                        vkc_cTarget = lastKeyChangeCursorTarget select 0;
                                    };

                                    if (vkc_cTarget getVariable ["VKC_claming_disabled", 0] == 0) then {
                                        vkc_magazinesPlayer = magazines player;
                                        vkc_itemsPlayer = items player;
                                    
                                        if (("ItemKeyKit" in vkc_itemsPlayer || vkc_needKeykit == 0) && ((vkc_claimingPrice == "0" || vkc_claimingPrice in vkc_magazinesPlayer))) then {
                                            vkc_objectID = vkc_cTarget getVariable ["ObjectID","0"];
                                            vkc_objectUID = vkc_cTarget getVariable ["ObjectUID","0"];

                                            if (!(vkc_objectID == "0" && vkc_objectUID == "0")) then {
                                                vkc_key_colors = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"];
                                                vkc_temp_keys = [];
                                                vkc_temp_keysDisplayName = [];
                                                vkc_temp_keysDisplayNameParse = [];
                                            
                                                {
    
                                                    if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _x)) in vkc_key_colors) then {
                                                        vkc_ownerKeyId = getNumber(configFile >> "CfgWeapons" >> _x >> "keyid");
                                                        vkc_keyName = getText(configFile >> "CfgWeapons" >> _x >> "displayName");
                                                        vkc_temp_keysDisplayName set [count vkc_temp_keysDisplayName,vkc_keyName];
                                                        vkc_temp_keys set [count vkc_temp_keys,str(vkc_ownerKeyId)];
                                                    };
                                                } forEach vkc_itemsPlayer;

                                                if ((count vkc_temp_keys) > 0) then {
    
                                                    if (s_player_claimVehicle < 0) then {
                                                        s_player_claimVehicle = player addAction [("<t color='#00FFFF'>" + ("Claim Vehicle") + "</t>"),"custom\VehicleKeyChanger\VehicleKeyChanger.sqf",[vkc_cTarget,vkc_temp_keys,"0",vkc_temp_keysDisplayName,"0","0","0", vkc_claimingPrice],-1002,false,false,"",""];
                                                    };
    
                                                } else {

                                                    player removeAction s_player_claimVehicle;
                                                    s_player_claimVehicle = -1;
                                                };

                                            } else {

                                                player removeAction s_player_claimVehicle;
                                                s_player_claimVehicle = -1;
                                            };

                                        } else {

                                            player removeAction s_player_claimVehicle;
                                            s_player_claimVehicle = -1;
                                        };

                                    } else {

                                        player removeAction s_player_claimVehicle;
                                        s_player_claimVehicle = -1;
                                    };

                                } else {

                                    player removeAction s_player_claimVehicle;
                                    s_player_claimVehicle = -1;
                                };

                            } else {

                                player removeAction s_player_claimVehicle;
                                s_player_claimVehicle = -1;
                            };

                            if (vkc_carKey != "0") then {

                                if ((lastKeyChangeCursorTarget select 1) != _cursorTarget) then {
                                    player removeAction s_player_copyToKey;
                                    s_player_copyToKey = -1;

                                    lastKeyChangeCursorTarget set [1,_cursorTarget];
                                    vkc_cTarget = lastKeyChangeCursorTarget select 1;
                                };

                                if (vkc_cTarget getVariable ["VKC_disabled",0] == 0) then {

                                    vkc_magazinesPlayer = magazines player;
                                    vkc_itemsPlayer = items player;

                                    if (("ItemKeyKit" in vkc_itemsPlayer || vkc_needKeykit == 0) && (vkc_Price == "0" || vkc_Price in vkc_magazinesPlayer)) then {

                                        vkc_objectID = vkc_cTarget getVariable ["ObjectID","0"];
                                        vkc_objectUID = vkc_cTarget getVariable ["ObjectUID","0"];

                                        if (!(vkc_objectID == "0" && vkc_objectUID == "0")) then {
                                
                                            vkc_key_colors = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"];
                                            vkc_temp_keys = [];
                                            vkc_temp_keysDisplayName = [];
                                            vkc_temp_keysDisplayNameParse = [];
                                            vkc_temp_keysParse = [];

                                            {

                                                if (configName(inheritsFrom(configFile >> "CfgWeapons" >> _x)) in vkc_key_colors) then {
                                                    vkc_ownerKeyId = getNumber(configFile >> "CfgWeapons" >> _x >> "keyid");
                                                    vkc_keyName = getText(configFile >> "CfgWeapons" >> _x >> "displayName");
                                                    vkc_temp_keysDisplayName set [count vkc_temp_keysDisplayName,vkc_keyName];
                                                    vkc_temp_keysDisplayNameParse set [vkc_ownerKeyId,vkc_keyName];
                                                    vkc_temp_keys set [count vkc_temp_keys,str(vkc_ownerKeyId)];
                                                    vkc_temp_keysParse set [vkc_ownerKeyId, _x];
                                                };
                                            } forEach vkc_itemsPlayer;

                                            vkc_hasKey = vkc_carKey in vkc_temp_keys;

                                            if (vkc_hasKey && (count vkc_temp_keys) > 1) then {
                                                vkc_carKeyName = (vkc_temp_keysDisplayNameParse select (parseNumber vkc_carKey));
                                                vkc_targetVehicleKey = (vkc_temp_keysParse select (parseNumber vkc_carKey));
                                                vkc_temp_keys = vkc_temp_keys - [vkc_carKey];
                                                vkc_temp_keysDisplayName = vkc_temp_keysDisplayName - [vkc_carKeyName];

                                                if (s_player_copyToKey < 0) then {
                                                    s_player_copyToKey = player addAction [("<t color=""#0000FF"">" + ("Change Vehicle Key") + "</t>"),"custom\VehicleKeyChanger\VehicleKeyChanger.sqf",[vkc_cTarget, vkc_temp_keys, vkc_carKey, vkc_temp_keysDisplayName, vkc_carKeyName, vkc_targetVehicleKey, vkc_Price, "0"],-1002,false,false,"",""];
                                                };

                                            } else {
                                        
                                                player removeAction s_player_copyToKey;
                                                s_player_copyToKey = -1;
                                            };

                                        } else {
                                        
                                            player removeAction s_player_copyToKey;
                                            s_player_copyToKey = -1;
                                        };

                                    } else {
                                    
                                        player removeAction s_player_copyToKey;
                                        s_player_copyToKey = -1;
                                    };
                            
                                } else {
                                    
                                    player removeAction s_player_copyToKey;
                                    s_player_copyToKey = -1;
                                };

                            } else {
                                    
                                player removeAction s_player_copyToKey;
                                s_player_copyToKey = -1;
                            };

                        } else {
                            
                            [] call ON_fnc_vkcReset;
                        };

                    } else {

                        [] call ON_fnc_vkcReset;
                    };

                } else {

                    [] call ON_fnc_vkcReset;
                };

            } else {

                [] call ON_fnc_vkcReset;
            };

        } else {

            [] call ON_fnc_vkcReset;
        };

    } else {

        [] call ON_fnc_vkcReset;
    };

};


Link to comment
Share on other sites

  • 0

I haven't looked through the whole script as in what reacts with what and with which exceptions but looking over it briefly I believe you can do:

 

change

 

 

 

    if ((vehicle player) == player) then {

 

to

 

 

 

    if ((vehicle player) == player) && !(_nearSP) then {

 

and add:

 

 

 

_nearSP = count nearestObjects [_playerPos, ["your service point object"], your distance away allowed] > 0;

 

So all in all it would be:

private ["_nearSP","_playerPos"]

 

_playerPos = getPosATL player;

_nearSP = count nearestObjects [_playerPos, ["your service point object"], your distance away allowed] > 0;

 

 

 if ((vehicle player) == player) && (_nearSP) then {

 

That would make him be able to what ever you put in "then" if he is near the service point and inside the vehicle

Link to comment
Share on other sites

  • 0

Why don't you just make a marker for that location in mission.sqf like so....

 

class Item28
        {
            position[]={22599.2,0.001,19685.8};     //{X,Z,Y}
            name="SectorB";
            type="Empty";
        };

 

make sure to increment the number Item# by one and the amount of markers by 1 at the top of the markers array.

 

then make a sensor where a variable is set to true when the player is in that area... again increment item and amount of items by 1

 

class Item4
        {
            position[]={22599.2,0.001,19685.8};
            a=600;
            b=600;
            activationBy="WEST";
            repeating=1;
            interruptable=1;
            age="UNKNOWN";
            name="SectorB";
            expCond="(player distance SectorB) < 800;";
            expActiv="sectB=true; canbuild = false; clearzeds = [] execVM ""custom\clearzeds.sqf"";";
            expDesactiv="canbuild=true; sectB=false; terminate clearzeds;";
            class Effects
            {
            };
        };

 

In my example here when you are within 800m of sectorB a script is called inside "expActiv" which clears zeds clearzeds = [] execVM ""custom\clearzeds.sqf"".  When you leave sectorB inside expDesactiv it terminates clearzeds.

 

You could make a script that runs that lets you do what you want as I have done using sensors.  Using never ending loops is never good practice and drops the FPS of your clients.

Link to comment
Share on other sites

  • 0

Well, great way to do so also, but I believe adding just the location and object variables is much more simple..But I guess that is up to him :)

 

And without being a douche or dick I just want to point out a little error:

 

Mission.sqm not sqf  :P

 

Have a good day,

Blite

Link to comment
Share on other sites

  • 0

 

private ["_nearSP","_playerPos","_ServiceObj","_distAllow"]

 

_ServiceObj = "building";

_distAllow = 10;

_playerPos = getPosATL player;

 

_nearSP = count nearestObjects [_playerPos, _ServiceObj, _distAllow] > 0;

 

 

 if ((vehicle player) == player) && (_nearSP) then {

 

For a better overview if that is what you were interested in :)

Link to comment
Share on other sites

  • 0

I've tried both ways and no joy, with the code removed it works everywhere, but with it in place as shown here, nothing happens. (this is an updated version of the script as well)

/***********************************/ 	/* Vehicle Key Changer v1.5.3      *//* Written by OtterNas3            *//* January, 11, 2014               *//* Last update: 23/10/2014         *//* Advanced by hellraver           *//***********************************/private ["_nearSP","_playerPos","_ServiceObj","_distAllow"]; //////////////////////////////////////////////////////////////////////////////////////////////////// Edit these settings to fit your needs/likes ///////////////////////////////////////////////////////////////////////////////////////////////////////// Claim Vehicles that do not have a Key ////////////// 0 = Not allowed | 1 = Allowed /////////vkc_claimKey = 1;//////////////////////////////////////////////////////// Change Key to create a Masterkey ///////////////// 0 = Not allowed | 1 = Allowed /////////vkc_changeKey = 1;///////////////////////////////////////////////////////// Set to "0" to disable the costs ////////vkc_claimKeyPrice = "ItemGoldBar10oz";///////////////////////////////////////////////////////// Set to "0" to disable the costs ////////vkc_changeKeyPrice = "ItemGoldBar10oz";/////////////////////////////////////////////////////// Need KeyKit to use Claim Vehicle Key /////////////// 0 = Not needed | 1 = Needed //////////vkc_claimNeedKeykit = 1;////////////////////////////////////////////////////// Need KeyKit to use Change Vehicle Key /////////////// 0 = Not needed | 1 = Needed //////////vkc_changeNeedKeykit = 1;/////////////////////////////////////////////////// Change Key & Claim Vehicles costs this Item ///// Any Item can be used here, some examples: /////// ItemTinBar, ItemSilverBar, ItemGoldBar, ////////// ItemSilverBar10oz, ItemGoldBar10oz, /////////// ItemBriefcase20oz, ItemBriefcase100oz ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// DONT EDIT BELOW ! /////////////////////////////////////////////////////////////////* Wait for player full ingame so we can access the action-menu */waitUntil {!isNil "dayz_animalCheck"};// Increase distance only if AIR || SHIP_ServiceObj = "MAP_Heli_H_cross";_distAllow = 10;_playerPos = getPosATL player;_nearSP = count nearestObjects [_playerPos, _ServiceObj, _distAllow] &gt; 0;_allowedDistance = 4;_isAir = cursorTarget isKindOf "Air";_isShip = cursorTarget isKindOf "Ship";if(_isAir || _isShip) then {	_allowedDistance = 8;};/* Start the loop check */while{true} do {if (_nearSP) then {	if (!isNull cursorTarget && (cursorTarget isKindOf "AllVehicles") && (player distance cursorTarget &lt; _allowedDistance) && (!isEngineOn cursorTarget)) then {		vkc_cursorTarget = cursorTarget;		vkc_ownerID = vkc_cursorTarget getVariable ["CharacterID","0"];		if (vkc_claimKey == 1 && vkc_ownerID == "0" && vkc_cursorTarget getVariable ["VKC_claiming_disabled", 0] == 0) then {			vkc_magazinesPlayer = magazines player;			vkc_itemsPlayer = items player;					if (("ItemKeyKit" in vkc_itemsPlayer || vkc_claimNeedKeykit == 0) && (vkc_claimKeyPrice == "0" || vkc_claimKeyPrice in vkc_magazinesPlayer)) then {				vkc_objectID = vkc_cursorTarget getVariable ["ObjectID","0"];				vkc_objectUID = vkc_cursorTarget getVariable ["ObjectUID","0"];				if (!(vkc_objectID == "0" && vkc_objectUID == "0")) then {					if (s_player_claimKey &lt; 0) then {						s_player_claimKey = player addAction [("" + ("Claim Vehicle Key") + ""),"custom\VehicleKeyChanger\VehicleKeyChanger.sqf",[vkc_cursorTarget, vkc_temp_keys, vkc_ownerID, vkc_temp_keysDisplayName, "0", "0", "0", vkc_claimKeyPrice],-1002,false,false,"",""];					};				} else {					player removeAction s_player_claimKey;					s_player_claimKey = -1;				};			} else {				player removeAction s_player_claimKey;				s_player_claimKey = -1;			};		} else {			player removeAction s_player_claimKey;			s_player_claimKey = -1;		};		if (vkc_changeKey == 1 && vkc_ownerID != "0" && vkc_cursorTarget getVariable ["VKC_disabled",0] == 0) then {			vkc_magazinesPlayer = magazines player;			vkc_itemsPlayer = items player;			if (("ItemKeyKit" in vkc_itemsPlayer || vkc_changeNeedKeykit == 0) && (vkc_changeKeyPrice == "0" || vkc_changeKeyPrice in vkc_magazinesPlayer)) then {				vkc_objectID = vkc_cursorTarget getVariable ["ObjectID","0"];				vkc_objectUID = vkc_cursorTarget getVariable ["ObjectUID","0"];				if (!(vkc_objectID == "0" && vkc_objectUID == "0")) then {							vkc_key_colors = ["ItemKeyYellow","ItemKeyBlue","ItemKeyRed","ItemKeyGreen","ItemKeyBlack"];					vkc_temp_keys = [];					vkc_temp_keysDisplayName = [];					vkc_temp_keysDisplayNameParse = [];					vkc_temp_keysParse = [];					{						if (configName(inheritsFrom(configFile &gt;&gt; "CfgWeapons" &gt;&gt; _x)) in vkc_key_colors) then {							vkc_ownerKeyId = getNumber(configFile &gt;&gt; "CfgWeapons" &gt;&gt; _x &gt;&gt; "keyid");							vkc_keyName = getText(configFile &gt;&gt; "CfgWeapons" &gt;&gt; _x &gt;&gt; "displayName");							vkc_temp_keysDisplayName set [count vkc_temp_keysDisplayName,vkc_keyName];							vkc_temp_keysDisplayNameParse set [vkc_ownerKeyId,vkc_keyName];							vkc_temp_keys set [count vkc_temp_keys,str(vkc_ownerKeyId)];							vkc_temp_keysParse set [vkc_ownerKeyId, _x];						};					} forEach vkc_itemsPlayer;					vkc_hasKey = vkc_ownerID in vkc_temp_keys;					if (vkc_hasKey && (count vkc_temp_keys) &gt; 1) then {						vkc_carKeyName = (vkc_temp_keysDisplayNameParse select (parseNumber vkc_ownerID));						vkc_targetVehicleKey = (vkc_temp_keysParse select (parseNumber vkc_ownerID));						vkc_temp_keys = vkc_temp_keys - [vkc_ownerID];						vkc_temp_keysDisplayName = vkc_temp_keysDisplayName - [vkc_carKeyName];						if (s_player_changeKey &lt; 0) then {							s_player_changeKey = player addAction [("" + ("Change Vehicle Key") + ""),"custom\VehicleKeyChanger\VehicleKeyChanger.sqf",[vkc_cursorTarget, vkc_temp_keys, vkc_ownerID, vkc_temp_keysDisplayName, vkc_carKeyName, vkc_targetVehicleKey, vkc_changeKeyPrice, "0"],-1002,false,false,"",""];						};					} else {										player removeAction s_player_changeKey;						s_player_changeKey = -1;					};				} else {									player removeAction s_player_changeKey;					s_player_changeKey = -1;				};			} else {							player removeAction s_player_changeKey;				s_player_changeKey = -1;			};		} else {							player removeAction s_player_changeKey;			s_player_changeKey = -1;			};	} else {							player removeAction s_player_changeKey;			s_player_changeKey = -1;		};	} else {		player removeAction s_player_claimKey;		s_player_claimKey = -1;		player removeAction s_player_changeKey;		s_player_changeKey = -1;	};};
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
  • Discord

×
×
  • Create New...