Home   Help Search Login Register  

Author Topic: addrating/rating how?(SOLVED)  (Read 1733 times)

0 Members and 2 Guests are viewing this topic.

Offline Odin

  • Members
  • *
addrating/rating how?(SOLVED)
« on: 26 Sep 2008, 08:40:39 »
G'day, whilst I understand the concepts of addrating/addscore for certain things how do I get it to work for ordanance?
I have just been searching and can not find a reference about it. I have had a few feeble attempts at it but no luck.

What I need it for is a parafrag script I have been making and would like the player to recieve a score for any units destroyed courtesy of the parafrags, in both SP and MP.

this is my script

Code: [Select]
_vehicle = _this select 0
_position = _this select 1
_unit = _this select 2
#init
?((position player select 2)<99): goto "end"
?((position player select 2)>99): goto "start"
#start
_vehicle removeAction frag
hint "FRAGS-AWAY!!"
_parafrag = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute = "ParachuteWest" createVehicle getPos _parafrag;
~0.25
_parafrag1 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute1 = "ParachuteWest" createVehicle getPos _parafrag1;
~0.25
_parafrag2 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute2 = "ParachuteWest" createVehicle getPos _parafrag2;
~0.25
_parafrag3 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute3 = "ParachuteWest" createVehicle getPos _parafrag3;
~0.25
_parafrag4 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute4 = "ParachuteWest" createVehicle getPos _parafrag4;
~0.25
_parafrag5 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute5 = "ParachuteWest" createVehicle getPos _parafrag5;
~0.25
_parafrag6 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute6 = "ParachuteWest" createVehicle getPos _parafrag6;
~0.25
_parafrag7 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute7 = "ParachuteWest" createVehicle getPos _parafrag7;
~0.25
_parafrag8 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute8 = "ParachuteWest" createVehicle getPos _parafrag8;
~0.25
_parafrag9 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute9 = "ParachuteWest" createVehicle getPos _parafrag9;
~0.25
_parafrag10 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute10 = "ParachuteWest" createVehicle getPos _parafrag10;

hint "RTB for more Frags"
rearm = true
#loop
_parafrag setVelocity [(velocity _parafrag select 0) / 1.1, (velocity _parafrag select 1) / 1.1, -9] 
_fragchute setPos getPos _parafrag
_parafrag SetVectorUp (vectorUp _fragchute0)
_parafrag1 setVelocity [(velocity _parafrag1 select 0) / 1.1, (velocity _parafrag1 select 1) / 1.1, -9] 
_fragchute1 setPos getPos _parafrag1
_parafrag1 SetVectorUp (vectorUp _fragchute1)
_parafrag2 setVelocity [(velocity _parafrag2 select 0) / 1.1, (velocity _parafrag2 select 1) / 1.1, -9] 
_fragchute2 setPos getPos _parafrag2
_parafrag2 SetVectorUp (vectorUp _fragchute2)
_parafrag3 setVelocity [(velocity _parafrag3 select 0) / 1.1, (velocity _parafrag3 select 1) / 1.1, -9] 
_fragchute3 setPos getPos _parafrag3
_parafrag3 SetVectorUp (vectorUp _fragchute3)
_parafrag4 setVelocity [(velocity _parafrag4 select 0) / 1.1, (velocity _parafrag4 select 1) / 1.1, -9] 
_fragchute4 setPos getPos _parafrag4
_parafrag4 SetVectorUp (vectorUp _fragchute4)
_parafrag5 setVelocity [(velocity _parafrag5 select 0) / 1.1, (velocity _parafrag5 select 1) / 1.1, -9] 
_fragchute5 setPos getPos _parafrag5
_parafrag5 SetVectorUp (vectorUp _fragchute5)
_parafrag6 setVelocity [(velocity _parafrag6 select 0) / 1.1, (velocity _parafrag6 select 1) / 1.1, -9] 
_fragchute6 setPos getPos _parafrag6
_parafrag6 SetVectorUp (vectorUp _fragchute6)
_parafrag7 setVelocity [(velocity _parafrag7 select 0) / 1.1, (velocity _parafrag7 select 1) / 1.1, -9] 
_fragchute7 setPos getPos _parafrag7
_parafrag7 SetVectorUp (vectorUp _fragchute7)
_parafrag8 setVelocity [(velocity _parafrag8 select 0) / 1.1, (velocity _parafrag8 select 1) / 1.1, -9] 
_fragchute8 setPos getPos _parafrag8
_parafrag8 SetVectorUp (vectorUp _fragchute8)
_parafrag9 setVelocity [(velocity _parafrag9 select 0) / 1.1, (velocity _parafrag9 select 1) / 1.1, -9] 
_fragchute9 setPos getPos _parafrag9
_parafrag9 SetVectorUp (vectorUp _fragchute9)
_parafrag10 setVelocity [(velocity _parafrag10 select 0) / 1.1, (velocity _parafrag10 select 1) / 1.1, -9] 
_fragchute10 setPos getPos _parafrag10
_parafrag10 SetVectorUp (vectorUp _fragchute10)
goto "loop"
exit
#end
hint "to low"
exit

