English Solved Help with Script for Dynamic Drug Field

  • Auteur de la discussion Auteur de la discussion AltisLifeDev
  • Date de début Date de début
17/4/23
16
2
1
100
I have a dynamic drug field script but it's not working right and looking for some help.
C++:
#include "\life_server\script_macros.hpp"
/*
    File: fn_dynDrugFields.sqf
    Author: Your Mom /(.)(.)\
*/

diag_log "--------------------------------------";
diag_log "Dyn Drug Fields: Initializing...";
diag_log "--------------------------------------";

private _drugLocations = [
    ["weed", "Weed Field", "ColorRed", "mil_dot"],
    ["heroin", "Heroin Field", "ColorRed", "mil_dot"],
    ["cocaine", "Cocaine Field", "ColorRed", "mil_dot"]
];

private _stayTime = getNumber(missionConfigFile >> "CfgDynMarkers" >> "DynMarkers_Settings" >> "fields_position_time");
if (_stayTime == 0) exitWith {
    diag_log "--------------------------------------";
    diag_log "Error: fields_position_time is set to 0!";
    diag_log "--------------------------------------";
};

private ["_createDrugFieldMarker", "_createDrugFieldAreaMarker"];

_createDrugFieldMarker = {
    private ["_drugType", "_drugName", "_color", "_markerType", "_location", "_markerName", "_drugFieldMarker"];

    _drugType = _this select 0;
    _drugName = _this select 1;
    _color = _this select 2;
    _markerType = _this select 3;

    _locationArray = configFile >> "CfgDynMarkers" >> "DynMarkers_Settings" >> format ["%1_locations", _drugType];
    if (count _locationArray == 0) exitWith {
        diag_log format ["Error: No %1 locations defined!", _drugType];
    };

    _location = selectRandom _locationArray;

    _markerName = format ["%1_1", _drugType];
    deleteMarker _markerName;
    _drugFieldMarker = createMarker [_markerName, _location];
    _drugFieldMarker setMarkerColor _color;
    _drugFieldMarker setMarkerType _markerType;
    _drugFieldMarker setMarkerText _drugName;

    format ["%1_field", _drugType] setMarkerPos _location;

    diag_log format ["Created %1 field marker at %2", _drugType, _location];
};

_createDrugFieldAreaMarker = {
    private ["_drugType", "_areaMarkerName", "_areaMarkerPos", "_drugFieldAreaMarker"];

    _drugType = _this select 0;

    _areaMarkerName = format ["%1_field", _drugType];
    _areaMarkerPos = getMarkerPos _areaMarkerName;
    deleteMarker _areaMarkerName;
    _drugFieldAreaMarker = createMarker [_areaMarkerName, _areaMarkerPos];
    _drugFieldAreaMarker setMarkerColor "ColorWhite";
    _drugFieldAreaMarker setMarkerType "empty";
    _drugFieldAreaMarker setMarkerShape "ELLIPSE";
    _drugFieldAreaMarker setMarkerSize [35, 35];

    diag_log format ["Created %1 field area marker at %2", _drugType, _areaMarkerPos];
};

{
    _drugType = _x select 0;
    [_x] call _createDrugFieldMarker;
    [_x] call _createDrugFieldAreaMarker;
    [0,format ["<t align='center'><t size='2.4'><t color='#FF0000'>Drug Field</t></t><br/> A %1 field has been spoted and marked on your map!",_drugType]] remoteExecCall ["life_fnc_broadcast",west,civilian];
} forEach _drugLocations;


sleep (_stayTime * 60);

[0,format ["<t align='center'><t size='2.4'><t color='#FF0000'>Drug Field</t></t><br/> The Drug Field is moving to a new location. The new location will be marked on map in 10 Min!"]] remoteExecCall ["life_fnc_broadcast",west,civilian];

{
    private _markerName = format ["%1_1", _x select 0];
    private _areaMarkerName = format ["%1_field", _x select 0];
    deleteMarker _markerName;
    deleteMarker _areaMarkerName;

    diag_log format ["Removed %1 field marker and area marker", _x select 0];
} forEach _drugLocations;

diag_log "---------------------------";
diag_log "Dyn Drug Fields: Removed...";
diag_log "---------------------------";

[]spawn TON_fnc_drugFieldsInit;


