![]() |
[General] Adding new /commands - Printable Version +- Mirage Source (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: Source Code Development (https://mirage-engine.uk/forums/forumdisplay.php?fid=51) +----- Forum: Mirage Source 4 (Visual Basic 6) (https://mirage-engine.uk/forums/forumdisplay.php?fid=44) +------ Forum: Tutorials (https://mirage-engine.uk/forums/forumdisplay.php?fid=13) +------ Thread: [General] Adding new /commands (/showthread.php?tid=2116) |
[General] Adding new /commands - Jacob - 18-09-2008 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 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) Example Code: Case "/info" As you can see we have to add Code: If UBound(Command) >= 1 Then 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 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 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. Re: Adding new /commands - Nean - 18-09-2008 Wow. Now things are complicated again. It's gonna take some time to get used to this again. Re: Adding new /commands - Jacob - 18-09-2008 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" Code: If UBound(Command) >= 1 Then Code: sendMutePlayer MyIndex, CLng(Command(1)) And that's it to add the /command. Re: Adding new /commands - Doomy - 18-09-2008 so all you do is really replace sendMutePlayer MyIndex, CLng(Command(1)) correct? Re: Adding new /commands - Nean - 18-09-2008 doomteam1 Wrote:so And add in the Code: If UBound(Command) >= 1 Then Re: Adding new /commands - Doomy - 18-09-2008 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 Re: Adding new /commands - GIAKEN - 18-09-2008 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) Server would do: Code: Select Case Parse$(1) Something like that...thoughts? Re: Adding new /commands - Robin - 18-09-2008 GIAKEN Wrote:This makes things a lot better. I could go for a banana right now. Re: Adding new /commands - GIAKEN - 18-09-2008 Robin Wrote:GIAKEN Wrote:This makes things a lot better. Tarantulas lay their eggs in bananas. Re: Adding new /commands - Jacob - 19-09-2008 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. Re: [General] Adding new /commands - Jacob - 23-09-2008 Added a little bit about checking IsNumeric before using the conversion. This will protect you against RTEs. |