Page 1 of 1

Making a teleport in Carentan

Posted: May 25th, 2010, 7:41 pm
by xeno
Hey, I am trying to make a teleporter in carentan. I tried using the distance command to check for the players origin and if they are within like 5 feet and press f they will be teleported but for some reason it doesn't work. Maybe I got the coordinates wrong... but dunno. I used the command /viewpos while in call of duty to get the coordinates of where my players was standing.

Here is my code:

Code: Select all

s_tele3()//teleporter in carentan
{	
	self endon("boot");

	setcvar("s_tele3", "");
	while(1)
	{
		if(getcvar("s_tele3") != "")
		{
			players = getentarray("player", "classname");
			for(i = 0; i < players.size; i++)
			{
					if (getcvar("mapname") == "mp_carentan")
					{
						iprintln("Map is Carentan");//Check 1
						players[i].useheld = .2;
						if(((distance(players[i].origin,(247, 1111, 68))) < 25))
						{
							iprintlnBold("Check Origin");//Check 2
							if(players[i] useButtonPressed() == true)
           						{
								iprintlnBold("Check Use Key");//Check 3
								if (players[i].useheld == 0.2)
								{
									iprintlnBold("Check Use Key Held");//Check 4
									players[i] setorigin((366, 1254, 684));
									iprintlnBold("Teleported and Check Complete");//Check 5
								}
							}
						}

					}
					else
					{
						iprintlnBold("Wrong map");
					}

			}
			setcvar("s_tele3", "");
		}
		wait 0.05;
	}
}

Re: Making a teleport in Carentan

Posted: May 26th, 2010, 12:47 am
by Drofder2004
Firstly:

instead of looping an if check, you can simply do:

Code: Select all

while(1)
{
   setCvar("s_tele3", "");
   while(getCvar("s_tele3") == "")
      wait 0.5;

   <start code here>
}
Secondly, you are running one loops trying to detect multiple players...
Get your player list and thread them each into a new function.
The new function will contain the code to check for use being pressed.

How far did your "checks" get to?

Re: Making a teleport in Carentan

Posted: May 26th, 2010, 4:06 am
by megazor
a few notes.
getcvar("mapname") == "mp_carentan"
it wouldn't work if the mapname was mp_CaReNtaN xD use function toLower(sText)

make the code short. if (player useButtonPressed() == true) is the same as if (player useButtonPressed())


call iPrintLnBold() on the player in order not to get confused if there are many players.

Get your player list and thread them each into a new function


why use many functions if it is possible to use only one?

Re: Making a teleport in Carentan

Posted: May 26th, 2010, 5:53 am
by xeno
Drofder2004 wrote: How far did your "checks" get to?
It got through the first Check. haha

Code: Select all

iprintln("Map is Carentan");//Check 1
And I couldn't get toLower to work =/ so now I feel stupid.

Re: Making a teleport in Carentan

Posted: May 26th, 2010, 6:31 am
by Nightmare

Code: Select all

s_tele3()//teleporter in carentan
{   
	self endon("boot");
	if (getcvar("mapname") == "mp_carentan")
	{
		iprintln("Map is Carentan");//Check 1
		while(1)
		{
			players = getentarray("player", "classname");
			for(i = 0; i < players.size; i++)
				players[i] thread teleChecker();
			wait 0.05;
		}
	}
}

teleChecker()
{
	iprintlnBold("Check Origin");//Check 2
	if(distance(self.origin,(247, 1111, 68)) < 25)
	{
		iprintlnBold("You did it.");//Check 4
		self setorigin((366, 1254, 684));	
		iprintlnBold("Teleported and Check Complete");//Check 5
	}
}

Re: Making a teleport in Carentan

Posted: May 26th, 2010, 6:50 am
by xeno
Works. <3

Re: Making a teleport in Carentan

Posted: May 27th, 2010, 9:17 pm
by Drofder2004
Nightmare wrote:

Code: Select all

s_tele3()//teleporter in carentan
{   
	self endon("boot");
	if (getcvar("mapname") == "mp_carentan")
	{
		iprintln("Map is Carentan");//Check 1
		while(1)
		{
			players = getentarray("player", "classname");
			for(i = 0; i < players.size; i++)
				players[i] thread teleChecker();
			wait 0.05;
		}
	}
}

teleChecker()
{
	iprintlnBold("Check Origin");//Check 2
	if(distance(self.origin,(247, 1111, 68)) < 25)
	{
		iprintlnBold("You did it.");//Check 4
		self setorigin((366, 1254, 684));	
		iprintlnBold("Teleported and Check Complete");//Check 5
	}
}
All it needs (if wanted) is the UseButton thing, but otherwise, nicely done!