So to get it to score am I in need of publicvariables or can it all be done from with in the script? I am a bit lost on this :dunno:

I have a rearm pad and the script is only accsesable to the pilot and activated by "getin" and "getout" eventhandlers, I hope to pack and release it as soon as I can get it to score. :yes:


Thanx
Odin


« Last Edit: 27 Sep 2008, 23:46:08 by Odin »

Offline Wolfrug

  • Addons Depot
  • Former Staff
  • ****
  • Official OFPEC Old Timer
Re: addscore/score addrating/rating how?
« Reply #1 on: 26 Sep 2008, 14:17:15 »
My best bet would be a rather complicated one, especially if tried in MP (ask someone else about that - or more precisely, post in the appropriate forum), but it'd basically involve adding a host of "killed" eventhandlers on all units within a certain area who could potentially be slain by the parafrag, which would then add to your score (only important for MP) or rating (only really important for SP).

Here's the question: do you want the rating/score to be as complicated as default ArmA does it, or are you happy with just an approximation? Because the rating you get from say killing a soldier depends on for instance the rank of the soldier - and I might be wrong but I also think the "type" of the soldier is important (more rating for AT guys, machinegunners etc.). Rating is also used by the engine to determine how dangerous someone is, so. Same with score - you get more score for killing a BMP than killing a 5ton truck, and so on. To really make it work the same you'd need to figure out all these different combinations.

But since we're talking an eyeless faceless blind weapon of mass destruction here, I'd say getting an approximate score/rating added from those you "kill" should be enough, no?

I'd say something like this should work:

Create a dynamic trigger in the beginning of the script:
Code: [Select]

//_pos = the general center of the blasts
_trig = createtrigger ["EmptyDetector", _pos];
//_areax, _areay = the size of the blast, once again in general
_trig setTriggerArea [_areax, _areay, 0, false];
//_side = whatever side the enemy is on. You can use something like Mandoble's side-checking function to figure out, dynamically, who the player's enemies are. However you can also use "ANY" to add eventhandlers to everyone - potentially making friendly units detract points etc.
_trig settriggerActivation [_side, "PRESENT", false];

Now, sleep a second or so to let the trigger collect all the information it needs - generally the time it'd take for the bombs to hit the ground anyway should be enough, so don't worry too much about it. You do need to have a short wait inbetween creating _trig and using list _trig to get its information! Which is what we'll do next:

Code: [Select]
sleep 1;
_allunits = list _trig;
_EHList = [];
{_EH = _x addeventhandler ["killed", {Player addrating 100}]; _EHList = _EhList + [_EH]} forEach _allUnits;

Now, what I'm doing above is untested but should work: basically each unit is added a "killed" eventhandler (currently just adding 100 to the player's rating), and the eventhandler ID (just a number) is added to an array, which will later be used to remove the unnecessary "killed" eventhandlers.

Code: [Select]
//boom baam explode, people getting killed and eventhandlers getting run.
//Now we remove the eventhandlers gotten from the list above
_i= count (_allunits);
_j = 0;
while {_i < _j} do
{
private ["_unitList", "_unit", "_handler"];
_unitList = _allUnits;
_unit = _unitList select _j;
_handler = _EHList select _j;
_unit removeEventHandler ["killed", _handler];
_j = _j + 1;
sleep 0.02;
};

