When dedicated 2 mod isn't working

Have a question about modding, modelling or skinning? Have a tutorial to post? Post here!

Moderator: Core Staff

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

When dedicated 2 mod isn't working

Post by Moustache » May 2nd, 2010, 3:09 pm

When I run the mod at home with dedicated 0 the mod works great. But when I place it on an external server then the mod fails.
I found out that when I run the mod at home with dedicated 2 (dedicated to internet) that the mod fails.

How is that possible?

I will give a few examples.

With dedicated 0 this scipt would say M40A3 BUG if you have m40a3 but not the sniper class.
But with dedicated 2 this script always say m40a3 bug of r700 bug no matter wich class you got.

Code: Select all

setcheck()
{
	self endon( "disconnect" );
	for(;;)
	{
		self waittill("spawned_player");
		if( (self HasWeapon("m40a3_mp")) && (getDvar("loadout_class") != "sniper") )
		{
			self IPrintLnBold( "M40A3 ^1BUG" );
		}

		if( (self HasWeapon("remington700_mp")) && (getDvar("loadout_class") != "sniper") )
		{
			self IPrintLnBold( "R700 ^1BUG" );
		}
	}
}
With dedicated 0 this scipt would give me an extra weapon (r700 or m40a3 with the same camo as the weapon that you choose).
But with dedicated 2 this script doesn't do anything :?

Code: Select all

setweapons()
{
	self endon( "disconnect" );
	for(;;)
		{
		self waittill("spawned_player");

		if( ( getDvar("loadout_camo") == "camo_none") && (self HasWeapon("m40a3_mp")) )
		{
			self giveWeapon("remington700_mp");
		}

		if( ( getDvar("loadout_camo") == "camo_none") && (self HasWeapon("remington700_mp")) )
		{
			self giveWeapon("m40a3_mp");
		}

		if( ( getDvar("loadout_camo") == "camo_brockhaurd") && (self HasWeapon("m40a3_mp")) )
		{
			self giveWeapon("remington700_mp", 1);
		}

		if( ( getDvar("loadout_camo") == "camo_brockhaurd") && (self HasWeapon("remington700_mp")) )
		{
			self giveWeapon("m40a3_mp", 1);
		}

		if( ( getDvar("loadout_camo") == "camo_bushdweller") && (self HasWeapon("m40a3_mp")) )
		{
			self giveWeapon("remington700_mp", 2);
		}

		if( ( getDvar("loadout_camo") == "camo_bushdweller") && (self HasWeapon("remington700_mp")) )
		{
			self giveWeapon("m40a3_mp", 2);
		}

		if( ( getDvar("loadout_camo") == "camo_blackwhitemarpat") && (self HasWeapon("m40a3_mp")) )
		{
			self giveWeapon("remington700_mp", 3);
		}

		if( ( getDvar("loadout_camo") == "camo_blackwhitemarpat") && (self HasWeapon("remington700_mp")) )
		{
			self giveWeapon("m40a3_mp", 3);
		}

		if( ( getDvar("loadout_camo") == "camo_tigerred") && (self HasWeapon("m40a3_mp")) )
		{
			self giveWeapon("remington700_mp", 4);
		}

		if( ( getDvar("loadout_camo") == "camo_tigerred") && (self HasWeapon("remington700_mp")) )
		{
			self giveWeapon("m40a3_mp", 4);
		}

		if( ( getDvar("loadout_camo") == "camo_stagger") && (self HasWeapon("m40a3_mp")) )
		{
			self giveWeapon("remington700_mp", 5);
		}

		if( ( getDvar("loadout_camo") == "camo_stagger") && (self HasWeapon("remington700_mp")) )
		{
			self giveWeapon("m40a3_mp", 5);
		}

		self giveMaxammo("m40a3_mp");
		self giveMaxammo("remington700_mp");
	}
}

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: When dedicated 2 mod isn't working

Post by Drofder2004 » May 2nd, 2010, 6:50 pm

Your code needs major revision.

Just to take a small example (I have made the code easier to udnerstand by using an extra IF)

