Kc Jones 0 Posted December 20, 2023 Hello I'm trying to write a simple script to reward players on killing an enemy AI to receive an item that will be added to their inventory. I've been looking around and I have not been able to find anything that works. The item I am trying to use is the bank notes from ravage because I'm using the VASS “virtual arsenal shop system” so that players can also purchase weapons, ammo and gear Etc. I do know I had something to do with add event handlers but I've just can't figure it out whatsoever. If you have any examples please post it would be very helpful in creating my multiplayer mission. Thank you. Share this post Link to post Share on other sites
j0nes 194 Posted December 20, 2023 Untested but you'd need to add a "Killed" eventHandler to every AI you want to reward them for. (I dont think you'll need the MPKilled eventhandler for this scenario, just the regular one) AIunit addEventHandler ["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; _rewardAmount = round(random [50,70,100]) //REWARD SOMEWHERE BETWEEN $50 & $100 //ADD THE MONEY ITEMS (IDK IF ITS $1 = 1 MONEY ITEM, SO ADJUST ACCORDINGLY) for "_i" from 1 to _rewardAmount do { if(!canAdd "moneyItem")exitWith{}; //NOT ENOUGH SPACE, CANT ADD _killer addItem "moneyItem"; }; _hintStr = format["Congrats murderer... heres $%1",_rewardAmount]; //SHOW A HINT WITH THE AMOUNT THEYVE EARNED [_hintStr] remoteExec ["hint",local _killer]; }]; Share this post Link to post Share on other sites
j0nes 194 Posted December 20, 2023 ACTUALLY, this might work better for your purposes. should only have to add this to the server (if someone could check me on this, my MP coding has never been great) addMissionEventHandler ["EntityKilled", { params ["_killed", "_killer", "_instigator"]; if (isNull _instigator) then { _instigator = UAVControl vehicle _killer select 0 }; // UAV/UGV player operated road kill if (isNull _instigator) then { _instigator = _killer }; // player driven vehicle road kill //ADD THE MONEY ITEMS (IDK IF ITS $1 = 1 MONEY ITEM, SO ADJUST ACCORDINGLY) for "_i" from 1 to _rewardAmount do { if(!canAdd "moneyItem")exitWith{}; //NOT ENOUGH SPACE, CANT ADD _instigator addItem "moneyItem"; }; _hintStr = format["Congrats murderer... heres $%1",_rewardAmount]; //SHOW A HINT WITH THE AMOUNT THEYVE EARNED [_hintStr] remoteExec ["hint",local _instigator]; }]; Share this post Link to post Share on other sites
Kc Jones 0 Posted December 21, 2023 So I've tried to implement both codes Within my game and I keep getting a “ error GIAR pre stack size violation “ The code placed below is what I'm trying to implement so far with the added “rvg_money” item. In my initServer.sqf addMissionEventHandler ["Killed", { params ["_unit", "_killer", "_instigator", "_useEffects"]; _rewardAmount = round(random [50,70,100]) //REWARD SOMEWHERE BETWEEN $50 & $100 //ADD THE MONEY ITEMS (IDK IF ITS $1 = 1 MONEY ITEM, SO ADJUST ACCORDINGLY) for "_i" from 1 to _rewardAmount do { if(!canAdd "rvg_money")exitWith{}; //NOT ENOUGH SPACE, CANT ADD _killer addItem "rvg_money"; }; _hintStr = format["Congrats murderer... heres $%1",_rewardAmount]; //SHOW A HINT WITH THE AMOUNT THEYVE EARNED [_hintStr] remoteExec ["hint",local _killer]; }]; Share this post Link to post Share on other sites
j0nes 194 Posted December 21, 2023 The eventhandler type in the first line needs to be "EntityKilled" not just "Killed" I THINK thatll solve it Share this post Link to post Share on other sites
itomcurrann 0 Posted December 26, 2023 On 12/20/2023 at 10:59 PM, Kc Jones said: Hello I'm trying to write a simple script to reward players on killing an enemy AI to receive an item that will be added to their inventory. I've been looking around and I have not been able to find anything that works. The item I am trying to use is the bank notes from ravage because I'm using the VASS “virtual arsenal shop system” so that players can also purchase weapons, ammo and gear Etc. I do know I had something to do with add event handlers but I've just can't figure it out whatsoever. If you have any examples please post it would be very helpful in creating my multiplayer mission. Thank you. Creating a script to reward players for killing an enemy AI in Arma 3 involves using event handlers and scripting. Here's a simple example to get you started. This script assumes you have a basic understanding of Arma 3 scripting. Create a new file (e.g., rewardScript.sqf) in your mission folder. Open the file and add the following code: // rewardScript.sqf // Define the item class name you want to add to the player's inventory (replace "YourItemClass" with the actual class name). _rewardItem = "YourItemClass"; // Define the amount of items to add to the player's inventory. _rewardAmount = 1; // Event handler function to be executed when an AI unit is killed. _rewardEventHandler = { params ["_unit", "_killer", "_instigator"]; // Check if the killer is a player. if (isPlayer _killer) then { // Add the reward item to the player's inventory. _killer addItemToBackpack [_rewardItem, _rewardAmount]; // You can also add additional actions or code here. // Display a hint to the player (optional). hint format ["You received %1 %2 for killing an enemy!", _rewardAmount, _rewardItem]; }; }; // Register the event handler. "ManKilled" addEventHandler ["killed", _rewardEventHandler]; In your mission, open the init.sqf file (or create one if it doesn't exist) and add the following line at the end: execVM "rewardScript.sqf"; Replace "YourItemClass" with the actual class name of the bank notes from the Ravage mod. This script registers an event handler that triggers whenever an AI unit is killed. It checks if the killer is a player and adds the specified item to the player's backpack. Customize the script according to your needs, and make sure to test it in your multiplayer mission. Share this post Link to post Share on other sites