#########################################################################################################################################
#FTL Drive(developed for Rise of Kobol mod)
#Authors: 	[RoK] Gaius Baltar
#	    	[RoK] [C22] Milton
#Version .2a	
#Description: Players can type "jump^x" where x is a distance,	
#	they will then jump x meters in the direction they are	
#	facing, alternatively they can say "blindjump" and they		
#	will jump to a random coordinate(along the same x,z plane).	
#	They can also say "jumphome" and they will jump back near			
#	an un-cappable base, owned by their team. Finally, if they have
#	a squad they can type JUMP^x to move their entire squad
#	along with them.			
#											
#Features:								
#	.2a:									
#		-Jump home									
#		-Blind jump									
#		-Co-ordinate jump								
#		-Cooldown(based on distance jumped for now)
#	.3a
#		-jump errors:
#			-chance of not jumping
#			-chance of normal jump going blind
#			-chance of blind jump going off map
#		-Only squad leaders can jump
#		-Rest of squad jumps with squad leader, exiting jump in a delta formation, if the squad leader uses JUMP
#		-need 2 squad members in order to jump
#		-Comrose fuctionality added in
#
#	Future plans
#		-jump jamming
#		-special jumps(blind and home) limited to raptors and heavy raiders(they have to be in game before I start this)
#
#	And if I ever get time, or the ability to go and research further in...
#		-jumps based on the squad leader map(like calling for supplies and such...) ##UPDATE## As of 1.21 this does not seem possible
#########################################################################################################################################

import bf2
import host
import math
import random
import sys
import bf2.Timer


#variable settings
WCMessage1 = "weapon change event"
WCMessage2 = "weapon change complete"
Diemessage1 = "Die......."
DieMessage2 = "Die Again"
DieMessage3 = "Die Complete"
DieMessage4 = "Die Try"
jumpfailchance = 3 # %chance that a jump fails
misjumpchance = 20 # %chance that a blind jump goes off the map
badjumpchance = 5 # %chance that a jump goes blind
speedmode = 0 # can people access speedmode(no cooldowns/warmups on jumps)?    !!!!!!!!!!!!!!!!  THIS SHOULD BE SET TO 0 IF YOU DO NOT WANT CHEATERS :) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
devmode = 0 #can people access devmode       !!!!!!!!!!!!!!!!!!!!!!!!!! Please, don't enable this, you don't need the devmode tools, it's just there for us...!!!!!!!!!!!!!!!!!!!!!!!!!!!!
SD = 30
DA = 2.36

#don't know if this is the best way, only way I know works
jumpRecent = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
speed = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
dev = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]


# Register game hooks
def init():
	host.registerHandler('PlayerSpawn', onPlayerSpawn)
	host.registerHandler('ChatMessage', onChatMessage, 1)
	host.registerHandler('RemoteCommand', onRemoteCommand, 1)
	#host.registerHandler('PlayerChangeWeapon', onPlayerChangeWeapon)

	
def onRemoteCommand(playerId, msgText):
	global msgTimer, jumpRecent, misjumpchance, badjumpchance, speedmode, jumpfailchance
	p = bf2.playerManager.getPlayerByIndex(playerId)
	p.hasASquad = 0
	if msgText.find("JUMP") <> -1:
		p.hasASquad = 1		
		if p.isSquadLeader() == 1:
			p.squadmembers = 0
			for sm in bf2.playerManager.getPlayers():
				if sm.getSquadId() == p.getSquadId() and p.getTeam() == sm.getTeam(): #checks to see if there's more than one person in a squad, doesn't need to check for squad 0 because no one can be the squad leader of squad 0
					p.squadmembers = p.squadmembers + 1
					host.rcon_invoke('game.sayAll "Found player '+sm.getName()+' in '+p.getName()+'\'s squad"')
			if p.squadmembers > 1:
				p.hasASquad = 1
				host.rcon_invoke('game.sayAll "Jump preparations underway"')
				p.jumpgonebad = 0
				p.newx = 0.0
				p.newy = 0.0
				p.newz = 0.0
				p.JumpInterval = 5
				p.jumpdist = 0
				myweapon = p.getPrimaryWeapon()
				myweaponType = myweapon.templateName
				myvehic = p.getVehicle()
				mypos = myvehic.getPosition()
				newpos = myvehic.getPosition()
				myrot = myvehic.getRotation()
				myyaw = myrot[0]
				mypitch = myrot[1]
				r = 1.0