And now, hopefully, all the units who were in the area at the time have had their temporary eventhandlers removed - so if they escaped, you won't magically get twice the amount of rating for killing them again. :)

As noted, none of this has been tested in SP or MP, so take it with a grain of salt. Should work though. Might be a better way to remove the eventhandlers too, but I'm too lazy to go for...do-ing. Also, to make proper "friendly fire negative score" and so on work, you'll probably need to create a separate script for the eventhandler (instead of just {Player addrating 100}), but that's another discussion alltogether.  :good:

Good luck!

Wolfrug out.
"When 900 years YOU reach, look as good you will not!"

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: addscore/score addrating/rating how?
« Reply #2 on: 26 Sep 2008, 14:49:43 »
You don't start to keep the bombs next to the parachutes until 3 seconds after the first bomb has been dropped, which is probably after that first bomb has hit the ground. The loop that keeps the bombs in the correct place runs indefinitely, even after all the items have been destroyed, so ties up resources indefinitely. I could easily fix this in SQF, but you are using SQS so I don't think I can face sorting you out :whistle:

However, as to your original question: There is no easy way to add score based on kills caused by created objects. I really wish there was a way to assign the ownership of an object to a player, since I have lots of things that could benefit from this (actually, I've been thinking about a workaround for this recently, but it would require an addon).

Wolfrug's solution seems great for SP (MP has a dozen extra issues). However, if you or AI kills someone normally during the bombing period then you get the points twice. If someone is killed by an impersonal event (being run over, falling or being killed by created bombs), then the killer is the same object as the victim:
Code: [Select]
{_EH = _x addeventhandler ["killed", { _victim = _this select 0; _killer = _this select 1; if (_victim == _killer) then { addrating 100}}]; _EHList = _EhList + [_EH]} forEach _allUnits;
OK, not a big issue, but worth considering.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline Odin

  • Members
  • *
Re: addscore/score addrating/rating how?
« Reply #3 on: 27 Sep 2008, 00:05:19 »
Thx for the replies  :good: I havent had a chance to test yet as I am on my way to work but will ASAP, I am very gratefull for the code supplied

Quote
Here's the question: do you want the rating/score to be as complicated as default ArmA does it, or are you happy with just an approximation?
I am happy with just an approximation and at the moment I am going to put the MP scoreing on the backburner and just concentrate on the addRating. Also looks like I may have to convert it to sqf so as I can make more sense(get more help hehe) out of it.

yes my loop is a problem I tried a few ways of getting out of it with conditions and a count but as soon as I added it in the loop the chutes went all crazy and bombs fell out of them. anyway you both have given me food for thought.

Cheers :cool2:

EDIT: Thanx a bunch guys it is alive! well working. I still have it in SQS but I did manage to get outa that orrible loop ;) well here is the working version.