I get error codes:
C++:
"Error: No [""weed"",""Weed Field"",""ColorRed"",""mil_dot""] locations defined!"
Error in expression <ugName = _this select 1;
_color = _this select 2;
_markerType = _this select 3;
>
  Error position: <select 2;
_markerType = _this select 3;
>
  Error Zero divisor
File life_server\Functions\Systems\fn_dynDrugFields.sqf..., line 31


And :

C++:
"Created [""weed"",""Weed Field"",""ColorRed"",""mil_dot""] field area marker at [0,0,0]"
Error in expression <ed and marked on your map!",_drugType]] remoteExecCall ["life_fnc_broadcast",wes>
  Error position: <remoteExecCall ["life_fnc_broadcast",wes>
  Error Type Side, expected String, Bool, Object, Group
File life_server\Functions\Systems\fn_dynDrugFields.sqf..., line 74
 
Solution
Solved the issus, can close.
C++:
/*
    File: fn_dynDrugFields.sqf
    Author: Your Mom /(.)(.)\
*/

diag_log "--------------------------------------";
diag_log "Drug Fields Init: Initializing...";
diag_log "--------------------------------------";

// Lets Make them waite
sleep(1*60);


diag_log "--------------------------------------";
diag_log "Dyn Drug Fields: Initializing...";
diag_log "--------------------------------------";

private _drugLocations = [
    ["weed", "Weed Field", "ColorRed", "mil_dot"],
    ["heroin", "Heroin Field", "ColorRed", "mil_dot"],
    ["cocaine", "Cocaine Field", "ColorRed", "mil_dot"]
];

private _stayTime = getNumber(missionConfigFile >> "CfgDynMarkers" >> "DynMarkers_Settings" >>...
--- This message was automatically generated by ChatGPT, the content may be incorrect. Please read the message with precautions! ---

It looks like you're encountering two issues with your dynamic drug field script.

The first error, "Error: No [""weed"",""Weed Field"",""ColorRed"",""mil_dot""] locations defined!", suggests that there are no locations defined for the "weed" drug type in the config file. Make sure that you have defined the weed locations in the config file correctly.

The second error, "Created [""weed"",""Weed Field"",""ColorRed"",""mil_dot""] field area marker at [0,0,0]", is related to the remote execution call. The issue seems to be with the parameters passed to the remoteExecCall function. Make sure that the parameters are of the correct type (String, Bool, Object, or Group).

--- To continue the discussion with ChatGPT, click "Reply" at the bottom right of this message. Otherwise, wait for someone to reply. ---
 
--- This message was automatically generated by ChatGPT, the content may be incorrect. Please read the message with precautions! ---

It looks like you're encountering two issues with your dynamic drug field script.

The first error, "Error: No [""weed"",""Weed Field"",""ColorRed"",""mil_dot""] locations defined!", suggests that there are no locations defined for the "weed" drug type in the config file. Make sure that you have defined the weed locations in the config file correctly.

The second error, "Created [""weed"",""Weed Field"",""ColorRed"",""mil_dot""] field area marker at [0,0,0]", is related to the remote execution call. The issue seems to be with the parameters passed to the remoteExecCall function. Make sure that the parameters are of the correct type (String, Bool, Object, or Group).

--- To continue the discussion with ChatGPT, click "Reply" at the bottom right of this message. Otherwise, wait for someone to reply. ---


My config:
C++:
class CfgDynMarkers {
    class DynMarkers_Settings {
        fields_position_time = 10; // Time in minutes between field position changes
        weed_locations[] = {
            {11556.4,7048.07,0},
            {4219.25,20464.5,0},
            {15880.5,18843.8,0}
        };
        heroin_locations[] = {
            {19879,17006.7,0},
            {8331.38,20787.2,0},
            {9659.47,8852.26,9.53674e-007}
        };
        cocaine_locations[] = {
            {13462.2,20630.8,0},
            {5188.2,20872.7,0},
            {25915.7,20678,0}
        };
    };
};
 
Dernière édition:
Okay so I have updated the script and the issue now is the 2nd marker is not being created at the same spot as the first marker
C++:
/*
    File: fn_dynDrugFields.sqf
    Author: Your Mom /(.)(.)\
*/

diag_log "--------------------------------------";
diag_log "Drug Fields Init: Initializing...";
diag_log "--------------------------------------";

// Lets Make them waite
sleep(1*60);


diag_log "--------------------------------------";
diag_log "Dyn Drug Fields: Initializing...";
diag_log "--------------------------------------";

private _drugLocations = [
    ["weed", "Weed Field", "ColorRed", "mil_dot"],
    ["heroin", "Heroin Field", "ColorRed", "mil_dot"],
    ["cocaine", "Cocaine Field", "ColorRed", "mil_dot"]
];

private _stayTime = getNumber(missionConfigFile >> "CfgDynMarkers" >> "DynMarkers_Settings" >> "fields_position_time");
if (_stayTime == 0) exitWith {
    diag_log "--------------------------------------";
    diag_log "Error: fields_position_time is set to 0!";
    diag_log "--------------------------------------";
};

private ["_createDrugFieldMarker", "_createDrugFieldAreaMarker"];

//Used for marking Field on the Map
_createDrugFieldMarker = {
    private ["_drugType", "_drugName", "_color", "_markerType", "_location", "_markerName", "_drugFieldMarker", "_locationArray"];

    _params = params [
        ["_drugType", "", [""]],
        ["_drugName", "", [""]],
        ["_color", "", [""]],
        ["_markerType", "", [""]]
    ];

    _locationArray = getArray(missionConfigFile >> "CfgDynMarkers" >> "DynMarkers_Settings" >> format ["%1_locations", _drugType]);
    if (count _locationArray == 0) exitWith {
        diag_log format ["Error: No %1 locations defined!", _drugType];
    };

    _location = selectRandom _locationArray;

    _markerName = format ["%1_field", _drugType];
    deleteMarker _markerName;
    _drugFieldMarker = createMarker [_markerName, _location];
    _drugFieldMarker setMarkerColor _color;
    _drugFieldMarker setMarkerType _markerType;
    _drugFieldMarker setMarkerText _drugName;

    format ["%1_field", _drugType] setMarkerPos _location;

    diag_log format ["Created %1 Map Marker At: %2", _drugType, _location];
};

//Main Marker Used for Config_Gather.hpp
_createDrugFieldAreaMarker = {
    private ["_drugType", "_areaMarkerName", "_areaMarkerPos", "_drugFieldAreaMarker"];

    _drugType = param [0, "", [""]];

    _areaMarkerName = format ["%1_zone", _drugType];
    _areaMarkerPos = getMarkerPos _areaMarkerName;
    deleteMarker _areaMarkerName;
    _drugFieldAreaMarker = createMarker [_areaMarkerName, _areaMarkerPos];
    _drugFieldAreaMarker setMarkerColor "ColorWhite";
    _drugFieldAreaMarker setMarkerType "empty";
    _drugFieldAreaMarker setMarkerShape "ELLIPSE";
    _drugFieldAreaMarker setMarkerSize [30, 30];

    if(_areaMarkerName in allMapMarkers)then{
        diag_log format ["Created %1 Gather Zone At: %2", _drugType, _areaMarkerPos];
    };
};

{
    _x call _createDrugFieldMarker;
    _x call _createDrugFieldAreaMarker;
} forEach _drugLocations;

sleep (_stayTime * 60);

{
    private _drugType = _x select 0;
    private _markerName = format ["%1_field", _drugType];
    private _areaMarkerName = format ["%1_zone", _drugType];
    deleteMarker _markerName;
    deleteMarker _areaMarkerName;

    diag_log format ["Removed %1 field marker and area marker", _drugType];
} forEach _drugLocations;

diag_log "---------------------------";
diag_log "Dyn Drug Fields: Removed...";
diag_log "---------------------------";

//Repsawn the drug fields
{
    _x call _createDrugFieldMarker;
    _x call _createDrugFieldAreaMarker;
} forEach _drugLocations;

diag_log "--------------------------------------";
diag_log "Dyn Drug Fields: Respawning...";
diag_log "--------------------------------------";

C++:
"Created weed Map Marker At: [11556.4,7048.07,0]"
"Created weed Gather Zone At: [0,0,0]"
"Created heroin Map Marker At: [19879,17006.7,0]"
"Created heroin Gather Zone At: [0,0,0]"
"Created cocaine Map Marker At: [25915.7,20678,0]"
"Created cocaine Gather Zone At: [0,0,0]"
 
Solved the issus, can close.
C++:
/*
    File: fn_dynDrugFields.sqf
    Author: Your Mom /(.)(.)\
*/

diag_log "--------------------------------------";
diag_log "Drug Fields Init: Initializing...";
diag_log "--------------------------------------";

// Lets Make them waite
sleep(1*60);


diag_log "--------------------------------------";
diag_log "Dyn Drug Fields: Initializing...";
diag_log "--------------------------------------";

private _drugLocations = [
    ["weed", "Weed Field", "ColorRed", "mil_dot"],
    ["heroin", "Heroin Field", "ColorRed", "mil_dot"],
    ["cocaine", "Cocaine Field", "ColorRed", "mil_dot"]
];

private _stayTime = getNumber(missionConfigFile >> "CfgDynMarkers" >> "DynMarkers_Settings" >> "fields_position_time");
if (_stayTime == 0) exitWith {
    diag_log "--------------------------------------";
    diag_log "Error: fields_position_time is set to 0!";
    diag_log "--------------------------------------";
};

private ["_createDrugFieldMarker", "_createDrugFieldAreaMarker"];

//Used for marking Field on the Map
_createDrugFieldMarker = {
    private ["_drugType", "_drugName", "_color", "_markerType", "_location", "_markerName", "_drugFieldMarker", "_locationArray"];

    _params = params [
        ["_drugType", "", [""]],
        ["_drugName", "", [""]],
        ["_color", "", [""]],
        ["_markerType", "", [""]]
    ];

    _locationArray = getArray(missionConfigFile >> "CfgDynMarkers" >> "DynMarkers_Settings" >> format ["%1_locations", _drugType]);
    if (count _locationArray == 0) exitWith {
        diag_log format ["Error: No %1 locations defined!", _drugType];
    };

    _location = selectRandom _locationArray;

    _markerName = format ["%1_field", _drugType];
    _drugFieldMarker = createMarker [_markerName, _location];
    _drugFieldMarker setMarkerColor _color;
    _drugFieldMarker setMarkerType _markerType;
    _drugFieldMarker setMarkerText _drugName;

    format ["%1_field", _drugType] setMarkerPos _location;

    diag_log format ["Server Created %1 Map Marker At: %2", _drugType, _location];
};

//Main Marker Used for Config_Gather.hpp
_createDrugFieldAreaMarker = {
    private ["_drugType", "_areaMarkerName", "_areaMarkerPos", "_drugFieldAreaMarker","_zoneMarkerName"];

    _params = params [
        ["_drugType", "", [""]]
    ];

    _areaMarkerName = format ["%1_field", _drugType];
    _zoneMarkerName = format ["%1_zone", _drugType];
    _areaMarkerPos = getMarkerPos _areaMarkerName;
    _drugFieldAreaMarker = createMarker [_zoneMarkerName, _areaMarkerPos];
    _drugFieldAreaMarker setMarkerColor "ColorWhite";
    _drugFieldAreaMarker setMarkerType "empty";
    _drugFieldAreaMarker setMarkerShape "ELLIPSE";
    _drugFieldAreaMarker setMarkerSize [30, 30];

    format ["%1_zone", _drugType] setMarkerPos _areaMarkerPos;

    if(_areaMarkerName in allMapMarkers)then{
        diag_log format ["Server Created %1 Gather Zone At: %2", _drugType, _areaMarkerPos];
    };
};

{
    _x call _createDrugFieldMarker;
    _x call _createDrugFieldAreaMarker;
} forEach _drugLocations;

sleep (_stayTime * 60);

{
    private _drugType = _x select 0;
    private _markerName = format ["%1_field", _drugType];
    private _areaMarkerName = format ["%1_zone", _drugType];
    deleteMarker _markerName;
    deleteMarker _areaMarkerName;

    diag_log format ["Server Removed %1 field marker and area marker", _drugType];
} forEach _drugLocations;

diag_log "---------------------------";
diag_log "Dyn Drug Fields: Removed...";
diag_log "---------------------------";

//Repsawn the drug fields
{
    _x call _createDrugFieldMarker;
    _x call _createDrugFieldAreaMarker;
} forEach _drugLocations;

diag_log "--------------------------------------";
diag_log "Dyn Drug Fields: Respawning...";
diag_log "--------------------------------------";
 
  • Muscle
Les réactions: Maxence
Solution