#################################################################################################
#												NormalJumpSquad
#################################################################################################

				if msgText.find("^") <> -1:
					JMsplt = msgText.split("^")
					JDText = JMsplt[1]
					r = float(JDText)
					p.jumpdist = int(r)
					badjump = random.randint(1,100)
					if badjump < badjumpchance:
						p.jumpgonebad = 1
						host.rcon_invoke('game.sayAll "Ummmm... something\'s not right here..."')
				jumpfail = random.randint(1,100)
				if jumpfail < jumpfailchance:
					p.newx = mypos[0]
					p.newy = mypos[1]
					p.newz = mypos[2]
					host.rcon_invoke('game.sayAll "ERROR Jump failure imminent"')
					p.JumpInterval = 0
				else:
					mypitch = -1.0 * mypitch  #pitch is backwards
					mypitch = math.radians(mypitch)
					myyaw = math.radians(myyaw)
					dz = math.cos(myyaw) * math.cos(mypitch) * r
					dx = math.sin(myyaw) * math.cos(mypitch) * r
					dy = math.sin(mypitch) * r
					#assume good code to here
					host.rcon_invoke('game.sayAll "Jump co-ordinates recieved"')
					#newpos[1] = newpos[1] + 300.0
					#host.rcon_invoke('game.sayAll "' + str(myrot[0]) + '"')
					#host.rcon_invoke('game.sayAll "' + str(myrot[1]) + '"')
					p.newx = mypos[0] + dx
					p.newy = mypos[1] + dy
					p.newz = mypos[2] + dz
#################################################################################################

#################################################################################################
#					Jump CalculationsSquad
#################################################################################################
				#host.rcon_invoke("game.sayAll \"" + str(dx) + "\"")
				#host.rcon_invoke("game.sayAll \"" + str(dy) + "\"")
				#host.rcon_invoke("game.sayAll \"" + str(dz) + "\"")
				#host.rcon_invoke("game.sayAll \"" + str(myweaponType) + "\"")
				if jumpRecent[playerId] == 0:
					host.rcon_invoke('game.sayAll "Engines are at acceptable temperature levels"')
					JumpInterval = p.JumpInterval
					jumpRecent[p.index] = 1
					p.hasASquad = 1
					host.rcon_invoke('game.sayAll "FTL drive spinning up"')
					if speed[p.index] == 1:
						JumpInterval = 0
					p.timerID = bf2.Timer(onJumpTimer, JumpInterval, 1, p)  #Sending the x, y, z variables to onJumpTimer
				else:
					host.rcon_invoke('game.sayAll "'+p.getName()+', your FTL drive is not ready yet, need to wait for your engines to cool down!"')
				#myvehic.setPosition((newx, newy, newz))
				vehicname = p.myvehic.templateName
				#host.rcon_invoke("game.sayAll \"" + str(vehicname) + "\"")
			else:
				host.rcon_invoke('game.sayAll "Need more than one FTL computer to make proper calculations"')
		else:
			host.rcon_invoke('game.sayAll "Only squad leaders can begin FTL preparations"')
	if msgText.find("jump") <> -1:
		if p.isSquadLeader() == 1:
			host.rcon_invoke('game.sayAll "Jump preparations underway"')
			p.jumpgonebad = 0
			p.newx = 0.0
			p.newy = 0.0
			p.newz = 0.0
			p.JumpInterval = 5
			p.jumpdist = 0
			myweapon = p.getPrimaryWeapon()
			myweaponType = myweapon.templateName
			myvehic = p.getVehicle()
			mypos = myvehic.getPosition()
			newpos = myvehic.getPosition()
			myrot = myvehic.getRotation()
			myyaw = myrot[0]
			mypitch = myrot[1]
			r = 1.0
#################################################################################################
#												NormalJump
#################################################################################################

			if msgText.find("^") <> -1:
				JMsplt = msgText.split("^")
				JDText = JMsplt[1]
				r = float(JDText)
				p.jumpdist = int(r)
				badjump = random.randint(1,100)
				if badjump < badjumpchance:
					p.jumpgonebad = 1
					host.rcon_invoke('game.sayAll "Ummmm... something\'s not right here..."')
				jumpfail = random.randint(1,100)
				if jumpfail < jumpfailchance:
					p.newx = mypos[0]
					p.newy = mypos[1]
					p.newz = mypos[2]
					host.rcon_invoke('game.sayAll "ERROR Jump failure"')
					p.JumpInterval = 0
				else:
					mypitch = -1.0 * mypitch  #pitch is backwards
					mypitch = math.radians(mypitch)
					myyaw = math.radians(myyaw)
					dz = math.cos(myyaw) * math.cos(mypitch) * r
					dx = math.sin(myyaw) * math.cos(mypitch) * r
					dy = math.sin(mypitch) * r
					#assume good code to here
					host.rcon_invoke('game.sayAll "Jump co-ordinates recieved"')
					#newpos[1] = newpos[1] + 300.0
					#host.rcon_invoke('game.sayAll "' + str(myrot[0]) + '"')
					#host.rcon_invoke('game.sayAll "' + str(myrot[1]) + '"')
					p.newx = mypos[0] + dx
					p.newy = mypos[1] + dy
					p.newz = mypos[2] + dz
