Jump to content

Recommended Posts

I would love to have a intel gathering system similar to the Extraction mission from WS. Im not looking to have the fancy transitions where the intel appears on the desk when its handed in at HQ but something a bit simpler.

Im an absolute scripting newb so I tried Chat GPT to help 🙂

 

It worked out the first part of the system where the enemy has a random chance of spawning intel in their inventory that I can collect as a physical item in my inventory

 

private _intelItems = ["MobilePhone","SmartPhone","FlashDisk","Wallet_ID"];
/*
This function will add random item to unit, if the unit has space in inventory for it.
How to use the function:
[
 unit,//<unit> to which item should be added
 [],//<array of strings> array of items that function should add (this array can´t be empty)
 0,//<scalar> number that will be randomized. (default:10)
 0//<scalar> number that should be always lower than number randomized. The lower the number is the higher is the chance that unit will have the item generated. If number is 0 every unit will have random item selected (default:0)
] spawn soldierXXXX_fnc_randomItem;
Example:[player,["FirstAidKit"],10,1] spawn soldierXXXX_fnc_randomItem;
*/
soldierXXXX_fnc_randomItem = {
                              scriptName "RandomItem";
                              params ["_unit","_itemsArray",["_RandomNumber",10],["_RandomNumberLow",3]];
                              private _addIntel = round random _RandomNumber;
                              if (_addIntel < _RandomNumberLow) exitWith {};
                              private _randomItem = selectRandom _itemsArray;
                              if (_unit canAdd _randomItem) then {
                                                                  _unit addItem _randomItem;
                                                                 };
                             };
{
 [_x,_intelItems,10,6] spawn soldierXXXX_fnc_randomItem;
} forEach units opfor;

 

But I'm (Chat GPT) really struggling to work out anyway of counting how many items of intel the player has collected and anyway of dropping the intel off back at HQ. If I could have a counter of how many has been collected I could start activating triggers and events as the mission progresses. Any help would be very much appreciated! 

Share this post


Link to post
Share on other sites

Lol no way. Did ChatGPT just stole my code? I've used it here in this topic. That just really made me laugh 🤣. When i'm back at home, i will see how can i help. I'm thinking about implementing "take" and "put" eventhandlers with some action that can do something similar like what you see in extraction. Or maybe someone will be quicker than me and solves your issue. 😉 

Edit:

Actually take and put eventhandlers might not be needed at all. Action that removes all required items from your inventory and adds numeric variable might do just fine.

Do you need it for singleplayer or multiplayer?

  • Thanks 1
  • Haha 4

Share this post


Link to post
Share on other sites

Ha, I think it probably did! Anything before Sept 2021 and Chat GPT has probably read it lol I've found that GPT uses and tries to adapt lots of content found in this forum especially GPT 4 that has Bing internet search integrated. I will just be using it in single player. Thanks in advance for the speedy reply

Share this post


Link to post
Share on other sites

This is my convo with Chat GPT and the AI's effort at creating a script that removes all intel items and keeps count. 

 

I haven't tested it yet but thanks for pointing me in the right direction. the AI tends to make up code and syntax so it normally means i have to kind of reverse engineer what it's trying to do and fix the syntax errors. For a noob it's great for simple scripting and story ideas etc

 

PROMPT:

 

This is the script i use to gather intel in my arma 3 mission:

 

private _intelItems = ["MobilePhone","SmartPhone","FlashDisk","Wallet_ID"];
/*
This function will add random item to unit, if the unit has space in inventory for it.
How to use the function:
[
 unit,//<unit> to which item should be added
 [],//<array of strings> array of items that function should add (this array can´t be empty)
 0,//<scalar> number that will be randomized. (default:10)
 0//<scalar> number that should be always lower than number randomized. The lower the number is the higher is the chance that unit will have the item generated. If number is 0 every unit will have random item selected (default:0)
] spawn soldierXXXX_fnc_randomItem;
Example:[player,["FirstAidKit"],10,1] spawn soldierXXXX_fnc_randomItem;
*/
soldierXXXX_fnc_randomItem = {
                              scriptName "RandomItem";
                              params ["_unit","_itemsArray",["_RandomNumber",10],["_RandomNumberLow",3]];
                              private _addIntel = round random _RandomNumber;
                              if (_addIntel < _RandomNumberLow) exitWith {};
                              private _randomItem = selectRandom _itemsArray;
                              if (_unit canAdd _randomItem) then {
                                                                  _unit addItem _randomItem;
                                                                 };
                             };
{
 [_x,_intelItems,10,6] spawn soldierXXXX_fnc_randomItem;
} forEach units opfor;

 

