terrence 10 Posted November 26, 2013 Hello, Last night I thought I got my MPKilled script to work on my TvT server, but the more I looked at the script the more I thought this wont work for JIP. :confused: I searched for over an hour on the fourms and google but couldnt find a answer. This is My Init.sqf if (isServer) then { { _x addMPEventHandler ["MPKilled", {_this call ADDXP_Function}]; } forEach allUnits; }; ADDXP_Function = { if (isServer) then { _victim = _this select 0; _killer = _this select 1; if (_victim != _killer) then { _tempxp = _killer getVariable ["playerxp", 0]; _killer setVariable ["playerxp", (_tempxp) + 5, true]; }; }; }; The way I understand it is with this script the server is going to only assign eventhandlers to the players that are in the match at the beginning. Im still pretty new to scripting for mp missions so if somebody doesn't mind just letting me know if im right or wrong about this issue. Thanks! ---------- Post added at 01:28 ---------- Previous post was at 23:58 ---------- Well its confirmed it doesnt assign to players who JIP. Does anybody know how I would have the server assign a MPKILLED EH to a JIP player? ---------- Post added at 02:28 ---------- Previous post was at 01:28 ---------- The only thing I can think of now is write a script for the server that checks to see if any new players have joined and if so remove all players EH and reassign them? ---------- Post added at 04:14 ---------- Previous post was at 02:28 ---------- Will do some testing after work this is the simple script I came up with while {isServer} do { sleep 30; { _x removeAllMPEventHandlers "MPKILLED"; } forEach allUnits; { _x addMPEventHandler ["MPKilled", {_this call ADDXP_Function}]; } forEach allUnits; }; I know this is probably a terrible way to do it but its all I can think of. Share this post Link to post Share on other sites
mariodu62 5 Posted November 26, 2013 Maybe easiest to use bis_fnc_MP Share this post Link to post Share on other sites
terrence 10 Posted November 26, 2013 Thanks man that makes more sense ill play around with it when i get off work tonight Sent from my HTL21 using Tapatalk 2 Share this post Link to post Share on other sites
giallustio 770 Posted November 26, 2013 You could just use the killed eh... Share this post Link to post Share on other sites
Heinrich Kramer 172 Posted November 26, 2013 how about a trigger with the condition "local player" and then change the script to: player addMPEventHandler ["MPKilled", {_this call ADDXP_Function}]; the trigger will fire local to every client on connect (be it on mission start or JIP). Share this post Link to post Share on other sites
saetheer 9 Posted November 26, 2013 Terrence, did you solve JIP? All my attempts ends up with running around in boxer-shorts. Share this post Link to post Share on other sites
Gudsawn 93 Posted November 26, 2013 (edited) Instead of doing this: if (isServer) then { { _x addMPEventHandler ["MPKilled", {_this call ADDXP_Function}]; } forEach allUnits; }; Which, as you know, only adds the EH to all units that are present at the beginning of the mission, Try this: if !(isDedicated) then { // Waits until player variable exists (JIP) waitUntil {!isNull player}; waitUntil {player == player}; player addMPEventHandler ["MPKilled", {_this call ADDXP_Function}]; }; This will add the event handler to the player upon joining/rejoining the server. Edited November 26, 2013 by GDSN Share this post Link to post Share on other sites
terrence 10 Posted November 26, 2013 Thanks for the suggestions guys. Correct me if I'm wrong here but I thought it was best for the server to assign the mp event handlers to each player. Due to the fact that if each player assigns his own event handler when it's fired all clients including the server exec the code, so if you have 4 clients connected and the dedicated server the code would be exec 5x. I haven't been able to test this extensively due to my work schedule. But with my limited testing I noticed I revived double the "Xp" points when it was just me on a dedicated server with an AI. When I used the client to assign the variables. Guessing because my client would exec the code and so would the server. I'll do some more research tomorrow, but for now I'm headed to bed. again thanks for the suggestions:) Share this post Link to post Share on other sites
Gudsawn 93 Posted November 26, 2013 Just noticed you're using the "MPKilled" event handler - this is what's causing the EH to fire on all clients including the server. Instead, use player addEventHandler ["Killed", {_this call ADDXP_Function}];. Your ADDXP_Function should also only be run on the client. Then, when you need to update certain variables (e.g. a killer's XP) across all clients, use publicVariable. Share this post Link to post Share on other sites
Larrow 2822 Posted November 26, 2013 (edited) Can you not just get each client to add its own MPKilled event handler. So according to the wiki this will make the events function run on all machine when the client is killed, Triggered when the unit is killed. EH can be added on any machine and EH code will trigger globally on every connected client and server. but if the function has a if (isserver) then { .... then the function is only going to run on the server no matter that it is called everywhere. ?? init.sqf //Must be a client if (!(isDedicated) then { //waituntil client player exists waitUntil { !(isNull player) }; //Add event to fire on all machines player addMPEventHandler ["MPKilled", {_this call ADDXP_Function}]; }; ADDXP_Function = { //Will only run on server if (isServer) then { _victim = _this select 0; _killer = _this select 1; if (_victim != _killer) then { _tempxp = _killer getVariable ["playerxp", 0]; _killer setVariable ["playerxp", (_tempxp) + 5, true]; }; }; }; _____________ After refreshing the page lol, as GDSN says in his first post but just make sure the function runs on the server only, if you only want it to do the xp calculations there Edited November 26, 2013 by Larrow Share this post Link to post Share on other sites
terrence 10 Posted November 27, 2013 Yea it looks like im just going to use the killed eh as Giallustio and GDSN suggested. Larrow I had isServer in my function but I was still getting double points when testing on a dedicated server which confused the crap out of me lol. Thanks for all the help! Share this post Link to post Share on other sites