Player Functions

From X-Moto
Jump to: navigation, search

Script Player Functions

GetPlayerProfileName()

[*deprecated* -- cannot be used anymore]

Explanation

This function returns a string with the players profile name.

Script Example

This example prints the players profile name on level start.

function OnLoad()
  name = Game.GetPlayerProfileName()
  Game.Message(name)
  return true
end

SetPlayerPosition(x, y, bRight)

Explanation

Set the position and direction of the players in the game. bRight can be 0 or 1.

Script example

The example teleports the playerq each time one enters the zone.

Zone0 = {}

function Zone0.OnEnter()
  Game.SetPlayerPosition(5, 0, 1)
end


SetAPlayerPosition(x, y, bRight, player)

Explanation

Set the position and direction of the player in the game. bRight can be 0 or 1.

Script example

The example show how to teleport the player 0 at start of the level to the position (20, 5)

function OnLoad()
  Game.SetAPlayerPosition(20, 5, 1, 0)
  return true
end


GetPlayerPosition()

Explanation

Return the triplet (x, y, bRight) which give the position of the player 0 in the game.

Script example

This example make the player unable to get the strawberry ;-)

function Tick()
  x, y, bright = Game.GetPlayerPosition()
  if x > 18
  then
    Game.SetPlayerPosition(5, 0, 1)
  end

  return true
end


GetPlayerVelocity(player)

[require Xmoto >= 0.5.0]

Explanation

Return the velocity of the player.

Script example

This example show informations when the player pressed the key M.

function OnLoad()
 Game.SetKeyHook("M", "Infos")
 return true
end

function Infos()
 Game.Message("Velocity: "..Game.GetPlayerVelocity(0))
 Game.Message("Speed: "..Game.GetPlayerSpeed(0))
 Game.Message("Angle: "..Game.GetPlayerAngle(0))
end


GetPlayerSpeed(player)

[require Xmoto >= 0.5.0]

Explanation

Return the speed of the player.

Script example

This example show informations when the player pressed the key M.

function OnLoad()
 Game.SetKeyHook("M", "Infos")
 return true
end

function Infos()
 Game.Message("Velocity: "..Game.GetPlayerVelocity(0))
 Game.Message("Speed: "..Game.GetPlayerSpeed(0))
 Game.Message("Angle: "..Game.GetPlayerAngle(0))
end


GetPlayerAngle(player)

[require Xmoto >= 0.5.0]

Explanation

Return the angle of the player.

Script example

This example show informations when the player pressed the key M.

function OnLoad()
 Game.SetKeyHook("M", "Infos")
 return true
end

function Infos()
 Game.Message("Velocity: "..Game.GetPlayerVelocity(0))
 Game.Message("Speed: "..Game.GetPlayerSpeed(0))
 Game.Message("Angle: "..Game.GetPlayerAngle(0))
end


GetAPlayerPosition(player)

[require Xmoto >= 0.3.0]

Explanation

Return the triplet (x, y, bRight) which give the position of a player in the game.

Script example

function OnLoad()
  x, y, bright = Game.GetAPlayerPosition(0)
  Game.Message("Player0 position is ("..x..","..y..")")
  return true
end


KillPlayer()

[require Xmoto >= 0.2.1]

Explanation

If you call this function, the players die. It's interesting if you want the players be killed by an enemy for example.

Script example

In the following example, the player will die when he will enter in the zone Zone0.

Zone0 = {}

function Zone0.OnEnter()
  Game.KillPlayer()
end


KillAPlayer(player)

[require Xmoto >= 0.3.0]

Explanation

If you call this function, a player dies. It's interesting if you want the player be killed by an enemy for example.

Script example

function OnLoad()
  Game.KillAPlayer(0)
  return true
end


WinPlayer()

[require Xmoto >= 0.2.1]

Explanation

If you call this function, all players win the game (even if there are remaining strawberries).

Script example

In the following example, the player win on entering in the zone Zone0.

Zone0 = {}
 
function Zone0.OnEnter()
  Game.WinPlayer()
end


WinAPlayer(player)

[require Xmoto >= 0.3.0]

Explanation

If you call this function, a player wins the game (even if there are remaining strawberries).

Script example

function OnLoad()
  Game.WinAPlayer(0)
  return true
end