#################################################################################################

#################################################################################################
#					Jumphome
#################################################################################################


			if msgText.find("jumphome") <> -1:    
				host.rcon_invoke('game.sayAll "Roger that, lets get out of here!"')
				controlPoints = bf2.objectManager.getObjectsOfType('dice.hfe.world.ObjectTemplate.ControlPoint')
				for cp in controlPoints:
					if cp.cp_getParam('unableToChangeTeam') != 0 and cp.cp_getParam('team') == p.getTeam():
						homepos = cp.getPosition()
				p.newx = float(homepos[0])
				p.newy = float(homepos[1])
				p.newz = float(homepos[2])+100.0
				p.JumpInterval = 5
				p.jumpdist = int(math.sqrt( pow((mypos[0]-homepos[0]),2) + pow((mypos[1]-homepos[1]),2) + pow((mypos[2]-homepos[2]),2) ))
################################################################################################

#################################################################################################         
#					Blindjump
#################################################################################################
			if msgText.find("blindjump") <> -1 or p.jumpgonebad == 1:
				host.rcon_invoke('game.sayAll "Calculating random co-ordinates"')
				size = bf2.gameLogic.getWorldSize()
				p.jumpgonebad = 0
				misjump = random.randint(1,100)
				if misjump < misjumpchance:
					randx = random.randint(250,500)+size[0]/2
					randz = random.randint(250,500)+size[1]/2
					host.rcon_invoke('game.sayAll "Oh, that can\'t be right..."')
				else:
					randx = random.randint(1, size[0])   
					randx = randx - size[0]/2
					randz = random.randint(1, size[1])
					randz = randz - size[1]/2
				p.newx = float(randx)
				p.newz = float(randz)
				p.JumpInterval = 1
				p.jumpdist = int(math.sqrt(randx*randx+randz*randz))

#################################################################################################

#################################################################################################
#					Jump Calculations
#################################################################################################
			#host.rcon_invoke("game.sayAll \"" + str(dx) + "\"")
			#host.rcon_invoke("game.sayAll \"" + str(dy) + "\"")
			#host.rcon_invoke("game.sayAll \"" + str(dz) + "\"")
			#host.rcon_invoke("game.sayAll \"" + str(myweaponType) + "\"")
			if jumpRecent[playerId] == 0:
				host.rcon_invoke('game.sayAll "Engines are at acceptable temperature levels"')
				JumpInterval = p.JumpInterval
				jumpRecent[p.index] = 1
				host.rcon_invoke('game.sayAll "FTL drive spinning up"')
				if speed[p.index] == 1:
					JumpInterval = 0
				p.timerID = bf2.Timer(onJumpTimer, JumpInterval, 1, p)  #Sending the x, y, z variables to onJumpTimer
			else:
				cooldown = int(p.cooldown-(host.timer_getWallTime()-p.cooldownstarttime))
				if cooldown == 1:
					host.rcon_invoke('game.sayAll "Your FTL drive is too hot, ' + str(cooldown) + ' second until '+p.getName()+'\'s FTL drive is ready again"')
				if cooldown < 60:
					host.rcon_invoke('game.sayAll "Your FTL drive is too hot, ' + str(cooldown) + ' seconds until '+p.getName()+'\'s FTL drive is ready again"')
				else:
					minutes = cooldown/60
					seconds = cooldown%60
					if minutes < 2:
						if seconds == 1:
							host.rcon_invoke('game.sayAll "Your FTL drive is too hot, ' + str(minutes) + ' minute and ' + str(seconds) + ' second until '+p.getName()+'\'s FTL drive is ready again"')
						else:
							host.rcon_invoke('game.sayAll "Your FTL drive is too hot, ' + str(minutes) + ' minute and ' + str(seconds) + ' seconds until '+p.getName()+'\'s FTL drive is ready again"')
					else:
						if seconds == 1:
							host.rcon_invoke('game.sayAll "Your FTL drive is too hot, ' + str(minutes) + ' minutes and ' + str(seconds) + ' second until '+p.getName()+'\'s FTL drive is ready again"')
						else:
							host.rcon_invoke('game.sayAll "Your FTL drive is too hot, ' + str(minutes) + ' minutes and ' + str(seconds) + ' seconds until '+p.getName()+'\'s FTL drive is ready again"')
			#myvehic.setPosition((newx, newy, newz))
			vehicname = p.myvehic.templateName
			#host.rcon_invoke("game.sayAll \"" + str(vehicname) + "\"")
		else:
			host.rcon_invoke('game.sayAll "Only squad leaders can begin FTL preparations"')