Code: Select all

	if((getDvar("loadout_camo") == "camo_none")   //1
	{
		if(self HasWeapon("m40a3_mp"))   //2
			self giveWeapon("remington700_mp");
        	
		if(self HasWeapon("remington700_mp"))   //3
			self giveWeapon("m40a3_mp");
	}
Ok, at '//1', lets presume this is TRUE.
We now check stage '//2'. Lets also say this is now TRUE.
The player now has a remington700.
We then proceed to stage '//3', which has been automatically set to TRUE by stage '//2'.

So even though he has BOTH guns, we are now going to give him the same gun again.

Next:

Code: Select all

self giveWeapon("remington700_mp", 4);
giveWeapon is a SINGLE argument function, the extra argument you have added will cause an error.

Code: Select all

giveWeapon(<weapon>)
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: When dedicated 2 mod isn't working

Post by Moustache » May 3rd, 2010, 3:55 pm

Drofder2004 wrote:Your code needs major revision.

Just to take a small example (I have made the code easier to udnerstand by using an extra IF)

Code: Select all

	if((getDvar("loadout_camo") == "camo_none")   //1
	{
		if(self HasWeapon("m40a3_mp"))   //2
			self giveWeapon("remington700_mp");
        	
		if(self HasWeapon("remington700_mp"))   //3
			self giveWeapon("m40a3_mp");
	}
Ok, at '//1', lets presume this is TRUE.
We now check stage '//2'. Lets also say this is now TRUE.
The player now has a remington700.
We then proceed to stage '//3', which has been automatically set to TRUE by stage '//2'.

So even though he has BOTH guns, we are now going to give him the same gun again.
I understand that. But I thought never mind it because it works on dedicated 0.
Before I tried it with if and elseif but I failed. I now tried it again, and failed.

The code:

Code: Select all

setweapons()
{
	self endon( "disconnect" );
	for(;;)
	{
		self waittill("spawned_player");

		if( ( getDvar("loadout_camo") == "camo_none") && (self HasWeapon("m40a3_mp")) )
		{
			self giveWeapon("remington700_mp");
		}
		Elseif( ( getDvar("loadout_camo") == "camo_none") && (self HasWeapon("remington700_mp")) )
		{
			self giveWeapon("m40a3_mp");
		}

	      self giveMaxammo("m40a3_mp");
	      self giveMaxammo("remington700_mp");
	}
}
The error:
Error:
******* script compile error *******
Error: bad syntax: (file 'promod_ruleset/double.gsc', line 13)
{
*
************************************
Drofder2004 wrote:Next:

Code: Select all

self giveWeapon("remington700_mp", 4);
giveWeapon is a SINGLE argument function, the extra argument you have added will cause an error.

Code: Select all

giveWeapon(<weapon>)
Yeahhh I can learn you something :D ;)
The extra argument is the camoflage on the weapon.
4 gives you the Red Tiger camo and 5 gives you the Blue Tiger camo. This goes from 1 to 6. Where 6 is the gold one but you can only use that for weapons that can be gold plated (ak47, mini-uzi, etc)

User avatar
Opel
CJ Fan
CJ Fan
Posts: 188
Joined: September 15th, 2008, 12:28 pm
Location: Scotland

Re: When dedicated 2 mod isn't working

Post by Opel » May 3rd, 2010, 4:51 pm

Put a space between else and if

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: When dedicated 2 mod isn't working

Post by Moustache » May 3rd, 2010, 5:30 pm

liam wrote:Put a space between else and if
True :)

But the script still isn't working. I do not get anny error. But the just doesn't do anything.

The script (only changed the else if):

Code: Select all

setweapons()
{
   self endon( "disconnect" );
   for(;;)
   {
      self waittill("spawned_player");

      if( ( getDvar("loadout_camo") == "camo_none") && (self HasWeapon("m40a3_mp")) )
      {
         self giveWeapon("remington700_mp");
      }
      else if( ( getDvar("loadout_camo") == "camo_none") && (self HasWeapon("remington700_mp")) )
      {
         self giveWeapon("m40a3_mp");
      }

         self giveMaxammo("m40a3_mp");
         self giveMaxammo("remington700_mp");
   }
}

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: When dedicated 2 mod isn't working

Post by Drofder2004 » May 4th, 2010, 12:12 pm

I seriously am not understanding the point of this "hasweapon"?

Why are we checking if he has the weapon in the first place?
If the player has no weapons, do we plan on giving him any?

Tell me your intentions because the code is technically correct.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: When dedicated 2 mod isn't working

Post by Moustache » May 4th, 2010, 4:56 pm

Drofder2004 wrote:I seriously am not understanding the point of this "hasweapon"?

Why are we checking if he has the weapon in the first place?
If the player has no weapons, do we plan on giving him any?

Tell me your intentions because the code is technically correct.
If he has the m40a3 and you do not check it he has 2 m40a3's and 1 r700. That was my thought.

But even if I use the script like this it isn't working. On dedi 0 it works like a charm (you get the m40a3 and r700, just like you said :)) But on dedi 2 it fails :?
Script:

Code: Select all

setweapons()
{
   self endon( "disconnect" );
   for(;;)
   {
      self waittill("spawned_player");

      if( ( getDvar("loadout_camo") == "camo_none") )
      {
         self giveWeapon("remington700_mp");
         self giveWeapon("m40a3_mp");
      }

         self giveMaxammo("m40a3_mp");
         self giveMaxammo("remington700_mp");
   }
}

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: When dedicated 2 mod isn't working

Post by Drofder2004 » May 4th, 2010, 6:25 pm

If you intention is to simply give them the two weapon everytime, why not just do:

self takeallweapons();
self giveWeapon(<weapon);
etc
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: When dedicated 2 mod isn't working

Post by Moustache » May 5th, 2010, 5:50 pm

Drofder2004 wrote:If you intention is to simply give them the two weapon everytime, why not just do:

self takeallweapons();
self giveWeapon(<weapon);
etc
I know that command. It fails on dedi 2 but works on dedi 0.
I already tried that like this:

Code: Select all

setweapons()
{							
	self endon( "disconnect" );				
	for(;;)
	{
		self waittill("spawned_player");			

		if( ( getDvar("loadout_camo") == "camo_none") )
		{
		self takeAllWeapons();
		self giveWeapon("m40a3_mp");
		self giveWeapon("remington700_mp");

		self giveMaxammo("m40a3_mp");
		self giveMaxammo("remington700_mp");
		wait 0.1;
		self SwitchToWeapon("m40a3_mp");
		}
	}
}

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: When dedicated 2 mod isn't working

Post by Drofder2004 » May 5th, 2010, 7:20 pm

Sorry ,just realsied one fatal flaw on why this is not working ona dedi...

You cannot use getDvar to detect a clients dvar. The reason this works on Listen servers, is because the DVAR you are getting is BOTH your dvar and the servers.

The only method of doing this is menus and menuresponses.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: When dedicated 2 mod isn't working

Post by Moustache » May 6th, 2010, 4:23 pm

Drofder2004 wrote:Sorry ,just realsied one fatal flaw on why this is not working ona dedi...

You cannot use getDvar to detect a clients dvar. The reason this works on Listen servers, is because the DVAR you are getting is BOTH your dvar and the servers.

The only method of doing this is menus and menuresponses.
K, thanxs for the info :)

