Afgan0r 0 Posted October 17, 2019 Hi, i want to if player killed another player of his side, he got a screamer. I use onPlayerKilled.sqf, here a code. _killed = _this select 1; _killer = _this select 2; try { if (!(_killed isEqualTo _killer) && (side _killed == side _killer) && (isPlayer(_killer))) then { _rnd_number = round(random 6); if (_rnd_number==0) then { _rnd_number = 1; }; playSound format["screamer_sound%1",_rnd_number]; 1200 cutRsc [format["Screamer%1",_rnd_number],"BLACK",4]; sleep 4; 1200 cutFadeOut 0; }; } catch { if (["undefined variable", _exception, false] call BIS_fnc_inString) then { }; }; So problem is how to play sound and show screamer for killer player? Share this post Link to post Share on other sites
Smart Games 76 Posted October 17, 2019 (edited) You could use setvariable/getvariable. init.sqf: player setvariable [“tkill“,“false“]; [] execVm “tkcheck.sqf“; onplayerkilled.sqf: _killer = _this select 2; _killer setvariable [“tkill“,“true“]; tkcheck.sqf: while {true} do { _sleep 0.05; _state = player getvariable “tkill“; if (_state == “true“) do { player setvariable [“tkill“,“false“]; //call here the scream(code) }; }; Edited October 18, 2019 by Smart Games Share this post Link to post Share on other sites
killzone_kid 1333 Posted October 18, 2019 try in sqf does not do what you think 1 Share this post Link to post Share on other sites
Afgan0r 0 Posted October 18, 2019 On 10/18/2019 at 1:58 AM, killzone_kid said: try in sqf does not do what you think I use this for situation when you kill yourself with respawn or grenade or something else. In this situation _killer is not defined so i get exception and i can't check it with isNil because variable have number type and isNil don't work with numbers (isNull don't work too). I think, using the solution above I will be able to not use try/catch. Share this post Link to post Share on other sites
Smart Games 76 Posted October 18, 2019 I am not sure, but do you really need try/catch? Share this post Link to post Share on other sites
killzone_kid 1333 Posted October 18, 2019 On 10/18/2019 at 2:16 AM, Afgan0r said: and isNil don't work with numbers How did you come to this wrongful conclusion? Share this post Link to post Share on other sites
Afgan0r 0 Posted October 18, 2019 On 10/18/2019 at 9:02 AM, killzone_kid said: How did you come to this wrongful conclusion? Because exception says that type is number, but expected string or something like this Share this post Link to post Share on other sites
Dedmen 2725 Posted October 18, 2019 On 10/18/2019 at 2:16 AM, Afgan0r said: In this situation _killer is not defined so i get exception As he said, it doesn't do what you think. try/catch doesn't catch script exceptions. We have a wiki page telling you everything about it https://community.bistudio.com/wiki/try On 10/18/2019 at 2:16 AM, Afgan0r said: i can't check it with isNil because variable have number type and isNil don't work with numbers (isNull don't work too). That's wrong, again there is a wiki page https://community.bistudio.com/wiki/isNil https://community.bistudio.com/wiki/isNull On 10/18/2019 at 9:12 AM, Afgan0r said: Because exception says that type is number, but expected string or something like this The wiki page also tells you why that happens. On 10/17/2019 at 11:02 AM, Afgan0r said: So problem is how to play sound and show screamer for killer player? The answer is remoteExec, and here again, we have a wiki page https://community.bistudio.com/wiki/remoteExec Just remotely execute the playSound and cutRsc and cutFadeOut on the _killer. Might be better to just remoteExec "call" or "spawn" and pass a script to it instead. Share this post Link to post Share on other sites
killzone_kid 1333 Posted October 18, 2019 On 10/18/2019 at 9:12 AM, Afgan0r said: Because exception says that type is number, but expected string or something like this It is not exception, we don’t have exceptions, it is script error resulting from attempt to pass wrong argument type. If you want to check variable you can do it in 2 ways: isNil "_killer” or isNil { _killer } both described on the wiki Share this post Link to post Share on other sites
killzone_kid 1333 Posted October 18, 2019 On 10/18/2019 at 9:14 AM, Dedmen said: Might be better to just remoteExec "call" or "spawn" and pass a script to it instead. For testing the concept, sure, but is bad idea to use in production scripts. Raw call and spawn should be blacklisted in CfgRemoteExec Share this post Link to post Share on other sites
Dedmen 2725 Posted October 18, 2019 On 10/18/2019 at 9:34 AM, killzone_kid said: For testing the concept, sure, but is bad idea to use in production scripts. Raw call and spawn should be blacklisted in CfgRemoteExec Yeah I'm going after the users apparent SQF scripting skill. In the order - remoteExec seperate commands - remoteExec a piece of code via call - remoteExec a proper CfgFunctions function I'm thinking the last one would be too much effort to explain now. https://community.bistudio.com/wiki/CfgFunctions Share this post Link to post Share on other sites
Afgan0r 0 Posted October 18, 2019 On 10/17/2019 at 5:18 PM, Smart Games said: You could use setvariable/getvariable. init.sqf: player setvariable [“tkill“,“false“]; [] execVm “tkcheck.sqf“; onplayerkilled.sqf: _killer = _this select 2; _killer setvariable [“tkill“,“true“]; tkcheck.sqf: while {true} do { _sleep 0.05; _state = player getvariable “tkill“; if (_state == “true“) do { player setvariable [“tkill“,“false“]; //call here the scream(code) }; }; I tried this solution and got an error in onPlayerKilled.sqf here: _killer setVariable ["tkill","true"]; Error is: Error setvariable: Type Number, expected Namespace,Object,Group,Display (dialog),Control,Team member,Task,Location. Share this post Link to post Share on other sites
killzone_kid 1333 Posted October 18, 2019 That’s right, you can’t set variable on number. Better question is why do you want _killer to be a number instead of an object? Share this post Link to post Share on other sites