Can you create a script that removes all required items from my inventory and keeps count of how many I have handed in

 

ANSWER:

 

Sure, I can provide a script for that. This script will go through your inventory and count and remove all items listed in _intelItems

 

/*
This function will remove and count certain items from a unit's inventory.
How to use the function:
[
 unit, //<unit> whose inventory will be checked
 array //<array of strings> array of items that function should remove and count
] call soldierXXXX_fnc_removeAndCount;
Example: [player, ["MobilePhone","SmartPhone","FlashDisk","Wallet_ID"]] call soldierXXXX_fnc_removeAndCount;
*/

soldierXXXX_fnc_removeAndCount = {
    scriptName "RemoveAndCount";
    params ["_unit", "_itemsArray"];
    private _itemCount = 0;
    {
        if (_unit canAdd _x) then {
            while {_unit canAdd _x} do {
                _unit removeItem _x;
                _itemCount = _itemCount + 1;
            };
        };
    } forEach _itemsArray;
    _itemCount
};

/*
To use the function and display the count of items removed, you can use:
*/

private _count = [player, ["MobilePhone","SmartPhone","FlashDisk","Wallet_ID"]] call soldierXXXX_fnc_removeAndCount;
hint format ["You have handed in %1 items.", _count];

 

This function will remove all instances of the items in the _itemsArray from the inventory of the _unit and count how many items have been removed in total. The count is then returned by the function. The last part of the script calls the function with the player as the unit and displays a hint with the total count of items removed.

 

 

Share this post


Link to post
Share on other sites

Yeah that code won't work because, as I'm reading what AI wrote, there might be two situations.

1) player might have full inventory and thus can't add any item so it will just return 0. 

2) player might be able to add item to inventory and the script will get stucked in while loop and since it's run in unscheduled environment it should stop around 10000 iterations and you don't want that. Pretty sure it would freeze arma if not whole PC 😄

If by any chance code worked it would have to repeat this process for x times depending on array length. However this is not what you desire. You want something much simpler and optimized. 

I will write the code for you when I'll return home. 

Basically the logic would be:

Global variable of items given;//this will be good for triggers implementation

Function:

Count items that are relevant;

Add this number to global variable;

Remove all relevant items from player's inventory

 

Currently I'm still at work, so I'll do it as soon as I'm available 😉

 

  • Like 1

Share this post


Link to post
Share on other sites

Your a legend! the day when AI replaces us all is a long way off LOL

  • Like 1

Share this post


Link to post
Share on other sites

So i just finished the code you wanted. Triggers can work with CollectedItems variable. Variable is number that is tracking how many intel you handed over. To see how many items you handed over you can write:

hint format ["Items i have handed over:%1",CollectedItems];

Condition in trigger might be something like this example if you have collected 13 and more items.

CollectedItems > 12;


The script is run from action that i demonstratively attached to player. I´ve added classic scroll menu action and hold action. Choose one you like more and delete the other one.
Only change in the original code is that local variable _intelItems was changed to global variable intelItems. Why ? Because now you need to access information about array of items in more than one script (or scope to be precise). Global variables are just better for changing information on single place. I´ve also added notification, but delete it if you want.

Put this whole code to init.sqf and it will work (or elsewhere if you want). This is solution for singleplayer. For multiplayer it must be done differently.

Spoiler

//Basically the same function just changed local variable for global variable as more than one script needs to access the informations.
intelItems = ["MobilePhone","SmartPhone","FlashDisk","Wallet_ID"];
soldierXXXX_fnc_randomItem = {
                              scriptName "RandomItem";
                              params ["_unit","_itemsArray",["_RandomNumber",10],["_RandomNumberLow",0]];
                              private _addIntel = round random _RandomNumber;
                              if (_addIntel < _RandomNumberLow) exitWith {};
                              private _randomItem = selectRandom _itemsArray;
                              if (_unit canAdd _randomItem) then {
                                                                  _unit addItem _randomItem;
                                                                 };
                             };
{
 [_x,intelItems,10,6] spawn soldierXXXX_fnc_randomItem;
} forEach units opfor;

CollectedItems = 0;//this global variable is tracking how many intel did you handed over at HQ. Might be used to create trigger condition you wanted

//Function that removes items from inventory. Notice that removeItems doesn´t work here because items are changed to magazines when you take them.
soldierXXXX_fnc_CollectIntel = {
scriptName "soldierXXXX_fnc_CollectIntel";
params ["_unit","_itemsArray"];
private _numberItems = {_x in _itemsArray} count magazines _unit;
CollectedItems = CollectedItems + _numberItems;
{_unit removeMagazines _x;} forEach intelItems;
//Fancy notification-you may delete it if you don´t like it :D
if (_numberItems > 0) then {
["IntelAdded", ["Intel secured","a3\ui_f\data\igui\cfg\actions\ico_on_ca.paa"]] call BIS_fnc_showNotification;
};
};

//for demonstration actions are attached to player - you can attach it to any object except simple objects or agents
//choose what action you like more and delete the other one, also you can add your own conditions when to show action.

//click action-basic action menu interaction
player addAction
[
	"Hand over intel",// Title of the action
	{
		params ["_target", "_caller", "_actionId", "_arguments"];
		[_caller,intelItems] spawn soldierXXXX_fnc_CollectIntel;
	},// Code
	nil,//arguments
	15,//priority
	true,//show window
	true,//hide on use
	"",//shortcut
	"true", //condition  (available params _target, _this, _originalTarget)
	3,//radius
	false,//Show in unconscious state 
	"",//selection
	""//memory point
];

//hold action-new and nice interaction
[
 player,// Object the action is attached to
 "Hand over intel",// Title of the action
 "a3\ui_f\data\igui\cfg\holdactions\holdaction_unloaddevice_ca.paa",// Idle icon shown on screen
 "\a3\ui_f\data\IGUI\Cfg\holdactions\holdAction_thumbsup_ca.paa",// Progress icon shown on screen
 "alive _target AND {(_this distance _target) < 3}",// Condition for the action to be shown, Special variables passed to the script code are _target (unit to which action is attached to) and _this (caller/executing unit)
 "alive _target AND {(_caller distance _target) < 3}",// Condition for the action to progress, arguments passed into it are: _target, _caller, _id, _arguments
 {},// Code executed when action starts
 {},// Code executed on every progress tick
 {
  //params ["_target", "_caller", "_actionId", "_arguments"];
  [_caller,intelItems] spawn soldierXXXX_fnc_CollectIntel;
 },// Code executed on completion
 {},// Code executed on interrupted
 [],// Arguments passed to the scripts as _this select 3
 3,// Action duration [s]
 15,// Priority
 FALSE,// Remove on completion
 FALSE// Show in unconscious state 
]  call BIS_fnc_holdActionAdd;

 


You can change parameters to your liking. I´ve commented most of them. If you have questions, i´m happy to answer them. 🙂 

  • Like 2

Share this post


Link to post
Share on other sites

Wow! Thankyou so much doing this. I can't wait to test it later. I will let you know how I get on.

Share this post


Link to post
Share on other sites

I've tried the freely available version of chatgpt 3 times, just purely out of curiosity. All 3 times i had to tell it that it was wrong, and it wasn't difficult stuff that it got wrong. I agree, chatgpt is not a good alternative.

  • Like 1

Share this post


Link to post
Share on other sites
15 hours ago, beno_83au said:

 I agree, chatgpt is not a good alternative.

 

Agree. Human devs have some difficulties scripting AI behaviors... I doubt AIs will do better soon about human thought.

  • Like 1

Share this post


Link to post
Share on other sites