I googled menuresponse cod but I only get tutorials and exampels about menus. Can you tell me how it works with menus and menuresponses?

And about the getDvar.
Isn't that possible with something like this:

Code: Select all

if( ( self getDvar("loadout_camo") == "camo_none") )

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: When dedicated 2 mod isn't working

Post by Drofder2004 » May 6th, 2010, 8:42 pm

No, getDvar will basically get the server dvars only.

Menuresponse is a simple solution to a common problem.
Menus are the only real way a players actions can be detected.


All menus are governed by a menuresponse system. Using a script to wait for menuresponses, you can hook into the code.

So, in the CJ mod for example, if I type in console:

/openscriptmenu cj suicide

The mod will detect the menu that I have chosen (cj) and the response I wish to send (suicide), and with code I can now do the appropriate action.

You can do a similar system using a menu and some variables.
Using a menu and response system, create a variable (i.e player.camo) and when the palyer clicks the menu button (or sends the correct command), the variable changes.

You can now, instead of using getDvar, can simply use a comparison to check the variable.

Check _menus.gsc [Line 95 onwards] for an example of using a menu response system and check _quickcommands.menu for a example menu.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: When dedicated 2 mod isn't working

Post by Moustache » May 7th, 2010, 6:42 pm

I understand what you say.

But I really do not have a clue how to create that into a script.

Code: Select all

setweapons()
{
	self endon("disconnect");
	
	for(;;)
	{
		self waittill("menuresponse", menu, response);
		
		if(response == "open_changeclass_menu" )
		{
			if( getDvar("loadout_camo") == "camo_none")
				self giveWeapon("m40a3_mp");
				self giveWeapon("remington700_mp");

				self giveMaxammo("m40a3_mp");
				self giveMaxammo("remington700_mp");
		}
	}
}
If I use it like this it doesn't work.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: When dedicated 2 mod isn't working

Post by Drofder2004 » May 7th, 2010, 7:20 pm

No, you cannot use getDvar at all. You need to ignore that function when thinking about clients.

Code: Select all

setweapons()
{
   self endon("disconnect");
   
   for(;;)
   {
      self waittill("menuresponse", menu, response);
      
      if(menu != "m_weapon")
         continue;

      switch(response)
      {
         case "camo_none":
            self.camo = 0;
            break;
         case "camo_something":
            self.camo = 1;
            break;
      }

      self giveWeapon("m40a3_mp", self.camo);
      self giveWeapon("remington700_mp", self.camo);

      self giveMaxammo("m40a3_mp");
      self giveMaxammo("remington700_mp");
   }
}
After reading some code, it turns out you can use an extra argument in giveweapon to define the camo, it is just not listed in the script index.

To explain the above code:
Whena scriptmenuresponse is sent by a player, the script shall detect it. The script will check to see the menu. If the menu doesn't equal "m_weapon", the code should simply continue to the end of the loop ignoring other statements.
If the menu is correct, the switch statement will determine which camo is being asked for using the "response" as the key.
The switch statement should then define a variable on the player, and then the giveWeapon will simply give the weapon with the desired camo.

To test this code (if no errors occur) you can simply type in console:
/openscriptmenu m_weapon camo_something
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: When dedicated 2 mod isn't working

Post by Moustache » May 7th, 2010, 8:14 pm

Thanxs, again :)

When I changed this

Code: Select all

if(menu != "m_weapon")
Into this

Code: Select all

if(menu == "m_weapon")
It woks, but only if I place this command: /openscriptmenu m_weapon camo_none (or /openscriptmenu m_weapon camo_something)
in the console.
Not when I choose a camo in to the menu. Or when I changed class or something. Only with that command.

Is it possible that the menu checks wich camo you have clicked? Then I think it is possible to link

Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests