| Mirage Source http://www.miragesource.net/forums/ |
|
| [General] Adding new /commands http://www.miragesource.net/forums/viewtopic.php?f=183&t=4353 |
Page 1 of 74 |
| Author: | Jacob [ Thu Sep 18, 2008 5:52 pm ] |
| Post subject: | [General] Adding new /commands |
MS4 v3.51 Adding new /commands like /kill or /mute have changed. They are now structured like the packet system. Reference: http://web.miragesource.com/forums/viewtopic.php?f=120&t=4331#p52200 HandleKeyPresses Find Code: If Left$(MyText, 1) = "/" Then Command = Split(MyText, " ") It will first get the text that you have typed in and will split it wherever a space is. Example: You type in "/info Admin". The split function will then create the following array. Command(0) = "/info" Command(1) = "Admin" So now we have to select what the command was and do something with it. After Code: Select Case Command(0) You'll have all the select statements. Example Code: Case "/info" ' Checks to make sure we have more than one string in the array If UBound(Command) >= 1 Then Call SendData(CPlayerInfoRequest & SEP_CHAR & Command(1) & END_CHAR) End If As you can see we have to add Code: If UBound(Command) >= 1 Then This will be our error checking, since we know that we have to have the "/Command' and an additional piece of info, we have to make sure our array contains the right amount of elements. If you know you need 4 pieces of info for your command you would have to do something like Code: If UBound(Command) >= 5 Then 1 for your command and 4 additional pieces of info. Then you can access the strings in your command with Code: Command(NumberYouNeed) Little thing on Val() to convert to a numerical value. It would be better to use the correct conversion. For example if you know your string needs to be a long then you would do: Code: CLng(Command(1)) Clng() - Converts to a long CInt() - Converts to an integer Cbyte() - Converts to a byte Now before we convert we want to make sure we have a valid number first. A good check would be Code: If IsNumeric(Command(1)) Then SendSetAccess Command(2), CLng(Command(1)) End If MAKE SURE TO CHECK ISNUMERIC BEFORE CONVERTING OTHERWISE YOU WILL GET ERRORS IF SOMEONE TYPES IN ANYTHING BESIDES A NUMBER. I think that's it. If I'm missing something or didn't explain things well please let me know. |
|
| Author: | Nean [ Thu Sep 18, 2008 6:26 pm ] |
| Post subject: | Re: Adding new /commands |
Wow. Now things are complicated again. It's gonna take some time to get used to this again. |
|
| Author: | Jacob [ Thu Sep 18, 2008 6:31 pm ] |
| Post subject: | Re: Adding new /commands |
It's a lot easier this way. You don't have to do letter counting or anything. Let's say you have your "/mute player" command. So you add Code: Case "/mute" If UBound(Command) >= 1 Then sendMutePlayer MyIndex, CLng(Command(1)) End If Code: If UBound(Command) >= 1 Then That makes sure you have the command and the player to mute. Code: sendMutePlayer MyIndex, CLng(Command(1)) Psuedo code - dunno what your function is And that's it to add the /command. |
|
| Author: | Doomy [ Thu Sep 18, 2008 6:48 pm ] |
| Post subject: | Re: Adding new /commands |
so all you do is really replace sendMutePlayer MyIndex, CLng(Command(1)) correct? |
|
| Author: | Nean [ Thu Sep 18, 2008 6:50 pm ] |
| Post subject: | Re: Adding new /commands |
doomteam1 wrote: so all you do is really replace sendMutePlayer MyIndex, CLng(Command(1)) correct? And add in the Code: If UBound(Command) >= 1 Then
|
|
| Author: | Doomy [ Thu Sep 18, 2008 6:53 pm ] |
| Post subject: | Re: Adding new /commands |
Code: sendMutePlayer MyIndex, CLng(Command(1)) The one is saying what word it is correct? after 0 right like sendMuteplayer blah(command(1) sendMuteServer blah(command(2) or what? cause i dont get the number |
|
| Author: | GIAKEN [ Thu Sep 18, 2008 7:17 pm ] |
| Post subject: | Re: Adding new /commands |
This makes things a lot better. However, all command handling should be in the server. You could send a packet like: Code: packet = "commands" & SEP_CHAR & Command(0) If UBound(Command) > 0 Then packet = packet & SEP_CHAR & UBound(Command(0)) For i = 1 To UBound(Command) packet = packet & SEP_CHAR & Command(i) Next i Else packet = packet & SEP_CHAR & 0 End If packet = packet & END_CHAR Server would do: Code: Select Case Parse$(1) If Val(Parse$(2)) = 0 Then Case "/help" 'seperate the commands that are only single End If If Val(Parse$(2)) = 1 Then 'seperate the commands that have a second parameter Case "/mute" End If End Select Something like that...thoughts? |
|
| Author: | Robin [ Thu Sep 18, 2008 9:33 pm ] |
| Post subject: | Re: Adding new /commands |
GIAKEN wrote: This makes things a lot better. However, all command handling should be in the server. You could send a packet like: Code: packet = "commands" & SEP_CHAR & Command(0) If UBound(Command) > 0 Then packet = packet & SEP_CHAR & UBound(Command(0)) For i = 1 To UBound(Command) packet = packet & SEP_CHAR & Command(i) Next i Else packet = packet & SEP_CHAR & 0 End If packet = packet & END_CHAR Server would do: Code: Select Case Parse$(1) If Val(Parse$(2)) = 0 Then Case "/help" 'seperate the commands that are only single End If If Val(Parse$(2)) = 1 Then 'seperate the commands that have a second parameter Case "/mute" End If End Select Something like that...thoughts? I could go for a banana right now. |
|
| Author: | GIAKEN [ Thu Sep 18, 2008 11:20 pm ] |
| Post subject: | Re: Adding new /commands |
Robin wrote: GIAKEN wrote: This makes things a lot better. However, all command handling should be in the server. You could send a packet like: Code: packet = "commands" & SEP_CHAR & Command(0) If UBound(Command) > 0 Then packet = packet & SEP_CHAR & UBound(Command(0)) For i = 1 To UBound(Command) packet = packet & SEP_CHAR & Command(i) Next i Else packet = packet & SEP_CHAR & 0 End If packet = packet & END_CHAR Server would do: Code: Select Case Parse$(1) If Val(Parse$(2)) = 0 Then Case "/help" 'seperate the commands that are only single End If If Val(Parse$(2)) = 1 Then 'seperate the commands that have a second parameter Case "/mute" End If End Select Something like that...thoughts? I could go for a banana right now. Tarantulas lay their eggs in bananas. |
|
| Author: | Jacob [ Fri Sep 19, 2008 12:35 pm ] |
| Post subject: | Re: Adding new /commands |
Personally I would leave them client side. If you do the proper checks server side it wouldn't matter what they have access to on the client. |
|
| Author: | Jacob [ Tue Sep 23, 2008 1:50 pm ] |
| Post subject: | Re: [General] Adding new /commands |
Added a little bit about checking IsNumeric before using the conversion. This will protect you against RTEs. |
|
| Author: | wanai [ Sun Dec 26, 2021 1:57 pm ] |
| Post subject: | Re: [General] Adding new /commands |
Vrin |
|
| Author: | wanai [ Sun Dec 26, 2021 1:58 pm ] |
| Post subject: | Re: [General] Adding new /commands |
37.6 |
|
| Author: | wanai [ Sun Dec 26, 2021 2:00 pm ] |
| Post subject: | Re: [General] Adding new /commands |
Bett |
|
| Author: | wanai [ Sun Dec 26, 2021 2:01 pm ] |
| Post subject: | Re: [General] Adding new /commands |
Bett |
|
| Author: | wanai [ Sun Dec 26, 2021 2:02 pm ] |
| Post subject: | Re: [General] Adding new /commands |
Rael |
|
| Author: | wanai [ Sun Dec 26, 2021 2:03 pm ] |
| Post subject: | Re: [General] Adding new /commands |
Colu |
|
| Author: | wanai [ Sun Dec 26, 2021 2:04 pm ] |
| Post subject: | Re: [General] Adding new /commands |
Bana |
|
| Author: | wanai [ Sun Dec 26, 2021 2:05 pm ] |
| Post subject: | Re: [General] Adding new /commands |
Henr |
|
| Author: | wanai [ Sun Dec 26, 2021 2:06 pm ] |
| Post subject: | Re: [General] Adding new /commands |
BNIA |
|
| Author: | wanai [ Sun Dec 26, 2021 2:07 pm ] |
| Post subject: | Re: [General] Adding new /commands |
Medi |
|
| Author: | wanai [ Sun Dec 26, 2021 2:09 pm ] |
| Post subject: | Re: [General] Adding new /commands |
Brot |
|
| Author: | wanai [ Sun Dec 26, 2021 2:10 pm ] |
| Post subject: | Re: [General] Adding new /commands |
Orie |
|
| Author: | wanai [ Sun Dec 26, 2021 2:11 pm ] |
| Post subject: | Re: [General] Adding new /commands |
Enns |
|
| Page 1 of 74 | All times are UTC |
| Powered by phpBB® Forum Software © phpBB Group https://www.phpbb.com/ |
|