raedor 8 Posted October 19, 2004 try<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?!(_unit == player): exitor, even better:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? _unit != player: exit Share this post Link to post Share on other sites
MrZig 0 Posted October 19, 2004 Eh? If I'm gettng this right, which I probably aint, you're using <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_this select 0 in your exec part. Isn't that the person who is killed? Try <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_this select 1 And in your script, put <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> _unit = _this select 0 _points = _this select 1 ? (_unit != aP) : exit hint "player's score adjusted" scoreadjust = scoreadjust + _points exit Share this post Link to post Share on other sites
theavonlady 2 Posted October 19, 2004 or, even better:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? _unit != player: exit This works: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_unit = _this select 0 _points = _this select 1 hint format ["Name of killer is: %1", (_unit)] ? _unit != player: exit scoreadjust = scoreadjust + _points exit The hint command reveals that _unit is indeed set to something crazy like: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">WEST Charlie Green:1 (Jane Doe) Share this post Link to post Share on other sites
theavonlady 2 Posted October 19, 2004 Eh?If I'm gettng this right, which I probably aint, you're using <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_this select 0 in your exec part. Isn't that the person who is killed? My mistake. I meant _this select 1 for ID'ing the killer. Anyway, script works now. Just have to tackle this player naming business, which should be simple. Share this post Link to post Share on other sites
raedor 8 Posted October 19, 2004 mrZig is right: _this select 0 is the guy who was killed. /edit: avon was too fast. Share this post Link to post Share on other sites
Zombie_Mod 0 Posted October 19, 2004 try<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">?!(_unit == player): exitor, even better:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? _unit != player: exitThe code above will work. Here's why the previous examples didn't work: _unit is an OBJECT reference, and you tried to compare the object to a string. The script parser can't cast a object reference type to a string type. However <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ? _unit == Player will work, as player is an object reference in itself. The two types are compatible and the compare will work. If you REALLY want to cast an object to a string, use: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ? format["%1", _unit] == "aP": goto "itmatches" Share this post Link to post Share on other sites
theavonlady 2 Posted October 19, 2004 I bet raedor is going to post that mrZig was right and that I'm too fast. And thanks Mr. Zombie. I got the idea now! Share this post Link to post Share on other sites
raedor 8 Posted October 19, 2004 but <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !_unit == Player won't work. and mrs avon does not want to compare _unit with a string. she wants to check if it is the same unit like the player... /edit: @avon: you placed your bet too late Share this post Link to post Share on other sites
Zombie_Mod 0 Posted October 19, 2004 but <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">? !_unit == Player won't work.and mrs avon does not want to compare _unit with a string. she wants to check if it is the same unit like the player...  /edit: @avon: you placed your bet too late   You sure? Cos Avon said this did work on the previous page... <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> ? _unit != player: exit /mutters to self never to bother interfering in scripting threads again Share this post Link to post Share on other sites
T J 0 Posted October 19, 2004 avon, you dont really need to name your player unit for SP missions, he's always "PLAYER" aP is just a tag that got used by early mission makers and it stuck....... sorry about forgetting the () You COULD get rid of that line by adding a condition to the eventhandler, to only run the sqs if the killer was the player, thats simple enough too. Share this post Link to post Share on other sites
theavonlady 2 Posted October 20, 2004 You COULD get rid of that line by adding a condition to the eventhandler, to only run the sqs if the killer was the player, thats simple enough too. Now he tells me! To summarize: I've chucked out a lot of code. All I need is a global variable, preset to zero in init.sqs: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">scoreadjust = 0 Then whenever I need to give a negative score, I just code on the trigger itself: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">scoreadjust = scoreadjust - 1000 Whenever I need to add a positive score, I simply use: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">player adRating 1000 This would include the addEventHandler, which now looks like this and will only adjust the score if the player killed the vehicle: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vehicle addEventHandler ["killed",{? _this select 1 == player:player addRating 1000}] And in my mission pre-end processing, I finalize the score with: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">player addRating scoreadjust Thank you all for your time. You may go home now. Share this post Link to post Share on other sites
MrZig 0 Posted October 20, 2004 That eventhandler won't work, you'll get an error. Use this, <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vehicle addEventHandler ["killed",{IF ((_this select 1) == player) THEN {player addRating 1000}}] And remember the _this select 1 !!! Share this post Link to post Share on other sites
theavonlady 2 Posted October 20, 2004 That eventhandler won't work, you'll get an error.Use this, <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vehicle addEventHandler ["killed",{IF ((_this select 1) == player) THEN {player addRating 1000}}] EDIT: Thanks. Will test. Quote[/b] ]And remember the _this select 1 !!! Share this post Link to post Share on other sites
theavonlady 2 Posted October 20, 2004 That eventhandler won't work, you'll get an error.Use this, <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_vehicle addEventHandler ["killed",{IF ((_this select 1) == player) THEN {player addRating 1000}}] EDIT: Thanks. Will test. Didn't work. That is, the script with the addEventHandler command ran without error messages but my score was not adjusted. Share this post Link to post Share on other sites
theavonlady 2 Posted October 20, 2004 Being that I'm piloting a plane, I also tried: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plane addEventHandler ["killed",{IF ((_this select 1) == vehicle player) THEN {player addRating 4000}}] but <span style='color:red'>vehicle player</span> didn't help either. Share this post Link to post Share on other sites
T J 0 Posted October 20, 2004 the killer is the player, (usually driver) always. Just to check for sure, you ARE putting the eventhandler in the INIT of the target units aren't you? Hint: you dont need to put it into each single target in a group, rather in just one INIT field enter your line..... and add <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE"> foreach units group this Share this post Link to post Share on other sites
raedor 8 Posted October 20, 2004 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x addEventHandler ["killed",{IF ((_this select 1) == vehicle player) THEN {player addRating 4000}}]} forEach units group thisshould work. or make a biig trigger activated by all (?) and wirte in the onAct line:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x addEventHandler ["killed",{IF ((_this select 1) == vehicle player) THEN {player addRating 4000}}]} forEach thislist Share this post Link to post Share on other sites
theavonlady 2 Posted October 20, 2004 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x addEventHandler ["killed",{IF ((_this select 1) == vehicle player) THEN {player addRating 4000}}]} forEach units group thisshould work. or make a biig trigger activated by all (?) and wirte in the onAct line:<table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">{_x addEventHandler ["killed",{IF ((_this select 1) == vehicle player) THEN {player addRating 4000}}]} forEach thislistNo go! Neither of these worked. Here's the script that issues that addEventHandler command: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_apos = [getmarkerpos "VplaneStart" select 0,getmarkerpos "VplaneStart" select 1,(getmarkerpos "VplaneStart" select 2) + 1500] _aSpd = 600 _aDir = 220 _aVel = [sin(_aDir)*_aSpd, cos(_aDir)*_aSpd,0] vpilot = [] "SoldierEPilot" createUnit [getmarkerpos "VplaneStart",groupAlpha,"vpilot=this",1] _plane = "Su27" createVehicle [0,0] _plane setPos _apos vpilot moveInDriver _plane _plane engineOn true _plane setSkill 1 _plane setDir _aDir _plane setVelocity _aVel while {(speed _plane)<_aSpd} do {_aVel=velocity _plane; _plane setVelocity [1.05*_aVel select 0, 1.05*_aVel select 1, 0]} _plane setBehaviour "Combat" _plane setCombatMode "RED" {_plane addEventHandler ["killed",{IF ((_this select 1) == player) THEN {player addRating 4000}}]} forEach thisList #target1 ? not (canMove h1) : goto "target2" _plane domove (getpos h1) _plane dotarget h1 _plane dofire h1 ~1 goto "target1" #target2 ? not (canMove h2) : goto "exit" _plane domove (getpos h2) _plane dotarget h2 _plane dofire h2 ~1 goto "target2" #exit exit I discussed this script here a few weeks ago. It spawns an enemy aircraft in flight. Life is never simple. UPDATE: Also tried specifying vehicle player instead of just player. No difference. Share this post Link to post Share on other sites
theavonlady 2 Posted October 21, 2004 /bump Stumped the stars? Share this post Link to post Share on other sites
korax 4 Posted October 21, 2004 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">... {_plane addEventHandler ["killed",{IF ((_this select 1) == player) THEN {player addRating 4000}}]} forEach thisList ... Whats the "forEach thisList" part for? That basically means "Exec this line of code once for every unit in this trigger list". But this is not a trigger and there is no list so that is useless. <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plane addEventHandler ["killed",{IF (vehicle (_this select 1) == vehicle player) THEN {player addRating 4000;Hint "Player rating adjusted"}}] This should work (Note the check to see if the vehicle of the killer is equal to the vehicle of the player) Edit: Added a hint in the EH so you can see if it really did adjust And if this doesnt work then I'm not sure whats going on, unless somehow you arent killing the plane afterall Share this post Link to post Share on other sites
theavonlady 2 Posted October 21, 2004 <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">...{_plane addEventHandler ["killed",{IF ((_this select 1) == player) THEN {player addRating 4000}}]} forEach thisList ... Whats the "forEach thisList" part for? Indeed, when specifying "forEach thisList" or "foreach units group this", things were extremly fickle. But I've discovered where the problem lies: the SFM SU27 addon. Backing up a bit: specifying "vehicle player" in the "IF" statement does the job. Here's my working addEventHanlder line: <table border="0" align="center" width="95%" cellpadding="0" cellspacing="0"><tr><td>Code Sample </td></tr><tr><td id="CODE">_plane addEventHandler ["killed",{hint format ["Name of killer is: %1", (_this select 1)];IF ((_this select 1) == vehicle player) THEN {player addRating 4000}}] When the script runs to create the SU27, sometimes the event handler doesn't trigger, even though the SU27 is shot to bits (thanks to FootMunch's F16 MIGCAP ). At other times, it tells me that the killer is something like "12bcc500H NOID, SFM_SU27", which is completely wacky, considering that I'm displaying the value of "_this select 1". When I change the script to vCreateVehicle a standard BIS SU25, it works perfectly. Now, I'm curious as to how an addon, no matter what code it contains, can mess up returned values from this "killed" addEventHandler command. The value of "_this select 1" should be totally in OFP's control. OFP bug? Evil Russian addon? Hmmm.......................... Share this post Link to post Share on other sites
theavonlady 2 Posted October 21, 2004 When the script runs to create the SU27, sometimes the event handler doesn't trigger, even though the SU27 is shot to bits (thanks to FootMunch's F16 MIGCAP ). At other times, it tells me that the killer is something like "12bcc500H NOID, SFM_SU27", which is completely wacky, considering that I'm displaying the value of "_this select 1". Argh! Same problem with FootMunch's SU-27 Flanker! Share this post Link to post Share on other sites
Footmunch 0 Posted October 21, 2004 It _could_ be a 'timing' issue. The init scripts on 3rd party planes usually take a few 'beats' to run, unlike the BIS planes. Maybe insert a half-second delay after creation before addeventhandler (or check on alive _plane)? Share this post Link to post Share on other sites
theavonlady 2 Posted October 21, 2004 It _could_ be a 'timing' issue. The init scripts on 3rd partyplanes usually take a few 'beats' to run, unlike the BIS planes. Maybe insert a half-second delay after creation before addeventhandler (or check on alive _plane)? I tried a 1 second delay. Same problem. Share this post Link to post Share on other sites
Footmunch 0 Posted October 21, 2004 It could also be a consequence of the proximity detonation scripting. In that case, a large 'target' box is created in the path of the missile: the missile hits it and explodes, hopefully catching the OPFOR plane in the blast. In that case, the firing-plane only 'kills' the proximity target, rather than the 'dead' plane itself. Does it happen when a particular weapon is used? If it's guns only (via removeweapon), there _shouldn't_ be a problem. I'm not sure if the SFM Flanker uses proximity detonation, but both the F-16 and Su-27 from me do. Share this post Link to post Share on other sites