Announcement

Collapse
No announcement yet.

Possible to have a coop server auto restart when 'end' has been won?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    Yes I probably will use arrays whenever possible.

    PrimalLove, I may be missing it but how does the server know when you've input a command? That's the thing I need to find out mostly.

    Also what does #24 mean?
    Code:
    void (entity client, string s1, string s2, string s3) sprint3 = #24;

    -r0t.uk- cOOp - Mapvote - r0t.uk:26001
    -r0t.uk- DM - Mapvote - r0t.uk:26000

    Comment


    • #32
      Originally posted by slackhead View Post
      Yes I probably will use arrays whenever possible.

      PrimalLove, I may be missing it but how does the server know when you've input a command? That's the thing I need to find out mostly.

      Also what does #24 mean?
      Code:
      void (entity client, string s1, string s2, string s3) sprint3 = #24;

      The #24 is a reference to let this function know to use the builtin function sprint which uses #24 to point this function to that builtin. Check defs.qc for examples of these.

      Comment


      • #33
        Thanks. I'm guessing the builtins are native then?

        -r0t.uk- cOOp - Mapvote - r0t.uk:26001
        -r0t.uk- DM - Mapvote - r0t.uk:26000

        Comment


        • #34
          They are built into the engine code. Yes.

          Comment


          • #35
            Originally posted by slackhead View Post

            PrimalLove, I may be missing it but how does the server know when you've input a command? That's the thing I need to find out mostly.
            I missed this one. What do you mean by this?

            stuffcmd is used when you want to send a command to a client on the server.

            syntax: stuffcmd (entity client, string text);

            localcmd is when you want to issue the command to the server (locally)

            syntax: localcmd (string text);

            We needed to use localcmd because we are changing cvars on the server side. Maybe I am confused to what you are asking?

            Comment


            • #36
              Where in qc does the server read commands that have been input by the client? Or is it just a case of checking cvars in the main loop? If so, which part of client.qc would that be?

              Would this be in PlayerPostThink()?

              -r0t.uk- cOOp - Mapvote - r0t.uk:26001
              -r0t.uk- DM - Mapvote - r0t.uk:26000

              Comment


              • #37
                Oh ok. Well first we needed this:


                Code:
                void () vote_command =
                {
                	local float command;
                	command = cvar("cmd1");
                	cvar_set("cmd1", "0");
                        if (command)
                	console_command(command); [COLOR="Lime"]//This is new addition[/COLOR]
                };
                This sits in Startframe in world.qc. This gets run all the time on the server. Remember we need this to run server side not on the client so PlayerPostthink wouldn't apply. This currently checks for whether cmd1 is used. If so it resets it to 0 so that it can be used again. The beauty of this is that you can use this for multiple functions. Now in this code:

                Code:
                void () map_set_aliases =
                {	
                	local float temp;
                    local string maptemp;
                    temp = 150;
                    while (temp < 200)
                    {
                        maptemp = strings_get_mapname(temp - 150);
                        if (maptemp != "")
                        {
                            localcmd3("alias ", maptemp, " \"cmd1 ");
                            maptemp = ftos(temp);
                            localcmd2(maptemp, ";wait\"\n");
                        }
                        temp = temp + 1;
                    }
                };
                This code uses cmd1 as a way to set aliases. using numbers. So temp starts out at 150, 150 is subtracted from it, it looks for that result (0) and prints that result (start) in localcmd3 after alias and then asets the alias to cmd1 and in this case 150. Also 150 being used here for temp is arbitrary. Technically you could use a much lower number to start. Basically up to this point you haven't used any commands so it could even be temp =1; and just go up from there. This is what the cmd will look like that is sent to the server to run:

                Code:
                alias start "cmd1 150;wait"
                So it just created an alias for cmd1 150 = start.

                Now we have to setup a check for these new commands when the player uses the alias. Something like this:

                Code:
                //This is to add some extra strings to sprint and it uses the same builtin function for sprint
                void (entity client, string s1, string s2, string s3) sprint3 = #24;
                
                //This checks for each new alias created when used and interprets it and if they are greater than 
                //or equal to 150 and less than or = to 199 then run a console_mapcheck.
                //This would also go in world.qc StartFrame ()
                void (float command) console_command =
                {
                
                  if (command >= 150 && command <= 199)
                     console_mapcheck(command - 150);
                  
                };
                
                //This just has to be defined before world.qc or in it. 
                //This will take the command number and apply it to the next map by it's number 
                // I think :/ Theory :( 
                void (float newmap) console_mapcheck =
                {
                        strings_get_mapname(newmap);
                
                };

                I haven't tested any of this code. :/ But it seems possible. I'll have to actually get home and try writing this out fully with some voting code. But see what you can do with it. This should atleast give you something you can do with the cmds that are created now. This is a bit convoluted but it essential says when I type start, it = start. :/ But by doing that you should in theory be able to use your old voting code you have now to apply this to it. Because now you can tie into this rather than just assigning alias_make command. The above makes the aliases for you.
                Last edited by PrimalLove; 09-11-2014, 01:29 PM.

                Comment


                • #38
                  Basically think of cmd1 that we created as being a new impulse command. Instead of using impulse, we are literally using a newly created temporary quasi "impulse" to assign all the new maps to. That make more sense? That gives us no real limitations because we do not need to use impulse but we still need to check for it's use and remember to reset it after every frame kind of like what we do with impulse =0; check. Hope this kinda makes sense. :/

                  Comment


                  • #39
                    I just thought I'd run a test:

                    In world.qc
                    Code:
                    void() vote_command =
                    {
                        local float command;
                        command = cvar("cmd1");
                        cvar_set("cmd1", "0");
                    
                        if (command)
                            bprint("TEST\n");
                    };
                    and in StartFrame:
                    vote_command();

                    But server logs: "var_Set: variable cmd1 not found"

                    How do I initialise a cvar?

                    -r0t.uk- cOOp - Mapvote - r0t.uk:26001
                    -r0t.uk- DM - Mapvote - r0t.uk:26000

                    Comment


                    • #40
                      OOps! Two ways to do this. One is to use a default.cfg and place it in and quake.rc or set it up in your code to run a specific .cfg or run a localcmd when server initializes in with this in it:

                      Code:
                      set cmd1 "0"

                      Also to simplify all this you could just simply use the temp1 instead of cmd1. I forgot temp1 is already defined by the engine by default for mods. So if you aren't already using that you can simply change it to temp1 and you will not get this error and will not need to set it using the above method.

                      Also if you are using DP as your server you can simply use

                      Code:
                      float autocvar_cmd1;
                      This is a nice extension in DP so that if it detects you use cvar_set command it will automatically register it without needing to set it before server starts. So sorry about that. I wasn't thinking clearly at the time.

                      So in conclusion you can simply use temp1 instead of my made up cmd1. Or if you decide to use cmd1 you'll need to either have it "set cmd1 0" in a default.cfg or have it run that command in localcmd when the server first starts. Default.cfg is your better option because it happens before the server starts.

                      Hope this makes sense. Either way now you shouldn't get the error.
                      Last edited by PrimalLove; 09-11-2014, 02:46 PM.

                      Comment


                      • #41
                        Ok that fixed the error, but doing 'cmd 10' or 'set cmd1 10' in console doesn't seem to affect it.

                        Thanks for all your help, by the way

                        -r0t.uk- cOOp - Mapvote - r0t.uk:26001
                        -r0t.uk- DM - Mapvote - r0t.uk:26000

                        Comment


                        • #42
                          Not sure what you mean by doesn't affect it but remember that the additional commands will get created along with the aliases just like a regular impulse command is created. So:

                          Code:
                          void () vote_command =
                          {
                          	local float command;
                          	command = cvar("cmd1");
                          	cvar_set("cmd1", "0");
                          	if (command)
                          	console_command(command);
                          };
                          This creates the command and checks for commands being used and if it detects a command it runs console_command. Then:

                          Code:
                          [COLOR="Lime"]//This is where you'll be defining what the console commands actually do when a specific number is used with cmd1 or temp1 or whatever. :) [/COLOR]
                          void (float command) console_command =
                          {
                          
                            if (command >= 150 && command <= 199) [COLOR="Lime"]//If the commands are between these numbers then run console_mapcheck[/COLOR]
                               console_mapcheck(command - 150);
                           else
                                  cprint("unknown command\n"); [COLOR="Lime"]// if anything else it is an unknown command so echo this in the console[/COLOR]
                          
                          };
                          cprint is a custom function that you'll need to define only if you want to simplify using localcmd multiple times. It looks like this:

                          Code:
                          void (string s1) cprint =
                          {
                              localcmd("echo ");
                              localcmd(s1);  
                          };
                          Now the way the code works if you type anything other than cmd1 between 150 and 200 then its not a recognized command so it echos that to the console. This is basically how you would need to use it. In the console_command function you could also define any other useful "impulse" like commands for your mod and it will use the same check as the rest of them and you'll need to set an alias for it somewhere as well.

                          Did this answer your question?
                          Last edited by PrimalLove; 09-11-2014, 04:11 PM.

                          Comment


                          • #43
                            If I just type 'cmd1 155' in the console, wouldn't it work that way?

                            I also tried putting an alias in autoexec.cfg:

                            alias start "cmd1 155; wait"

                            But all I get back either way is 'Unknown command cmd1'

                            All I'm doing at the moment is trying out the complete basic code needed to get a response on the server, rather than add all the functions/arrays etc etc.

                            -r0t.uk- cOOp - Mapvote - r0t.uk:26001
                            -r0t.uk- DM - Mapvote - r0t.uk:26000

                            Comment


                            • #44
                              Originally posted by slackhead View Post
                              If I just type 'cmd1 155' in the console, wouldn't it work that way? //What do you mean by this?

                              I also tried putting an alias in autoexec.cfg:

                              alias start "cmd1 155; wait"

                              But all I get back either way is 'Unknown command cmd1'

                              All I'm doing at the moment is trying out the complete basic code needed to get a response on the server, rather than add all the functions/arrays etc etc.
                              Putting it in your autoexec.cfg will not work. Why? Because the command doesn't get created until the worldspawn is initiated. Autoexec.cfg gets executed before that so there is literally no command yet made. Once the server initiates the command is created and it begins looking for commands. Also, why do you want to put that in autoexec.cfg anyway?? Once the server is up you can then set an alias that way. You have to remember here that this is a temporary command. The command has to be initiated when the server starts. The only other way to set up a permanent cvar is to go to the engine code in pr_edict.qc I believe. Otherwise, the way we are doing it the extra command only exist when the server is active.

                              Also this code below is what will be setting up the aliases for you automatically when the server is running assuming this is the method you are using:


                              Code:
                              void () map_set_aliases =
                              {	
                              	local float temp;
                                  local string maptemp;
                                  temp = 150;
                                  while (temp < 200)
                                  {
                                      maptemp = strings_get_mapname(temp - 150);
                                      if (maptemp != "")
                                      {
                                          localcmd3("alias ", maptemp, " \"cmd1 ");
                                          maptemp = ftos(temp);
                                          localcmd2(maptemp, ";wait\"\n");
                                      }
                                      temp = temp + 1;
                                  }
                              };
                              So you'll have no need to set up aliases in your autoexec.cfg. Once the full code is implemented. But once the server is up fully you can just type out an alias to test the cmd1 150 command.
                              Last edited by PrimalLove; 09-11-2014, 04:38 PM.

                              Comment


                              • #45
                                If I just type 'cmd1 155' in the console, wouldn't it work that way? //What do you mean by this?
                                Can we run these cmd1 commands in the console and get the same behaviour? If not I will add the code to set them up.

                                -r0t.uk- cOOp - Mapvote - r0t.uk:26001
                                -r0t.uk- DM - Mapvote - r0t.uk:26000

                                Comment

                                Working...
                                X