#################################################################################################
#					Die?
#################################################################################################
'''
	if msgText.find("die") <> -1:
		f35b_objs = bf2.objectManager.getObjectsOfType('dice.hfe.world.ObjectTemplate.PlayerControlObject')
		CounterX = 0
		for obj in f35b_objs:
			if obj.templateName == 'air_f35b':
				host.rcon_invoke("game.sayAll \"" + Diemessage1 + "\"")
				try:
					host.rcon_invoke("game.sayAll \"" + Diemessage1 + "\"")
					obj.setDamage(-1)
					CounterX = CounterX + 1
				except:
					host.rcon_invoke("game.sayAll \"" + Diemessage1 + "\"")
					host.rcon_invoke("game.sayAll \"" + str(CounterX) + "\"")
					host.rcon_invoke("game.sayAll \"" + Diemessage1 + "\"")
'''
   #      #f35b_pos = obj.getPosition()
   #      #if f35b_pos[1] > 100.0:   
   #         #host.rcon_invoke("game.sayAll \"" + str(f35b_pos[1]) + "\"")
   #         #f35bx = f35b_pos[0]
   #         #f35by = f35b_pos[1]
   #         #f35bz = f35b_pos[2]
   #         #f35by = 499.0
   #         #obj.setPosition((f35bx, f35by, f35bz))
   #         #f35b_pos[1] = f35by
   #         #host.rcon_invoke("game.sayAll \"" + str(f35by) + "\"")
	
def onChatMessage(playerId, msgText, channel, flags):
	global msgTimer, jumpRecent, misjumpchance, badjumpchance, speedmode, jumpfailchance
	p = bf2.playerManager.getPlayerByIndex(playerId)
	p.hasASquad = 0
	if msgText.find("JUMP") <> -1 and p.dev == 1:
		p.hasASquad = 1		
		if p.isSquadLeader() == 1:
			p.squadmembers = 0
			for sm in bf2.playerManager.getPlayers():
				if sm.getSquadId() == p.getSquadId() and p.getTeam() == sm.getTeam(): #checks to see if there's more than one person in a squad, doesn't need to check for squad 0 because no one can be the squad leader of squad 0
					p.squadmembers = p.squadmembers + 1
					host.rcon_invoke('game.sayAll "Found player '+sm.getName()+' in '+p.getName()+'\'s squad"')
			if p.squadmembers > 1:
				p.hasASquad = 1
				host.rcon_invoke('game.sayAll "Jump preparations underway"')
				p.jumpgonebad = 0
				p.newx = 0.0
				p.newy = 0.0
				p.newz = 0.0
				p.JumpInterval = 5
				p.jumpdist = 0
				myweapon = p.getPrimaryWeapon()
				myweaponType = myweapon.templateName
				myvehic = p.getVehicle()
				mypos = myvehic.getPosition()
				newpos = myvehic.getPosition()
				myrot = myvehic.getRotation()
				myyaw = myrot[0]
				mypitch = myrot[1]
				r = 1.0
#################################################################################################
#												NormalJumpSquad
#################################################################################################

				if msgText.find("^") <> -1:
					JMsplt = msgText.split("^")
					JDText = JMsplt[1]
					r = float(JDText)
					p.jumpdist = int(r)
					badjump = random.randint(1,100)
					if badjump < badjumpchance:
						p.jumpgonebad = 1
						host.rcon_invoke('game.sayAll "Ummmm... something\'s not right here..."')
				jumpfail = random.randint(1,100)
				if jumpfail < jumpfailchance:
					p.newx = mypos[0]
					p.newy = mypos[1]
					p.newz = mypos[2]
					host.rcon_invoke('game.sayAll "ERROR Jump failure imminent"')
					p.JumpInterval = 0
				else:
					mypitch = -1.0 * mypitch  #pitch is backwards
					mypitch = math.radians(mypitch)
					myyaw = math.radians(myyaw)
					dz = math.cos(myyaw) * math.cos(mypitch) * r
					dx = math.sin(myyaw) * math.cos(mypitch) * r
					dy = math.sin(mypitch) * r
					#assume good code to here
					host.rcon_invoke('game.sayAll "Jump co-ordinates recieved"')
					#newpos[1] = newpos[1] + 300.0
					#host.rcon_invoke('game.sayAll "' + str(myrot[0]) + '"')
					#host.rcon_invoke('game.sayAll "' + str(myrot[1]) + '"')
					p.newx = mypos[0] + dx
					p.newy = mypos[1] + dy
					p.newz = mypos[2] + dz
#################################################################################################