Maybe full ability AI yes chatgpt is so cuted that it act like young student on exams (he know something and trying to tell you that he know exactly how to do it - finally it not work correctly - but exam was pass - something he do at last -so when I hears about those test for IT programmer of some level passed by AI - in my head create ask - who do this exam and what was questions or taks for this AI and what was levels to pass it, after few tests i think this kind of info is rather PR for AI engines for now, but if it grow maybe some day they will do exams not be examined .

Share this post


Link to post
Share on other sites
17 minutes ago, h4wek said:

but if it grow maybe some day they will do exams not be examined

Right, and what would we be doing then? Pursuing some artistic and philosophical endeavors that we never got the chance to because of all the chores hindering us? Oh wait...

  • Like 1

Share this post


Link to post
Share on other sites

I don't know what will happen next but real is that AI exist and groving up, your vision is very probable question only if and how fast will be possibile in that form. Most of humans can't look for this problem from outside without self afraid of AI concurrency or like for AI as new spicies (not organic but maybe in whole evoluition chain this is logically next step in all worlds in universe so we are only some step of evolution of intelligence andmost of humans are terryfing by this vision - that we are not end of chain but only part). But don't worry will take some time to make it real i mabe even  not in time of our lives.

Share this post


Link to post
Share on other sites
20 hours ago, h4wek said:

not organic but maybe in whole evoluition chain this is logically next step in all worlds in universe so we are only some step of evolution of intelligence andmost of humans are terryfing by this vision

Not at all what I was getting at but if one is looking at the world through the lens of Hollywood rather then reality, then yeah, that's the line of thinking.

Share this post


Link to post
Share on other sites

Evolution will test all possibilities and only ones viable will continue. Rotten branches will fall. That doesn't mean bad ones! Difficult to predict what will stay alive, for how many time. Humans are just a temporary link.
And yes, Hollywood often works on Arma 5, where AIs produce human being for their plays... and even Arma 6 when AIs are gods reformatting Universe.
Until they do, ChatGPT doesn't have real creativity, just a guided "imagination". 

evolution.png?raw=1

Share this post


Link to post
Share on other sites
On 6/1/2023 at 3:32 AM, CMDR Echo3 said:

I would love to have a intel gathering system similar to the Extraction mission from WS. Im not looking to have the fancy transitions where the intel appears on the desk when its handed in at HQ but something a bit simpler.

Im an absolute scripting newb so I tried Chat GPT to help 🙂

 

It worked out the first part of the system where the enemy has a random chance of spawning intel in their inventory that I can collect as a physical item in my inventory

 

private _intelItems = ["MobilePhone","SmartPhone","FlashDisk","Wallet_ID"];
/*
This function will add random item to unit, if the unit has space in inventory for it.
How to use the function:
[
 unit,//<unit> to which item should be added
 [],//<array of strings> array of items that function should add (this array can´t be empty)
 0,//<scalar> number that will be randomized. (default:10)
 0//<scalar> number that should be always lower than number randomized. The lower the number is the higher is the chance that unit will have the item generated. If number is 0 every unit will have random item selected (default:0)
] spawn soldierXXXX_fnc_randomItem;
Example:[player,["FirstAidKit"],10,1] spawn soldierXXXX_fnc_randomItem;
*/
soldierXXXX_fnc_randomItem = {
                              scriptName "RandomItem";
                              params ["_unit","_itemsArray",["_RandomNumber",10],["_RandomNumberLow",3]];
                              private _addIntel = round random _RandomNumber;
                              if (_addIntel < _RandomNumberLow) exitWith {};
                              private _randomItem = selectRandom _itemsArray;
                              if (_unit canAdd _randomItem) then {
                                                                  _unit addItem _randomItem;
                                                                 };
                             };
{
 [_x,_intelItems,10,6] spawn soldierXXXX_fnc_randomItem;
} forEach units opfor;

 

But I'm (Chat GPT) really struggling to work out anyway of counting how many items of intel the player has collected and anyway of dropping the intel off back at HQ. If I could have a test counter of how many has been collected I could start activating triggers and events as the mission progresses. Any help would be very much appreciated! 

To count the intel items collected by the player, you can create a global variable to store the count. Increment this variable each time the player collects intel. To drop off intel at HQ, you can implement a trigger at the HQ location and use a script to check the player's inventory for intel items, updating the count and removing the items accordingly.

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

×