ryansoper 10 Posted September 23, 2013 Hi guys, This has probably been asked before, but I have searched and cannot find anything which clears it up for me. I understand that 'player' is null on multiplayer games at init stage, but I do not understand what I need to use instead, for instance, if I want to addAction on a player that has tripped one of my triggers, how would I select the player who has walked into the trigger? Thanks, Ryan Share this post Link to post Share on other sites
galzohar 31 Posted September 23, 2013 (edited) waitUntil {!(isNull player)}; Run this before you use any code that requires the player. Some commands (for example anything related to equipment add/remove) may also require you to add sleep 0.01; afterwards in order to work correctly. Make sure you don't run it on the dedicated server, as it will make your server scripts get stuck (since player will always be null there, and you will not see it when you test on a local hosted server). Selecting a unit that walked into the trigger is completely different. Remember player points at the player unit of the machine that is running the script (and thus has a different value for each computer that will run it). A unit that enters a trigger is the same unit on all machines (although don't trust it, because in some rare cases desync might show different units in trigger list on different machines at the same time). Basically you need to think about what you actually want to do, think about how it can break due to different computers seeing different things and running their own scripts, and make sure you don't allow those situations to happen. For your example, what you probably want to do is add the action to all players during init, and in the condition place player in list actionTrigger, where actionTrigger is the name of the trigger in the editor (and of course set the trigger activation condition to include the player. For example if the player is bluefor then activated by bluefor or activated by any will work). You don't need anything in the "on activation" and "on deactivation" fields for your purpose, since the action is already added. Edited September 23, 2013 by galzohar Share this post Link to post Share on other sites
ryansoper 10 Posted September 23, 2013 waitUntil {!(isNull player)}; Run this before you use any code that requires the player. Some commands (for example anything related to equipment add/remove) may also require you to add sleep 0.01; afterwards in order to work correctly. Make sure you don't run it on the dedicated server, as it will make your server scripts get stuck (since player will always be null there, and you will not see it when you test on a local hosted server). Selecting a unit that walked into the trigger is completely different. Remember player points at the player unit of the machine that is running the script (and thus has a different value for each computer that will run it). A unit that enters a trigger is the same unit on all machines (although don't trust it, because in some rare cases desync might show different units in trigger list on different machines at the same time). Basically you need to think about what you actually want to do, think about how it can break due to different computers seeing different things and running their own scripts, and make sure you don't allow those situations to happen. For your example, what you probably want to do is add the action to all players during init, and in the condition place player in list actionTrigger, where actionTrigger is the name of the trigger in the editor (and of course set the trigger activation condition to include the player. For example if the player is bluefor then activated by bluefor or activated by any will work). You don't need anything in the "on activation" and "on deactivation" fields for your purpose, since the action is already added. That is very helpful thank you. How could I achieve similar results on a dedicated server then? What would you use instead of player? Share this post Link to post Share on other sites
Tajin 349 Posted September 23, 2013 (edited) Even on a dedicated server you have players. It really depends on where the script is running. Triggers exist on all machines, so it will work but that specific trigger will only trigger on the machine where the triggering player is local. Therefor you'll have to make sure that whatever effects the trigger has are also distributed to the other clients. Same goes for actions. MP locality can be quite a bitch. ;) If you want to have the script running on the server only, you'll need to identiy your players either by giving naming their units or by going through the list of "playableUnits". Edited September 23, 2013 by Tajin Share this post Link to post Share on other sites
galzohar 31 Posted September 23, 2013 For the server there is no player and thus nobody that needs to have the action added to them. Just add the action to those who aren't a dedicated server (use if (!isDedicated) then {...} for the condition before waiting until the player isn't null and then add the action). Basically scripts that only need to deal with the specific player that you are currently playing, you run them only on clients and not on the server. Scripts that need to deal with everyone need to either run only on the server or run on all machines, depending on what you want them to do, and of course not use the player variable as that only points at 1 specific unit that is different on each machine. Share this post Link to post Share on other sites