#################################################################################################
#					Jump CalculationsSquad
#################################################################################################
				#host.rcon_invoke("game.sayAll \"" + str(dx) + "\"")
				#host.rcon_invoke("game.sayAll \"" + str(dy) + "\"")
				#host.rcon_invoke("game.sayAll \"" + str(dz) + "\"")
				#host.rcon_invoke("game.sayAll \"" + str(myweaponType) + "\"")
				if jumpRecent[playerId] == 0:
					host.rcon_invoke('game.sayAll "Engines are at acceptable temperature levels"')
					JumpInterval = p.JumpInterval
					jumpRecent[p.index] = 1
					p.hasASquad = 1
					host.rcon_invoke('game.sayAll "FTL drive spinning up"')
					if speed[p.index] == 1:
						JumpInterval = 0
					p.timerID = bf2.Timer(onJumpTimer, JumpInterval, 1, p)  #Sending the x, y, z variables to onJumpTimer
				else:
					host.rcon_invoke('game.sayAll "'+p.getName()+', your FTL drive is not ready yet, need to wait for your engines to cool down!"')
				#myvehic.setPosition((newx, newy, newz))
				vehicname = p.myvehic.templateName
				#host.rcon_invoke("game.sayAll \"" + str(vehicname) + "\"")
			else:
				host.rcon_invoke('game.sayAll "Need more than one FTL computer to make proper calculations"')
		else:
			host.rcon_invoke('game.sayAll "Only squad leaders can begin FTL preparations"')
	
	if msgText.find("worldsize") <> -1 and p.dev == 1:
		size = bf2.gameLogic.getWorldSize()
		host.rcon_invoke('game.sayAll "Map size info:"')
		host.rcon_invoke('game.sayAll "size[0] = '+str(size[0])+'"')
		host.rcon_invoke('game.sayAll "size[1] = '+str(size[1])+'"')
	
	if msgText.find("mypos") <> -1 and p.dev == 1:
		mypos = myvehic.getPosition()
		myrot = myvehic.getRotation()
		host.rcon_invoke('game.sayAll "Player position info:"')
		host.rcon_invoke('game.sayAll "x position = '+str(mypos[0])+'"')
		host.rcon_invoke('game.sayAll "y position = '+str(mypos[1])+'"')
		host.rcon_invoke('game.sayAll "z position = '+str(mypos[2])+'"')
		
		host.rcon_invoke('game.sayAll "yaw = '+str(myrot[0])+'"')
		host.rcon_invoke('game.sayAll "pitch = '+str(myrot[1]*-1)+'"')
	
	if msgText.find("RoKrules") <> -1 and speedmode == 1 and p.dev == 1:
		speed[playerId] = 1
		host.rcon_invoke('game.sayAll "'+p.getName()+' has enabled speed mode"')
		
	if msgText.find("nospeed") <> -1 and speedmode == 1 and p.dev == 1:
		speed[playerId] = 0
		host.rcon_invoke('game.sayAll "'+p.getName()+' has disabled speed mode"')
	if msgText.find("jump") <> -1 and p.dev == 1:
		if p.isSquadLeader() == 1:
			host.rcon_invoke('game.sayAll "Jump preparations underway"')
			p.jumpgonebad = 0
			p.newx = 0.0
			p.newy = 0.0
			p.newz = 0.0
			p.JumpInterval = 5
			p.jumpdist = 0
			myweapon = p.getPrimaryWeapon()
			myweaponType = myweapon.templateName
			myvehic = p.getVehicle()
			mypos = myvehic.getPosition()
			newpos = myvehic.getPosition()
			myrot = myvehic.getRotation()
			myyaw = myrot[0]
			mypitch = myrot[1]
			r = 1.0
#################################################################################################
#												NormalJump
#################################################################################################

			if msgText.find("^") <> -1:
				JMsplt = msgText.split("^")
				JDText = JMsplt[1]
				r = float(JDText)
				p.jumpdist = int(r)
				badjump = random.randint(1,100)
				if badjump < badjumpchance:
					p.jumpgonebad = 1
					host.rcon_invoke('game.sayAll "Ummmm... something\'s not right here..."')
				jumpfail = random.randint(1,100)
				if jumpfail < jumpfailchance:
					p.newx = mypos[0]
					p.newy = mypos[1]
					p.newz = mypos[2]
					host.rcon_invoke('game.sayAll "ERROR Jump failure"')
					p.JumpInterval = 0
				else:
					mypitch = -1.0 * mypitch  #pitch is backwards
					mypitch = math.radians(mypitch)
					myyaw = math.radians(myyaw)
					dz = math.cos(myyaw) * math.cos(mypitch) * r
					dx = math.sin(myyaw) * math.cos(mypitch) * r
					dy = math.sin(mypitch) * r
					#assume good code to here
					host.rcon_invoke('game.sayAll "Jump co-ordinates recieved"')
					#newpos[1] = newpos[1] + 300.0
					#host.rcon_invoke('game.sayAll "' + str(myrot[0]) + '"')
					#host.rcon_invoke('game.sayAll "' + str(myrot[1]) + '"')
					p.newx = mypos[0] + dx
					p.newy = mypos[1] + dy
					p.newz = mypos[2] + dz