Code: [Select]
_vehicle = _this select 0
_position = _this select 1
_unit = _this select 2
_pos = getPos player;
_trig = createtrigger ["EmptyDetector", _pos];
_trig setTriggerArea [200, 200, 0, false];
_side = "ANY";
_trig settriggerActivation [_side, "PRESENT", false];
~0.5
#init
?((position player select 2)<99): goto "end"
?((position player select 2)>99): goto "start"
#start
_vehicle removeAction frag
hint "FRAGS-AWAY!!"
_parafrag = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute = "ParachuteWest" createVehicle getPos _parafrag;
~0.25
_parafrag1 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute1 = "ParachuteWest" createVehicle getPos _parafrag1;
~0.25
_parafrag2 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute2 = "ParachuteWest" createVehicle getPos _parafrag2;
~0.25
_parafrag3 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute3 = "ParachuteWest" createVehicle getPos _parafrag3;
~0.25
_parafrag4 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute4 = "ParachuteWest" createVehicle getPos _parafrag4;
~0.25
_parafrag5 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute5 = "ParachuteWest" createVehicle getPos _parafrag5;
~0.25
_parafrag6 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute6 = "ParachuteWest" createVehicle getPos _parafrag6;
~0.25
_parafrag7 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute7 = "ParachuteWest" createVehicle getPos _parafrag7;
~0.25
_parafrag8 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute8 = "ParachuteWest" createVehicle getPos _parafrag8;
~0.25
_parafrag9 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute9 = "ParachuteWest" createVehicle getPos _parafrag9;
~0.25
_parafrag10 = "Sh_120_HE" Createvehicle getPos _vehicle;
_fragchute10 = "ParachuteWest" createVehicle getPos _parafrag10;
~0.5
hint "RTB for more Frags"
rearm = true
_allunits = list _trig;
_EHList = [];
{_EH = _x addeventhandler ["killed", { _victim = _this select 0; _killer = _this select 1; if (_victim == _killer) then {player addrating 1000}}]; _EHList = _EhList + [_EH]} forEach _allUnits;
#loop
?! alive _parafrag10: goto "end1"
_parafrag setVelocity [(velocity _parafrag select 0) / 1.1, (velocity _parafrag select 1) / 1.1, -9] 
_fragchute setPos getPos _parafrag
_parafrag SetVectorUp (vectorUp _fragchute0)
_parafrag1 setVelocity [(velocity _parafrag1 select 0) / 1.1, (velocity _parafrag1 select 1) / 1.1, -9] 
_fragchute1 setPos getPos _parafrag1
_parafrag1 SetVectorUp (vectorUp _fragchute1)
_parafrag2 setVelocity [(velocity _parafrag2 select 0) / 1.1, (velocity _parafrag2 select 1) / 1.1, -9] 
_fragchute2 setPos getPos _parafrag2
_parafrag2 SetVectorUp (vectorUp _fragchute2)
_parafrag3 setVelocity [(velocity _parafrag3 select 0) / 1.1, (velocity _parafrag3 select 1) / 1.1, -9] 
_fragchute3 setPos getPos _parafrag3
_parafrag3 SetVectorUp (vectorUp _fragchute3)
_parafrag4 setVelocity [(velocity _parafrag4 select 0) / 1.1, (velocity _parafrag4 select 1) / 1.1, -9] 
_fragchute4 setPos getPos _parafrag4
_parafrag4 SetVectorUp (vectorUp _fragchute4)
_parafrag5 setVelocity [(velocity _parafrag5 select 0) / 1.1, (velocity _parafrag5 select 1) / 1.1, -9] 
_fragchute5 setPos getPos _parafrag5
_parafrag5 SetVectorUp (vectorUp _fragchute5)
_parafrag6 setVelocity [(velocity _parafrag6 select 0) / 1.1, (velocity _parafrag6 select 1) / 1.1, -9] 
_fragchute6 setPos getPos _parafrag6
_parafrag6 SetVectorUp (vectorUp _fragchute6)
_parafrag7 setVelocity [(velocity _parafrag7 select 0) / 1.1, (velocity _parafrag7 select 1) / 1.1, -9] 
_fragchute7 setPos getPos _parafrag7
_parafrag7 SetVectorUp (vectorUp _fragchute7)
_parafrag8 setVelocity [(velocity _parafrag8 select 0) / 1.1, (velocity _parafrag8 select 1) / 1.1, -9] 
_fragchute8 setPos getPos _parafrag8
_parafrag8 SetVectorUp (vectorUp _fragchute8)
_parafrag9 setVelocity [(velocity _parafrag9 select 0) / 1.1, (velocity _parafrag9 select 1) / 1.1, -9] 
_fragchute9 setPos getPos _parafrag9
_parafrag9 SetVectorUp (vectorUp _fragchute9)
_parafrag10 setVelocity [(velocity _parafrag10 select 0) / 1.1, (velocity _parafrag10 select 1) / 1.1, -9] 
_fragchute10 setPos getPos _parafrag10
_parafrag10 SetVectorUp (vectorUp _fragchute10)
goto "loop"
#end1
~10
_i= count (_allunits);
_j = 0;
?{_i < _j}: goto "next"
#next
private ["_unitList", "_unit", "_handler"];
_unitList = _allUnits;
_unit = _unitList select _j;
_handler = _EHList select _j;
_unit removeEventHandler ["killed", _handler];
_j = _j + 1;
~ 0.02
exit
#end
hint "to low"
exit

I salute you both thanx again
Odin
« Last Edit: 27 Sep 2008, 23:43:30 by Odin »