by Nyove » 5 July 2020, 16:44
TLDR: The key to make command system work in multiplayer is by utilising the trigger action:
Set value of variable 'A' to slot index of player who says text
For the others who are interested in how to set up a command system.
Step-by-step
Step 1. Run a timer (with delay=0) that executes a trigger, let's call it trigger 'A'.
Trigger A
Trigger action 1: Set value of variable 'A' to slot of current player
Param A: ~currentPlayer
Param B: N/A
(Slot number of current player will be stored in variable 'A'. This will be used later.)
Trigger action 2: Set trigger 'A' as player chat message receiver.
Param A: #ChatReceiverTrigger (just another trigger)
Param B: N/A
(Setting up a dedicated trigger to handle commands. Whenever someone types in chat, #ChatReceiverTrigger will be able to receive it.)
Chat receiver trigger
- Infinity calls, Enabled.
Trigger action 1: Set string-value of variable 'A' to text being said.
Param A: ~command
Param B: N/A
(This will capture whatever text has been typed in the chat and store it in variable 'A')
Trigger action 2: Continue trigger execution only if variable 'A' equals value 'B'
Param A: ~command
Param B: -help (whatever command you want to create)
(Checking if the text being said = to the command you set.)
#Below two trigger actions are neccesary for MP, they can be excluded in SP. The effect of the command will only apply to the person who says text.
Trigger action 3: Set value of variable 'A' to slot index of player who says text
Param A: ~playerWhoSaidTheText
Param B: N/A
(Sets the slot of the player who typed the command into variable 'A')
Trigger action 4: Continue trigger execution only if variable 'A' equals variable 'B'
Param A: ~currentPlayer
Param B: ~playerWhoSaidTheText
(This will check if the person who said the command is the current player himself.)
... Perform your trigger actions based on your command from here. (like printing out text for -help command, killing player 1 for -killGod, etc...)
Good luck.
Note: If you want your command system to perform different task based on their slot number
(like teleport player 1 if slot number is 0, teleport player 2 if slot number is 1, etc...), it gets more complicated.
TLDR for ^ is to execute a chain of triggers after the 1st 4 trigger actions, with each trigger having 'Continue if..' trigger action. (Every trigger checks for every slot number)
Proud to be part of something meaningful.
Need any assistance? Join the PB2 discord server at https://discord.com/invite/Bhe9rNz or raise a support ticket at https://www.plazmaburst2.com/support
Contact me on discord for quickest reply possible.