#################################################################################################

#################################################################################################
#					Jumphome
#################################################################################################


			if msgText.find("jumphome") <> -1:    
				host.rcon_invoke('game.sayAll "Roger that, lets get out of here!"')
				controlPoints = bf2.objectManager.getObjectsOfType('dice.hfe.world.ObjectTemplate.ControlPoint')
				for cp in controlPoints:
					if cp.cp_getParam('unableToChangeTeam') != 0 and cp.cp_getParam('team') == p.getTeam():
						homepos = cp.getPosition()
				p.newx = float(homepos[0])
				p.newy = float(homepos[1])
				p.newz = float(homepos[2])+100.0
				p.JumpInterval = 5
				p.jumpdist = int(math.sqrt( pow((mypos[0]-homepos[0]),2) + pow((mypos[1]-homepos[1]),2) + pow((mypos[2]-homepos[2]),2) ))
################################################################################################

#################################################################################################         
#					Blindjump
#################################################################################################
			if msgText.find("blindjump") <> -1 or p.jumpgonebad == 1:
				host.rcon_invoke('game.sayAll "Calculating random co-ordinates"')
				size = bf2.gameLogic.getWorldSize()
				p.jumpgonebad = 0
				misjump = random.randint(1,100)
				if misjump < misjumpchance:
					randx = random.randint(250,500)+size[0]/2
					randz = random.randint(250,500)+size[1]/2
					host.rcon_invoke('game.sayAll "Oh, that can\'t be right..."')
				else:
					randx = random.randint(1, size[0])   
					randx = randx - size[0]/2
					randz = random.randint(1, size[1])
					randz = randz - size[1]/2
				p.newx = float(randx)
				p.newz = float(randz)
				p.JumpInterval = 1
				p.jumpdist = int(math.sqrt(randx*randx+randz*randz))

#################################################################################################

#################################################################################################
#					Jump Calculations
#################################################################################################
			#host.rcon_invoke("game.sayAll \"" + str(dx) + "\"")
			#host.rcon_invoke("game.sayAll \"" + str(dy) + "\"")
			#host.rcon_invoke("game.sayAll \"" + str(dz) + "\"")
			#host.rcon_invoke("game.sayAll \"" + str(myweaponType) + "\"")
			if jumpRecent[playerId] == 0:
				host.rcon_invoke('game.sayAll "Engines are at acceptable temperature levels"')
				JumpInterval = p.JumpInterval
				jumpRecent[p.index] = 1
				host.rcon_invoke('game.sayAll "FTL drive spinning up"')
				if speed[p.index] == 1:
					JumpInterval = 0
				p.timerID = bf2.Timer(onJumpTimer, JumpInterval, 1, p)  #Sending the x, y, z variables to onJumpTimer
			else:
				cooldown = int(p.cooldown-(host.timer_getWallTime()-p.cooldownstarttime))
				if cooldown == 1:
					host.rcon_invoke('game.sayAll "Your FTL drive is too hot, ' + str(cooldown) + ' second until '+p.getName()+'\'s FTL drive is ready again"')
				if cooldown < 60:
					host.rcon_invoke('game.sayAll "Your FTL drive is too hot, ' + str(cooldown) + ' seconds until '+p.getName()+'\'s FTL drive is ready again"')
				else:
					minutes = cooldown/60
					seconds = cooldown%60
					if minutes < 2:
						if seconds == 1:
							host.rcon_invoke('game.sayAll "Your FTL drive is too hot, ' + str(minutes) + ' minute and ' + str(seconds) + ' second until '+p.getName()+'\'s FTL drive is ready again"')
						else:
							host.rcon_invoke('game.sayAll "Your FTL drive is too hot, ' + str(minutes) + ' minute and ' + str(seconds) + ' seconds until '+p.getName()+'\'s FTL drive is ready again"')
					else:
						if seconds == 1:
							host.rcon_invoke('game.sayAll "Your FTL drive is too hot, ' + str(minutes) + ' minutes and ' + str(seconds) + ' second until '+p.getName()+'\'s FTL drive is ready again"')
						else:
							host.rcon_invoke('game.sayAll "Your FTL drive is too hot, ' + str(minutes) + ' minutes and ' + str(seconds) + ' seconds until '+p.getName()+'\'s FTL drive is ready again"')
			#myvehic.setPosition((newx, newy, newz))
			vehicname = p.myvehic.templateName
			#host.rcon_invoke("game.sayAll \"" + str(vehicname) + "\"")
		else:
			host.rcon_invoke('game.sayAll "Only squad leaders can begin FTL preparations"')

	if msgText.find("gaiulton") <> -1 and devmode == 1:
		p.dev == 1
