Jump to content
Sign in to follow this  
redarmy

General scripting performance question

Recommended Posts

If i create a scenario with a few hundred AI(Shown/hidden throught scenario) and in their Init line,add some code for a damage multiplier,will it in some way drop performance?And if so in what way?

Im running bcombat which has in the config,a damage multiplier option,however it breaks the revive script i use.So i essentially want to add a damage multiplier for all units except me,the player,this is the best way i can think of doing it.

This is only for SP scenario,cheers

Share this post


Link to post
Share on other sites

Shouldn't be too much of a performance hit if you do it correctly.

Share this post


Link to post
Share on other sites

If you just add an eventhandler to each unit's init you should be golden. eg

this addeventhandler ["hit",{_unit = _this select 0;_dam = _this select 2; _dam = _dam * multiplier; _unit setdamage _dam}]

Not in front of my Arma box so can't confirm it working, but you get the idea.

Eventhandlers themselves use microscopic amounts of CPU, and the simple code in this one should cause no slowdowns.

Share this post


Link to post
Share on other sites

Sweet as a nut thanks guys.

Yeah TPW i had a line of code but it was 4times longer than yours for some reason,will give yours a shot.

---------- Post added at 11:18 ---------- Previous post was at 10:47 ----------

Tested with your code TPW it didnt work,though i think its correct.Iv tested with other ways:

_unit addeventhandler ["handledamage",{

_damage = _this select 2;

// Increase damage

_damage = _damage * 3;

_damage

}];

Still no luck.Im just gona guess Bcombat multiplier at 1.0 is cancelling out the units init

Share this post


Link to post
Share on other sites
this addeventhandler ["hit",{_unit = _this select 0;_dam = _this select 2; _dam = _dam * multiplier; _unit setdamage _dam}]

Do note that the damage that is returned using (_this select 2) is the total damage of the unit after calculating damage from the hit. Using this code will result in an exponential damage increase, not a base damage increase. To do this properly, you must first isolate the damage that the hit caused, then multiply that, then set the damage to the unit. I may have been thinking of the "HandleDamage" event handler instead.

this addEventHandler ["HandleDamage",
{
_unit = _this select 0;
_totalDamage = _this select 2;
_curHealth = damage _unit;

_shotDamage = _totalDamage - _curHealth; //Isolate the damage that the shot caused
(_curHealth + (_shotDamage * DAMAGE_MULTIPLIER)); //Return the modified damage to the engine because the engine will take care of adding the damage to the unit
}];

In this code, I have set a global variable called DAMAGE_MULTIPLIER which you can set in init.sqf (or wherever you want). Alternatively, you can just replace that with a number.

Also, this.

Tested with your code TPW it didnt work

lol. like...how can we help you if you don't give any details about it "not working".

Edited by DreadedEntity

Share this post


Link to post
Share on other sites
Do note that the damage that is returned using (_this select 2) is the total damage of the unit after calculating damage from the hit. Using this code will result in an exponential damage increase, not a base damage increase. To do this properly, you must first isolate the damage that the hit caused, then multiply that, then set the damage to the unit. I may have been thinking of the "HandleDamage" event handler instead.

this addEventHandler ["HandleDamage",
{
_unit = _this select 0;
_totalDamage = _this select 2;
_curHealth = damage _unit;

_shotDamage = _totalDamage - _curHealth; //Isolate the damage that the shot caused
(_curHealth + (_shotDamage * DAMAGE_MULTIPLIER)); //Return the modified damage to the engine because the engine will take care of adding the damage to the unit
}];

In this code, I have set a global variable called DAMAGE_MULTIPLIER which you can set in init.sqf (or wherever you want). Alternatively, you can just replace that with a number.

Also, this.

lol. like...how can we help you if you don't give any details about it "not working".

Cheers

When i say its "not working" i mean the damage multiplier isnt coming into effect.Vanilla damage remains

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
Sign in to follow this  

×