Difference between revisions of "Skate Park Mod"
Line 1: | Line 1: | ||
+ | [[Ca:Skate Park Mod|Català]] - [[Es:Skate Park Mod|Español]] | ||
+ | |||
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. | ||
Revision as of 18:27, 15 December 2006
This script allows you to convert your level into a skate park. To complete the level, you must collect points by performing tricks.
Note of an xmoto developper : this script is nice. However, it has a problem due to the xmoto limitation. It produces big replays (severals hundreads of Ko) due to the calls in the Ticks function.
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.
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.
<script> -- Level Parameters SCORE_WIN = 5000 MANUAL_MINTIME = 1.0 MANUAL_MAXTIME = 180.0 MANUAL_UPDATEINTERVAL = 3.0 MANUAL_BASESCORE = 15 MANUAL_FLIPDIVISOR = 4 AIR_MINDURATION = 2.0 AIR_MULTIPLIER = 4 AIR_MAXBONUSFLIPCOUNT = 5 FLIP_BASESCORE = 80 ICON_SCORE = 10 ICON_OFFSETX = -1.25 ICON_OFFSETY = 3.0 -- States ManualAirTime = 0.0 InAir = false AirStart = 0.0 AirFlips = 0 WheelTouching = {0, 0} Manualing = 0 ManualingStart = 0.0 -- Scores FlipCount = 0 FlipScore = 0 ManualScore = 0 BonusScore = 0 TotalScore = 0 HighTrickScore = 0 IconCount = { 0, 0, 0 } CurrentScore = 0 LastScore = 0 function OnLoad() Game.SetKeyHook("H", "ShowHelp") Game.Message("Press H for help") return true 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 >= 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) 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 -- Reset stats FlipCount = 0 FlipScore = 0 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>