'''
#################################################################################################
#					Die?
#################################################################################################

	if msgText.find("die") <> -1:
		f35b_objs = bf2.objectManager.getObjectsOfType('dice.hfe.world.ObjectTemplate.PlayerControlObject')
		CounterX = 0
		for obj in f35b_objs:
			if obj.templateName == 'air_f35b':
				host.rcon_invoke("game.sayAll \"" + Diemessage1 + "\"")
				try:
					host.rcon_invoke("game.sayAll \"" + Diemessage1 + "\"")
					obj.setDamage(-1)
					CounterX = CounterX + 1
				except:
					host.rcon_invoke("game.sayAll \"" + Diemessage1 + "\"")
					host.rcon_invoke("game.sayAll \"" + str(CounterX) + "\"")
					host.rcon_invoke("game.sayAll \"" + Diemessage1 + "\"")

   #      #f35b_pos = obj.getPosition()
   #      #if f35b_pos[1] > 100.0:   
   #         #host.rcon_invoke("game.sayAll \"" + str(f35b_pos[1]) + "\"")
   #         #f35bx = f35b_pos[0]
   #         #f35by = f35b_pos[1]
   #         #f35bz = f35b_pos[2]
   #         #f35by = 499.0
   #         #obj.setPosition((f35bx, f35by, f35bz))
   #         #f35b_pos[1] = f35by
   #         #host.rcon_invoke("game.sayAll \"" + str(f35by) + "\"")'''
