Difference between revisions of "Skate Park Mod"

From X-Moto
Jump to: navigation, search
(more info)
m (Reverted edits by Opofefemucu (Talk) to last revision by Gaivota)
 
(7 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 +
[[Ca:Skate Park Mod|Català]] - [[Es:Skate Park Mod|Español]]
 +
 +
[[Image:Skatepark.jpg]]
 +
 
This script allows you to convert your level into a skate park.  To complete the level, you must collect points by performing tricks.
 
This script allows you to convert your level into a skate park.  To complete the level, you must collect points by performing tricks.
  
The more tricks you string together, the higher the points.  Try to keep a manual going as long as you can while doing flips.  The icons above your head represent your current trick score.
+
The more tricks you string together, the higher the points.  Try to keep a manual going as long as you can while doing flips.  
  
 
If you would like to change the values, use the constants defined at the top of the script.
 
If you would like to change the values, use the constants defined at the top of the script.
  
Copy the code directly into your level to add this functionality.  Note that if you edit your level xmotoedit, you'll have to recopy the entities because the editor doesn't retain them correctly.
+
The original Script by Jacky J has been altered a bit, to make it compatible to actual xmoto versions (it won't produce huge replays anymore, but therefore the scoring display had to be changed).
 +
 
 +
Copy the code directly into your level to add this functionality.  Note that if you edit your level in any editor, you'll have to recopy the entities because the editor doesn't retain them correctly.
 +
 
 +
Level examples: Skate Park mod (old code), Half Pipe (current code)
  
<script>
+
<script>
+
-- Level Parameters
-- Level Parameters
+
SCORE_WIN = 6000
SCORE_WIN                 = 5000
+
MANUAL_MINTIME = 1.0
MANUAL_MINTIME             = 1.0
+
MANUAL_MAXTIME = 180.0
MANUAL_MAXTIME             = 180.0
+
MANUAL_UPDATEINTERVAL = 3.0
MANUAL_UPDATEINTERVAL     = 3.0
+
MANUAL_BASESCORE = 30
MANUAL_BASESCORE           = 15
+
MANUAL_FLIPDIVISOR = 4
MANUAL_FLIPDIVISOR         = 4
+
AIR_MINDURATION = 2.0
AIR_MINDURATION           = 2.0
+
AIR_MULTIPLIER = 3
AIR_MULTIPLIER             = 4
+
AIR_MAXBONUSFLIPCOUNT = 5
AIR_MAXBONUSFLIPCOUNT     = 5
+
FLIP_BASESCORE = 80
FLIP_BASESCORE             = 80
+
ICON_SCORE                = 10
+
-- States
ICON_OFFSETX              = -1.25
+
ManualAirTime = 0.0
ICON_OFFSETY              = 3.0
+
InAir = false
+
AirStart = 0.0
-- States
+
AirFlips = 0
ManualAirTime             = 0.0
+
WheelTouching = {0, 0}
InAir                     = false
+
Manualing = 0
AirStart                   = 0.0
+
ManualingStart = 0.0
AirFlips                   = 0
+
WheelTouching             = {0, 0}
+
-- Scores
Manualing                 = 0
+
FlipCount = 0
ManualingStart             = 0.0
+
                 CurrentStar                    = 0
+
FlipScore = 0
-- Scores
+
ManualScore = 0
FlipCount                  = 0
+
BonusScore = 0
FlipScore                 = 0
+
LastScore = 0   
ManualScore               = 0
+
TotalScore = 0
BonusScore                 = 0
+
HighTrickScore = 0
TotalScore                = 0
+
  HighTrickScore            = 0
+
function Tick()
IconCount                  = { 0, 0, 0 }
+
ManualScore = GetManualScore()
CurrentScore              = 0
+
if ManualScore ~= LastScore then
LastScore                  = 0
+
PlayerX, PlayerY, PlayerDirection = Game.GetPlayerPosition()
+
addStar(PlayerDirection)
function OnLoad()
+
LastScore = ManualScore
  Game.SetKeyHook("H", "ShowHelp")
+
end
  Game.Message("Press H for help")
+
return true
  return true
+
end  
end
 
 
function Tick()
 
  PlayerX, PlayerY, PlayerDirection = Game.GetPlayerPosition()
 
 
  -- Display icons
 
  ManualScore = GetManualScore()
 
  CurrentScore = math.floor((FlipScore + ManualScore + BonusScore) / ICON_SCORE)
 
 
  -- Calculate score icons
 
  if CurrentScore ~= LastScore then
 
  IconCount[1] = math.floor(CurrentScore / 100)
 
  CurrentScore = CurrentScore - IconCount[1] * 100
 
  IconCount[2] = math.floor(CurrentScore / 10)
 
  CurrentScore = CurrentScore - IconCount[2] * 10
 
  IconCount[3] = math.floor(CurrentScore)
 
  EraseIcons()
 
  end
 
 
  for i = 1, IconCount[1] do
 
  Game.SetEntityPos("High" .. (i-1), PlayerX + i / 5 + ICON_OFFSETX, PlayerY + ICON_OFFSETY)
 
  end
 
  for i = 1, IconCount[2] do
 
  Game.SetEntityPos("Mid" .. (i-1), PlayerX + i / 5 + ICON_OFFSETX, PlayerY + ICON_OFFSETY - 0.3)
 
  end
 
  for i = 1, IconCount[3] do
 
  Game.SetEntityPos("Low" .. (i-1), PlayerX + i / 5 + ICON_OFFSETX, PlayerY + ICON_OFFSETY - 0.6)
 
  end
 
 
  LastScore = CurrentScore
 
  if TotalScore &gt;= SCORE_WIN then
 
  Game.WinPlayer()
 
  end
 
 
  return true
 
end
 
 
function ShowHelp()
 
  Game.Message("Welcome to the Skate Park mod.  Gets points by performing huge tricks.")
 
  Game.Message("Get " .. SCORE_WIN .. " points to win.")
 
  Game.Message("Scripting by Jacky J")
 
end
 
 
function OnSomersault(TDirection)
 
  local AirTime = 0
 
  local FlipMultiplier = 0
 
  local FlipDecayCount = 0
 
 
  -- Get air time
 
  if InAir == true then
 
  AirTime = Game.GetTime() - AirStart
 
  end
 
 
  -- Get manual time
 
  local ManualTime = GetManualTime()
 
 
  -- Increment flip counter
 
  FlipCount = FlipCount + 1
 
  AirFlips = AirFlips + 1
 
  FlipDecayCount = AirFlips
 
  if FlipDecayCount > AIR_MAXBONUSFLIPCOUNT then
 
  FlipDecayCount = AIR_MAXBONUSFLIPCOUNT
 
  end
 
  FlipValue = (FLIP_BASESCORE - 5 * FlipDecayCount) * AirFlips
 
 
  -- Calculate flip score
 
  FlipScore = FlipScore + math.floor(FlipValue + AIR_MULTIPLIER * AirTime + math.floor(ManualTime / MANUAL_FLIPDIVISOR))
 
end
 
 
function OnWheel1Touchs(TStatus)
 
 
  WheelTouching[1] = TStatus
 
  if TStatus == 1 then
 
  CancelInAir()
 
  StartLandManual(1)
 
  else
 
  StartLiftManual(1)
 
  StartInAir(2)
 
  end
 
 
end
 
 
function OnWheel2Touchs(TStatus)
 
 
  WheelTouching[2] = TStatus
 
  if TStatus == 1 then
 
 
 
  CancelInAir()
 
  StartLandManual(2)
 
  else
 
  StartLiftManual(2)
 
  StartInAir(1)
 
  end
 
 
end
 
 
   
 
   
  function StartInAir(TWheel)
+
function OnLoad()
 +
Game.SetKeyHook("H", "ShowHelp")
 +
Game.Message("  Skate Park\nPress H for help")
 +
return true
 +
end
 +
 +
function ShowHelp()
 +
Game.Message("Get points by performing tricks!")
 +
Game.Message("Get " .. SCORE_WIN .. " points to win.")
 +
Game.Message("Scripting by Jacky J")
 +
Game.Message("Level design by Gaivota")
 +
end
 +
 +
function addStar(direction)
 +
CurrentStar = CurrentStar + 1
 +
if CurrentStar &lt;= 7 then
 +
PlayerX, PlayerY, PlayerDirection = Game.GetPlayerPosition()
 +
Game.SetDynamicEntityNone("som"..CurrentStar)
 +
Game.SetEntityPos("som"..CurrentStar, PlayerX, PlayerY)
 +
if direction == 0 then
 +
Game.SetDynamicEntityRotation("som"..CurrentStar, 0, 0.5, 100, 0, 0)
 +
else
 +
Game.SetDynamicEntityRotation("som"..CurrentStar, 0, 0.5, -100, 0, 0)
 +
end
 +
end
 +
end
 
   
 
   
  if WheelTouching[TWheel] == 0 then
+
function resetStars()
  InAir = true
+
  for i = 1, CurrentStar do
  AirStart = Game.GetTime()
+
if i &lt;= 7 then
  end
+
Game.SetDynamicEntityNone("som"..i)
end
+
Game.SetDynamicEntityTranslation("som"..i, 0, 50, 2500, 0, 1250)
 +
end
 +
end  
 
   
 
   
function CancelInAir()
+
CurrentStar = 0
 +
end
 
   
 
   
  if InAir == true then
+
function OnSomersault(TDirection)
  AirTime = Game.GetTime() - AirStart
+
local AirTime = 0
  if AirTime &gt; AIR_MINDURATION then
+
local FlipMultiplier = 0
    --Game.Message("Air Time: " .. AirTime)
+
local FlipDecayCount = 0
  end
+
 +
-- Get air time
 +
if InAir == true then
 +
AirTime = Game.GetTime() - AirStart
 +
end
 +
 +
-- Get manual time
 +
local ManualTime = GetManualTime()
 +
 +
-- Increment flip counter
 +
FlipCount = FlipCount + 1
 +
AirFlips = AirFlips + 1
 +
FlipDecayCount = AirFlips
 +
if FlipDecayCount > AIR_MAXBONUSFLIPCOUNT then
 +
FlipDecayCount = AIR_MAXBONUSFLIPCOUNT
 +
end
 +
FlipValue = (FLIP_BASESCORE - 5 * FlipDecayCount) * AirFlips
 +
 +
-- Calculate flip score
 +
FlipScore = FlipScore + math.floor(FlipValue + AIR_MULTIPLIER * AirTime + math.floor(ManualTime / MANUAL_FLIPDIVISOR))
 
   
 
   
  -- Subtract air time from manualing time
+
addStar(TDirection)
  if Manualing ~= 0 and AirTime &gt; 0.5 then
+
end
    ManualAirTime = ManualAirTime + AirTime
+
  end
+
function OnWheel1Touchs(TStatus)
  end
+
WheelTouching[1] = TStatus
 +
if TStatus == 1 then
 +
CancelInAir()
 +
StartLandManual(1)
 +
else
 +
StartLiftManual(1)
 +
StartInAir(2)
 +
end
 +
end
 +
 +
function OnWheel2Touchs(TStatus)
 +
WheelTouching[2] = TStatus
 +
if TStatus == 1 then
 +
 +
CancelInAir()
 +
StartLandManual(2)
 +
else
 +
StartLiftManual(2)
 +
StartInAir(1)
 +
end
 +
end
 +
 +
function StartInAir(TWheel)
 +
if WheelTouching[TWheel] == 0 then
 +
InAir = true
 +
AirStart = Game.GetTime()
 +
end
 +
end
 +
 +
function CancelInAir()
 +
if InAir == true then
 +
AirTime = Game.GetTime() - AirStart
 +
if AirTime &gt; AIR_MINDURATION then
 +
--Game.Message("Air Time: " .. AirTime)
 +
end
 +
-- Subtract air time from manualing time
 +
if Manualing ~= 0 and AirTime &gt; 0.5 then
 +
ManualAirTime = ManualAirTime + AirTime
 +
end
 +
end
 +
 +
AirFlips = 0
 +
InAir = false
 +
end
 +
 +
-- Called when a wheel touches
 +
function StartLandManual(TWheel)
 +
local OtherWheel = 3 - TWheel
 +
 +
-- Check for both wheels touching
 +
if WheelTouching[OtherWheel] == 1 and Manualing ~= 0 then
 +
UpdateScore()
 +
Manualing = 0
 +
ManualAirTime = 0
 +
return true
 +
end
 +
 +
-- Swapping manual wheels without both wheels touching
 +
if Manualing == OtherWheel then
 +
Manualing = TWheel
 +
--DisplayManualTime()
 +
return true
 +
end
 +
 +
-- Check for an existing manual
 +
if Manualing == 0 then
 +
 +
-- Start the manual
 +
Manualing = TWheel
 +
ManualingStart = Game.GetTime() + MANUAL_MINTIME
 +
end
 +
end
 +
 +
-- Called when a wheel lifts off the ground
 +
function StartLiftManual(TWheel)
 +
local OtherWheel = 3 - TWheel
 +
StartLandManual(OtherWheel)
 +
end
 +
 +
-- Returns the current manualing time
 +
function GetManualTime()
 +
 +
-- Check for a manual
 +
if Manualing == 0 then
 +
return 0.0
 +
end
 +
 +
-- Discount current air time
 +
if InAir == true then
 +
CurrentAirTime = Game.GetTime() - AirStart
 +
else
 +
CurrentAirTime = 0
 +
end
 +
 +
-- Calculate the time
 +
ManualTime = Game.GetTime() - ManualingStart - ManualAirTime - CurrentAirTime
 +
 +
-- Cap time
 +
if ManualTime &lt; 0 then
 +
ManualTime = 0
 +
elseif ManualTime &gt; MANUAL_MAXTIME then
 +
ManualTime = MANUAL_MAXTIME
 +
end
 +
 +
return ManualTime
 +
end
 +
 +
-- Calculates the manual score
 +
function GetManualScore()
 +
local ManualTime = GetManualTime()
 +
local Score = math.floor(ManualTime / MANUAL_UPDATEINTERVAL) * MANUAL_BASESCORE;
 +
 +
return Score
 +
end
 +
 +
-- Awards the player points
 +
function UpdateScore()
 +
ManualScore = GetManualScore()
 +
 +
-- Score formulas
 +
TrickScore = FlipScore + ManualScore + BonusScore
 +
TotalScore = TotalScore + TrickScore
 +
 +
-- Display score
 +
if TrickScore &gt; 0 then
 +
Game.Message("Trick Score: " .. TrickScore)
 +
Game.Message("Total Score: " .. TotalScore)
 +
end
 +
 +
if TotalScore &gt;= SCORE_WIN then
 +
Game.WinPlayer()
 +
end
 
   
 
   
  AirFlips = 0
 
  InAir = false
 
end
 
 
   
 
   
-- Called when a wheel touches
+
resetStars()  
function StartLandManual(TWheel)
 
 
  local OtherWheel = 3 - TWheel
 
 
    
 
    
  -- Check for both wheels touching
 
  if WheelTouching[OtherWheel] == 1 and Manualing ~= 0 then
 
  UpdateScore()
 
  Manualing = 0
 
  ManualAirTime = 0
 
  return true
 
  end
 
 
 
  -- Swapping manual wheels without both wheels touching
 
  if Manualing == OtherWheel then
 
  Manualing = TWheel
 
  --DisplayManualTime()
 
  return true
 
  end
 
 
 
  -- Check for an existing manual
 
  if Manualing == 0 then
 
  -- Start the manual
 
  Manualing = TWheel
 
  ManualingStart = Game.GetTime() + MANUAL_MINTIME
 
  end
 
end
 
 
   
 
   
-- Called when a wheel lifts off the ground
+
-- Reset stats
function StartLiftManual(TWheel)
+
FlipCount = 0
  local OtherWheel = 3 - TWheel
+
FlipScore = 0
  StartLandManual(OtherWheel)
+
ManualScore = 0
end
+
BonusScore = 0
+
TrickScore = 0
-- Returns the current manualing time
+
end
function GetManualTime()
+
 
+
</script>
  -- Check for a manual
+
        <theme_replacements>
  if Manualing == 0 then
+
<sprite_replacement old_name="Strawberry" new_name="Star"/>
  return 0.0
+
<sprite_replacement old_name="Flower" new_name="Star"/>
  end
+
<sprite_replacement old_name="Wrecker" new_name="Star"/>
 
+
</theme_replacements>  
  -- Discount current air time
+
 
  if InAir == true then
+
Level code here!
  CurrentAirTime = Game.GetTime() - AirStart
+
 
  else
+
  <entity id="som1" typeid="Sprite">
  CurrentAirTime = 0
+
<size r="0.400000" width="0.5" height="0.5"/>
  end
+
<position x="100" y="100"/>
+
<param name="z" value="-1"/>
  -- Calculate the time
+
<param name="name" value="Star"/>
  ManualTime = Game.GetTime() - ManualingStart - ManualAirTime - CurrentAirTime 
+
        </entity>
+
        <entity id="som2" typeid="Sprite">
  -- Cap time
+
<size r="0.400000" width="0.8" height="0.8"/>
  if ManualTime &lt; 0 then
+
<position x="100" y="100"/>
  ManualTime = 0
+
<param name="z" value="-1"/>
  elseif ManualTime &gt; MANUAL_MAXTIME then
+
<param name="name" value="Star"/>
  ManualTime = MANUAL_MAXTIME
+
        </entity>
  end
+
        <entity id="som3" typeid="Sprite">
+
<size r="0.400000" width="1.1" height="1.1"/>
  return ManualTime
+
<position x="100" y="100"/>
end
+
<param name="z" value="-1"/>
   
+
<param name="name" value="Star"/>
-- Calculates the manual score
+
        </entity>
function GetManualScore()
+
        <entity id="som4" typeid="Sprite">
  local ManualTime = GetManualTime()
+
<size r="0.400000" width="1.4" height="1.4"/>
  local Score = math.floor(ManualTime / MANUAL_UPDATEINTERVAL) * MANUAL_BASESCORE;
+
<position x="100" y="100"/>
  return Score
+
<param name="z" value="-1"/>
end
+
<param name="name" value="Star"/>
+
        </entity>
-- Awards the player points
+
        <entity id="som5" typeid="Sprite">
function UpdateScore()
+
<size r="0.400000" width="1.7" height="1.7"/>
+
<position x="100" y="100"/>
  ManualScore = GetManualScore()
+
<param name="z" value="-1"/>
+
<param name="name" value="Star"/>
  -- Score formulas
+
        </entity>
  TrickScore = FlipScore + ManualScore + BonusScore
+
        <entity id="som6" typeid="Sprite">
  TotalScore = TotalScore + TrickScore
+
<size r="0.400000" width="2.0" height="2.0"/>
+
<position x="100" y="100"/>
  -- Display score
+
<param name="z" value="-1"/>
  if TrickScore &gt; 0 then
+
<param name="name" value="Star"/>
  Game.Message("Trick Score: " .. TrickScore)
+
        </entity>
  Game.Message("Total Score: " .. TotalScore)
+
        <entity id="som7" typeid="Sprite">
  end
+
<size r="0.400000" width="2.3" height="2.3"/>
+
<position x="100" y="100"/>
  -- Reset stats
+
<param name="z" value="-1"/>
  FlipCount = 0
+
<param name="name" value="Star"/>
  FlipScore = 0
+
        </entity>
  ManualScore = 0
 
  BonusScore = 0
 
  TrickScore = 0
 
  IconCount = { 0, 0, 0 }
 
  EraseIcons()
 
end
 
 
-- Move icons offscreen
 
function EraseIcons()
 
  for i = 1, 9 do
 
  Game.SetEntityPos("High" .. (i-1), 0, 10000)
 
  end
 
  for i = 1, 9 do
 
  Game.SetEntityPos("Mid" .. (i-1), 0, 10000)
 
  end
 
  for i = 1, 9 do
 
  Game.SetEntityPos("Low" .. (i-1), 0, 10000)
 
  end
 
end
 
 
</script>
 
<entity id="Low0" typeid="Wrecker"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Low1" typeid="Wrecker"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Low2" typeid="Wrecker"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Low3" typeid="Wrecker"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Low4" typeid="Wrecker"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Low5" typeid="Wrecker"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Low6" typeid="Wrecker"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Low7" typeid="Wrecker"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Low8" typeid="Wrecker"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Low9" typeid="Wrecker"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Mid0" typeid="Strawberry"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Mid1" typeid="Strawberry"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Mid2" typeid="Strawberry"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Mid3" typeid="Strawberry"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Mid4" typeid="Strawberry"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Mid5" typeid="Strawberry"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Mid6" typeid="Strawberry"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Mid7" typeid="Strawberry"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Mid8" typeid="Strawberry"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="Mid9" typeid="Strawberry"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="High0" typeid="EndOfLevel"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="High1" typeid="EndOfLevel"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="High2" typeid="EndOfLevel"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="High3" typeid="EndOfLevel"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="High4" typeid="EndOfLevel"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="High5" typeid="EndOfLevel"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="High6" typeid="EndOfLevel"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="High7" typeid="EndOfLevel"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="High8" typeid="EndOfLevel"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 
<entity id="High9" typeid="EndOfLevel"><size r="0.500000" width="0.5" height="0.5"/><position x="0.000000" y="10000.000000"/></entity>
 

Latest revision as of 11:20, 26 November 2010

Català - Español

Skatepark.jpg

This script allows you to convert your level into a skate park. To complete the level, you must collect points by performing tricks.

The more tricks you string together, the higher the points. Try to keep a manual going as long as you can while doing flips.

If you would like to change the values, use the constants defined at the top of the script.

The original Script by Jacky J has been altered a bit, to make it compatible to actual xmoto versions (it won't produce huge replays anymore, but therefore the scoring display had to be changed).

Copy the code directly into your level to add this functionality. Note that if you edit your level in any editor, you'll have to recopy the entities because the editor doesn't retain them correctly.

Level examples: Skate Park mod (old code), Half Pipe (current code)

	<script>
	-- Level Parameters
		SCORE_WIN 			= 6000
		MANUAL_MINTIME 			= 1.0
		MANUAL_MAXTIME 			= 180.0
		MANUAL_UPDATEINTERVAL 		= 3.0
		MANUAL_BASESCORE		= 30
		MANUAL_FLIPDIVISOR		= 4
		AIR_MINDURATION			= 2.0
		AIR_MULTIPLIER			= 3
		AIR_MAXBONUSFLIPCOUNT		= 5		
		FLIP_BASESCORE			= 80
		
		-- States
		ManualAirTime			= 0.0
		InAir 				= false
		AirStart 			= 0.0
		AirFlips			= 0
		WheelTouching 			= {0, 0}
		Manualing				= 0
		ManualingStart 			= 0.0
		
		-- Scores
		FlipCount			= 0
                CurrentStar                     = 0
		FlipScore			= 0
		ManualScore			= 0
		BonusScore			= 0
		LastScore = 0  
		TotalScore 			= 0
		HighTrickScore			= 0
		
		function Tick()
			ManualScore = GetManualScore()
			if ManualScore ~= LastScore then
				PlayerX, PlayerY, PlayerDirection = Game.GetPlayerPosition()
				addStar(PlayerDirection)
				LastScore = ManualScore
			end
			return true
		end 

		function OnLoad()
			Game.SetKeyHook("H", "ShowHelp")
			Game.Message("   Skate Park\nPress H for help")
			return true
		end
		
		function ShowHelp()
			Game.Message("Get points by performing tricks!")
			Game.Message("Get " .. SCORE_WIN .. " points to win.")
			Game.Message("Scripting by Jacky J")
			Game.Message("Level design by Gaivota")
		end
		
		function addStar(direction)
			CurrentStar = CurrentStar + 1
			if CurrentStar <= 7 then
				PlayerX, PlayerY, PlayerDirection = Game.GetPlayerPosition()
				Game.SetDynamicEntityNone("som"..CurrentStar)
				Game.SetEntityPos("som"..CurrentStar, PlayerX, PlayerY)
				if direction == 0 then
					Game.SetDynamicEntityRotation("som"..CurrentStar, 0, 0.5, 100, 0,  0)
				else
					Game.SetDynamicEntityRotation("som"..CurrentStar, 0, 0.5, -100, 0, 0)
				end
			end	
		end 

		function resetStars()
  			for i = 1, CurrentStar do
				if i <= 7 then
					Game.SetDynamicEntityNone("som"..i)
					Game.SetDynamicEntityTranslation("som"..i, 0, 50, 2500, 0, 1250)
				end
			end 

			CurrentStar = 0
		end 

		function OnSomersault(TDirection)
			local AirTime = 0
			local FlipMultiplier = 0
			local FlipDecayCount = 0
			
			-- Get air time
			if InAir == true then
				AirTime = Game.GetTime() - AirStart
			end
			
			-- Get manual time
			local ManualTime = GetManualTime()
			
			-- Increment flip counter
			FlipCount = FlipCount + 1
			AirFlips = AirFlips + 1
			FlipDecayCount = AirFlips
			if FlipDecayCount > AIR_MAXBONUSFLIPCOUNT then
				FlipDecayCount = AIR_MAXBONUSFLIPCOUNT
			end 
			FlipValue = (FLIP_BASESCORE - 5 * FlipDecayCount) * AirFlips
			
			-- Calculate flip score
			FlipScore = FlipScore + math.floor(FlipValue + AIR_MULTIPLIER * AirTime + math.floor(ManualTime / MANUAL_FLIPDIVISOR))

			addStar(TDirection)
		end
		
		function OnWheel1Touchs(TStatus)
			WheelTouching[1] = TStatus
			if TStatus == 1 then
				CancelInAir()
				StartLandManual(1)
			else
				StartLiftManual(1)
				StartInAir(2)
			end
		end
		
		function OnWheel2Touchs(TStatus)
			WheelTouching[2] = TStatus
			if TStatus == 1 then
				
				CancelInAir()
				StartLandManual(2)
			else
				StartLiftManual(2)
				StartInAir(1)
			end
		end
		
		function StartInAir(TWheel)
			if WheelTouching[TWheel] == 0 then
				InAir = true
				AirStart = Game.GetTime()
			end
		end
		
		function CancelInAir()
			if InAir == true then
				AirTime = Game.GetTime() - AirStart
				if AirTime > AIR_MINDURATION then
					--Game.Message("Air Time: " .. AirTime)
				end
				-- Subtract air time from manualing time
				if Manualing ~= 0 and AirTime > 0.5 then
					ManualAirTime = ManualAirTime + AirTime
				end
			end
			
			AirFlips = 0
			InAir = false
		end
		
		-- Called when a wheel touches
		function StartLandManual(TWheel)
			local OtherWheel = 3 - TWheel
			
			-- Check for both wheels touching
			if WheelTouching[OtherWheel] == 1 and Manualing ~= 0 then
				UpdateScore()
				Manualing = 0
				ManualAirTime = 0
				return true
			end
			
			-- Swapping manual wheels without both wheels touching
			if Manualing == OtherWheel then
				Manualing = TWheel
				--DisplayManualTime()
				return true
			end
			
			-- Check for an existing manual
			if Manualing == 0 then
			
				-- Start the manual
				Manualing = TWheel
				ManualingStart = Game.GetTime() + MANUAL_MINTIME
			end
		end
		
		-- Called when a wheel lifts off the ground
		function StartLiftManual(TWheel)
			local OtherWheel = 3 - TWheel
			StartLandManual(OtherWheel)
		end
		
		-- Returns the current manualing time
		function GetManualTime()
		
			-- Check for a manual
			if Manualing == 0 then
				return 0.0
			end
			
			-- Discount current air time
			if InAir == true then
				CurrentAirTime = Game.GetTime() - AirStart
			else
				CurrentAirTime = 0
			end
			
			-- Calculate the time
			ManualTime = Game.GetTime() - ManualingStart - ManualAirTime - CurrentAirTime		 	
			
			-- Cap time
			if ManualTime < 0 then
				ManualTime = 0
			elseif ManualTime > MANUAL_MAXTIME then
				ManualTime = MANUAL_MAXTIME
			end
			
			return ManualTime
		end
					
		-- Calculates the manual score
		function GetManualScore()
			local ManualTime = GetManualTime()
			local Score = math.floor(ManualTime / MANUAL_UPDATEINTERVAL) * MANUAL_BASESCORE;
			
			return Score
		end
		
		-- Awards the player points
		function UpdateScore()
			ManualScore = GetManualScore()
			
			-- Score formulas
			TrickScore = FlipScore + ManualScore + BonusScore
			TotalScore = TotalScore + TrickScore
			
			-- Display score
			if TrickScore > 0 then
				Game.Message("Trick Score: " .. TrickScore)
				Game.Message("Total Score: " .. TotalScore)
			end
			
			if TotalScore >= SCORE_WIN then
				Game.WinPlayer()
			end


			resetStars() 
 

			-- Reset stats
			FlipCount = 0
			FlipScore = 0
			ManualScore = 0
			BonusScore = 0
			TrickScore = 0
		end
  		
	</script>	
        <theme_replacements>
		<sprite_replacement old_name="Strawberry" new_name="Star"/>
		<sprite_replacement old_name="Flower" new_name="Star"/>
		<sprite_replacement old_name="Wrecker" new_name="Star"/>
	</theme_replacements> 

Level code here!

  <entity id="som1" typeid="Sprite">
		<size r="0.400000" width="0.5" height="0.5"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>
        <entity id="som2" typeid="Sprite">
		<size r="0.400000" width="0.8" height="0.8"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>
        <entity id="som3" typeid="Sprite">
		<size r="0.400000" width="1.1" height="1.1"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>
        <entity id="som4" typeid="Sprite">
		<size r="0.400000" width="1.4" height="1.4"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>
        <entity id="som5" typeid="Sprite">
		<size r="0.400000" width="1.7" height="1.7"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>
        <entity id="som6" typeid="Sprite">
		<size r="0.400000" width="2.0" height="2.0"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>
        <entity id="som7" typeid="Sprite">
		<size r="0.400000" width="2.3" height="2.3"/>
		<position x="100" y="100"/>
		<param name="z" value="-1"/>
		<param name="name" value="Star"/>
        </entity>