Sciirof 6 Posted December 27, 2016 Hey folks, so I am working on a gamemode but when you get killed I want the player's cash to be reset but I can't get this to work. I have the feeling I have made a big misstake somewhere (still learning). Script: //Reset cash when you respawn if (!isDedicated)then{ _killed=(_this select 0); _killed addEventHandler ["MPKilled", { _killed= (_this select 0); if (player == _killed)then{ cash=100; any = [ [ ["Died!","align = 'center' size = '0.7' font='PuristaBold'","#FF0000"], ["","<br/>"], [str (date select 3) + ":" + str (date select 4),"align = 'center' size = '0.7'"] //Show date when died ] ] spawn BIS_fnc_typeText2; (uiNameSpace getVariable "myUI_DollarTitle") ctrlSetText format ["$%1",cash]; _killed removeAllEventHandlers "MPKilled"; }; }]; }; Thanks! - Sciirof Share this post Link to post Share on other sites
davidoss 551 Posted December 27, 2016 addEventHandler ["MPKilled" --> addMPEventHandler ["MPKilled" _killed removeAllEventHandlers "MPKilled"; --> _killed removeAllMPEventHandlers "MPKilled"; I am not sure if you should add it globally maybe just "killed" is enough as you handle local stuff inside Share this post Link to post Share on other sites
Sciirof 6 Posted December 27, 2016 Just now, davidoss said: addEventHandler ["MPKilled" --> addMPEventHandler ["MPKilled" I am not sure if you should add it globally maybe just "killed" is enough as you handle local stuff inside Thanks for responding. So what I did this time I did this: resetCash.sqf //Reset cash when you respawn if (!isDedicated)then{ _killed=(_this select 0); _killed addEventHandler ["Killed", { _killed= (_this select 0); if (player == _killed)then{ cash=100; any = [ [ ["Died!","align = 'center' size = '0.7' font='PuristaBold'","#FF0000"], ["","<br/>"], [str (date select 3) + ":" + str (date select 4),"align = 'center' size = '0.7'"] //Show date when died ] ] spawn BIS_fnc_typeText2; (uiNameSpace getVariable "myUI_DollarTitle") ctrlSetText format ["$%1",cash]; _killed removeAllEventHandlers "Killed"; }; }]; }; and in the unit's init: null = [this] execVM "resetCash.sqf" I get no errors but the cash doesn't reset also I have tried it with addMPEventHandler and still no luck Share this post Link to post Share on other sites
davidoss 551 Posted December 27, 2016 Well, i assume you have defined a cash variable which is for display text only in your example? Do you need to store the value somewhere? null = this execVM "resetCash.sqf"; if (local _this)then{ _this addEventHandler ["Killed", { profileNameSpace setVariable ["cash",100]; saveProfileNamespace; any = [ [ ["Died!","align = 'center' size = '0.7' font='PuristaBold'","#FF0000"], ["","<br/>"], [str (date select 3) + ":" + str (date select 4),"align = 'center' size = '0.7'"] //Show date when died ] ] spawn BIS_fnc_typeText2; (uiNameSpace getVariable "myUI_DollarTitle") ctrlSetText format ["$%1",100]; }]; }; Share this post Link to post Share on other sites
Sciirof 6 Posted December 27, 2016 12 minutes ago, davidoss said: Well, i assume you have defined a cash variable which is for display text only in your example? Do you need to store the value somewhere? null = this execVM "resetCash.sqf"; if (local _this)then{ _this addEventHandler ["Killed", { profileNameSpace setVariable ["cash",100]; saveProfileNamespace; any = [ [ ["Died!","align = 'center' size = '0.7' font='PuristaBold'","#FF0000"], ["","<br/>"], [str (date select 3) + ":" + str (date select 4),"align = 'center' size = '0.7'"] //Show date when died ] ] spawn BIS_fnc_typeText2; (uiNameSpace getVariable "myUI_DollarTitle") ctrlSetText format ["$%1",100]; }]; }; Thanks! The script works just fine for now. As you asked: Yes I am going to make it store the value in a database. Share this post Link to post Share on other sites