def onJumpTimer(p):      
	myvehic = p.getVehicle()
	newx = p.newx
	newy = p.newy
	newz = p.newz
	p.nummemjumped = 0
	myvehic.setPosition((newx, newy, newz))
	if p.hasASquad == 1:
		#host.rcon_invoke('game.sayAll "'+p.getName()+' has a squad"')
		for sm in bf2.playerManager.getPlayers():	
			if int(sm.getSquadId()) == int(p.getSquadId()) and p.index != sm.index and p.getTeam() == sm.getTeam():	
				#host.rcon_invoke('game.sayAll "Trying to move '+sm.getName()+' in '+p.getName()+'\'s squad"')
				smvehic = sm.getVehicle()
				#host.rcon_invoke('game.sayAll "Trying to move '+str(smvehic)+' in '+p.getName()+'\'s squad"')
				squadrot = myvehic.getRotation()
				#host.rcon_invoke('game.sayAll "Grabbed rotation, trying to split it"')
				squadyaw = squadrot[0]
				squadpitch = squadrot[1]
				squadroll = squadrot[2]
				#host.rcon_invoke('game.sayAll "Rotation split, trying to get position"')
				squadpos = myvehic.getPosition()
				#host.rcon_invoke('game.sayAll "Position grabbed converting rotation to radians"')
				squadyaw = math.radians(squadyaw)
				squadpitch = math.radians(squadpitch)
				squadroll = math.radians(squadroll)
				'''host.rcon_invoke('game.sayAll "converted to radians"')
				host.rcon_invoke('game.sayAll "nummemjumped = '+str(p.nummemjumped)+'"')
				host.rcon_invoke('game.sayAll "Trying to output vars"')
				try:
					host.rcon_invoke('game.sayAll "squadyaw = ' +str(squadyaw)+ '"')
				except:
					host.rcon_invoke('game.sayAll "squadyaw failed"')
				try:
					host.rcon_invoke('game.sayAll "squadpitch = ' +str(squadpitch)+ '"')
				except:
					host.rcon_invoke('game.sayAll "squadpitch failed"')
				try:
					host.rcon_invoke('game.sayAll "squadroll = ' +str(squadroll)+ '"')
				except:
					host.rcon_invoke('game.sayAll "squadroll failed"')
				try:
					host.rcon_invoke('game.sayAll "squadpos = ' +str(squadpos)+ '"')
				except:
					host.rcon_invoke('game.sayAll "squadpos failed"')'''
				if p.nummemjumped == 0:
					#host.rcon_invoke('game.sayAll "jumping squadmember ' +str(p.nummemjumped)+ '"')
					sm.newz = SD*math.sin(squadyaw+DA)
					sm.newx = SD*math.cos(squadyaw-DA)
					p.nummemjumped = 1
				elif p.nummemjumped == 1:
					#host.rcon_invoke('game.sayAll "jumping squadmember ' +str(p.nummemjumped)+ '"')
					sm.newz = SD*math.sin(squadyaw-DA)
					sm.newx = SD*math.cos(squadyaw-DA)
					p.nummemjumped = 2
				elif p.nummemjumped == 2:
					#host.rcon_invoke('game.sayAll "jumping squadmember ' +str(p.nummemjumped)+ '"')
					sm.newz = 2*SD*math.sin(squadyaw+DA)
					sm.newx = 2*SD*math.cos(squadyaw-DA)
					p.nummemjumped = 3
				elif p.nummemjumped == 3:
					#host.rcon_invoke('game.sayAll "jumping squadmember ' +str(p.nummemjumped)+ '"')
					sm.newz = 2*SD*math.sin(squadyaw-DA)
					sm.newx = 2*SD*math.cos(squadyaw-DA)
					p.nummemjumped = 4
				elif p.nummemjumped == 4:
					#host.rcon_invoke('game.sayAll "jumping squadmember ' +str(p.nummemjumped)+ '"')
					sm.newz = 3*SD*math.sin(squadyaw+DA)
					sm.newx = 3*SD*math.cos(squadyaw+DA)
					p.nummemjumped = 5
				elif p.nummemjumped == 5:
					#host.rcon_invoke('game.sayAll "jumping squadmember ' +str(p.nummemjumped)+ '"')
					sm.newz = 3*SD*math.sin(squadyaw-DA)
					sm.newx = 3*SD*math.cos(squadyaw-DA)
				#host.rcon_invoke('game.sayAll "You know math, trying to calculate new position..."')
				newx = sm.newx+squadpos[0]
				newz = sm.newz+squadpos[2]
				newy = squadpos[1]
				#host.rcon_invoke('game.sayAll "X '+str(newx)+' Y '+str(newy)+' Z '+str(newz)+'"')
				smvehic.setPosition((newx,newy,newz))
				smvehic.setRotation((squadyaw, squadpitch, squadroll))
				host.rcon_invoke('game.sayAll "Trying to set timer for player"')
				p.cooldown = p.jumpdist/12
				host.rcon_invoke('game.sayAll "time grabbed, converting"')
				cooldown = p.cooldown
				host.rcon_invoke('game.sayAll "converting starting timer"')
				sm.cooldownTimer = bf2.Timer(onCool, cooldown, 1, sm)
				host.rcon_invoke('game.sayAll "timer created"')
				sm.cooldownstarttime = host.timer_getWallTime()
				host.rcon_invoke('game.sayAll "starttime found"')
	host.rcon_invoke('game.sayAll "Jump succesfull"')
	p.timerID.destroy()
	p.timerID = None
	p.cooldown = p.jumpdist/12
	p.cooldownstarttime = host.timer_getWallTime()
	if p.cooldown == 1:
		host.rcon_invoke('game.sayAll "' + str(p.cooldown) + ' second until '+p.getName()+'\'s FTL drive is ready again"')
	if p.cooldown < 60:
		host.rcon_invoke('game.sayAll "' + str(p.cooldown) + ' seconds until '+p.getName()+'\'s FTL drive is ready again"')
	else:
		minutes = p.cooldown/60
		seconds = p.cooldown%60
		if minutes < 2:
			if seconds == 1:
				host.rcon_invoke('game.sayAll "' + str(minutes) + ' minute and ' + str(seconds) + ' second until '+p.getName()+'\'s FTL drive is ready again"')
			else:
				host.rcon_invoke('game.sayAll "' + str(minutes) + ' minute and ' + str(seconds) + ' seconds until '+p.getName()+'\'s FTL drive is ready again"')
		else:
			if seconds == 1:
				host.rcon_invoke('game.sayAll "' + str(minutes) + ' minutes and ' + str(seconds) + ' second until '+p.getName()+'\'s FTL drive is ready again"')
			else:
				host.rcon_invoke('game.sayAll "' + str(minutes) + ' minutes and ' + str(seconds) + ' seconds until '+p.getName()+'\'s FTL drive is ready again"')
	if speed[p.index] == 1:
		p.cooldown = 0
		host.rcon_invoke('game.sayAll "§3   ' + p.getName() + ' is a cheater, and therefore has no cooldown..."')
	cooldown = p.cooldown
	p.cooldownTimer = bf2.Timer(onCool, cooldown, 1, p)

def onCool(p):
	host.rcon_invoke('game.sayAll "Engines cooled, '+p.getName()+'\'s FTL drive is ready now"')
	jumpRecent[p.index] = 0
	p.cooldownTimer.destroy()
	p.cooldownTimer = None


#def onPlayerChangeWeapon(playerObject, oldWeaponObject, newWeaponObject):
     #host.rcon_invoke("game.sayAll \"" + WCMessage1 + "\"")
     #host.rcon_invoke("game.sayAll \"" + newWeaponObject.templateName + "\"")
     #host.rcon_invoke("game.sayAll \"" + WCMessage2 + "\"")

#On spawn, resets the cooldown for the player
def onPlayerSpawn(p, vehicle):
   global jumpRecent
   jumpRecent[p.index] = 0 #shouldn't be keeping the cooldown from a jump in their "past life"
   host.rcon_invoke('game.sayAll "'+p.getName()+'"\'s cooldown has been reset due to death"')
