mattisthebest
#1 Mystic Realm Enjoyer
Ive been trying to get the drifting code out of this script for a while now and i have no idea what i am doing since i have not learned lua yet, NOTE: The mod that the script comes from is Open Assets and im pretty sure im allowed to do this (any help or advice is VERY much appreciated :33)
--SCRIPT--
--SCRIPT--
Lua:
//Unleashed Physics and Camera by DarknessStylus
//Originally named "Centered Camera"
//Based on my first script
//Now with counters xD
freeslot("S_PLAY_ALLDRIFT", "sfx_drft2")
states[S_PLAY_ALLDRIFT] = {SPR_PLAY, SPR2_SPIN|FF_ANIMATE, 4, nil, 4, 5, S_PLAY_WALK}
COM_AddCommand("analogsens", function(player, arg)
if arg
if arg == "1" or arg == "true" or arg == "gens" or arg == "unwiished" or arg == "on"
if io and player == consoleplayer
local file = io.openlocal("client/analogsens.dat", "w+")
file:write(arg)
file:close()
end
player.analogsens = true
CONS_Printf(player, "Analog sensitivity now is Gens/Wii Unleashed type")
elseif arg == "0" or arg == "false" or arg == "vanilla" or arg == "off"
if io and player == consoleplayer
local file = io.openlocal("client/analogsens.dat", "w+")
file:write(arg)
file:close()
end
player.analogsens = false
CONS_Printf(player, "Analog sensitivity now is Vanilla type")
elseif player.analogsens
CONS_Printf(player, "analogsens [1 or 0] - Changes the sensitivity for your analog. Currently Gens/Wii Unleashed type.")
else
CONS_Printf(player, "analogsens [1 or 0] - Changes the sensitivity for your analog. Currently Vanilla type.")
end
elseif player.analogsens
CONS_Printf(player, "analogsens [1 or 0] - Changes the sensitivity for your analog. Currently Gens/Wii Unleashed type.")
else
CONS_Printf(player, "analogsens [1 or 0] - Changes the sensitivity for your analog. Currently Vanilla type.")
end
end, 0)
local MomentumLimiter = function(mo,svr)
if (not (mo.skin == "adventuresonic"))
svr = 77*mo.scale*1
else
svr = 88*FRACUNIT
end
if mo.eflags&MFE_UNDERWATER then
svr = $/2
end
if mo.player.powers[pw_sneakers]
or mo.player.powers[pw_super]
svr = $*2
end
if mo.player.cmd.forwardmove < 0
or mo.player.cmd.forwardmove == 0
//or mo.player.cmd.sidemove ~= 0
or mo.skin == "modernsonic" --silly failcheck
or mo.player.isondriftvar == 1
or mo.player.pflags & PF_SPINNING
or (not (P_IsObjectOnGround(mo)))
return
end
if mo.player.speed > svr then
mo.movefactor = 1*FRACUNIT/4
mo.friction = 30*FRACUNIT/32
P_InstaThrust(mo, mo.angle, 77*mo.scale*1)
mo.player.normalspeed = $ - FRACUNIT
return true
else
return false
end
end
//Better wall checker finally jajajajaja YES!!!!
addHook("MobjMoveBlocked", function(mo)
mo.player.wallcounterc = true
end, MT_PLAYER)
addHook("MobjLineCollide", function(mo, line)
if not(mo.player) then return end
if not mo and mo.valid then return end
if P_IsObjectOnGround(mo) then return end
if mo.player.wallcounterc == false then return end
mo.angle = mo.player.drawangle
end, MT_PLAYER)
addHook("PlayerCanDamage", function(player, enemy)
if player.isondriftvar == 1
return true
end
end)
addHook("PreThinkFrame", do
for player in players.iterate
if player.mo
local mo = player.mo
if player.cancelboostvar == nil
player.cancelboostvar = 0
end
if player.angleholdervar == nil
player.angleholdervar = 0
end
if player.momspeedvar == nil
player.momspeedvar = 0
end
if player.mo.skin == "modernsonic"
if player.cmd.buttons & BT_CUSTOM1
and ((player.boosting == true) or (player.airboost == true))
player.cancelboostvar = $ + 1
else
player.cancelboostvar = 0
end
end
if player.mo.skin == "adventuresonic"
if player.cmd.buttons & BT_SPIN
//and player.mo.state ~= S_PLAY_SPINDASH
and player.YuRushMode.boosting
player.cancelboostvar = $ + 1
else
player.cancelboostvar = 0
end
end
if player.mo.skin == "modernsonic"
if player.cancelboostvar > 0
and player.cancelboostvar < 2
and P_IsObjectOnGround(player.mo)
if player.cmd.sidemove < -25
P_InstaThrust(player.mo, player.mo.angle - ANGLE_45, 60*FRACUNIT)
elseif player.cmd.sidemove > 25
P_InstaThrust(player.mo, player.mo.angle + ANGLE_45, 60*FRACUNIT)
elseif player.cmd.sidemove < 25
and player.cmd.sidemove > -25
return
end
end
end
if player.mo.skin == "adventuresonic"
if player.cancelboostvar > 0
and player.cancelboostvar < 2
and P_IsObjectOnGround(player.mo)
if player.cmd.sidemove < -25
P_InstaThrust(player.mo, player.mo.angle - ANGLE_90, 60*FRACUNIT)
elseif player.cmd.sidemove > 25
P_InstaThrust(player.mo, player.mo.angle + ANGLE_90, 60*FRACUNIT)
elseif player.cmd.sidemove < 25
and player.cmd.sidemove > -25
return
end
end
end
end
end
end)
//Main hook
addHook("ThinkFrame", do
for player in players.iterate
if player.mo
local mo = player.mo
local movingfactor = 4*FRACUNIT/11
local movingslowfactor = 0
local momxyangle = R_PointToAngle2(player.mo.x, player.mo.y, (player.mo.x+player.mo.momx), (player.mo.y+player.mo.momy))
local vnormalcamera = R_PointToAngle2(0, 0, mo.height - 7*FRACUNIT, mo.momz)
local vspringcamera = R_PointToAngle2(0, 0, mo.height - 25*FRACUNIT, mo.momz)
if player.wallcounterc == nil
player.wallcounterc = false
end
if player.normalcamc == nil
player.normalcamc = false
end
if player.hspringcamc == nil
player.hspringcamc = 0
end
if player.speedturnvar == nil
player.speedturnvar = 0
end
if player.isonairvar == nil
player.isonairvar = 0
end
if player.beforeboostprevspd == nil
player.beforeboostprevspd = 0
end
if player.isondriftvar == nil
player.isondriftvar = 0
end
if player.prevpspeed2 == nil
player.prevpspeed2 = 0
end
if player.isdriftingvar == nil
player.isdriftingvar = 0
end
if player.isdriftdustvar == nil
player.isdriftdustvar = 0
end
if player.aerealboostvar == nil
player.aerealboostvar = 0
end
if player.boostanglechangervar == nil
player.boostanglechanglervar = 0
end
if player.analogsens == nil
player.analogsens = false
end
if player.localfriction2 == nil
player.localfriction2 = 32*FRACUNIT/32
end
//Checks and counters
if (not (P_IsObjectOnGround(player.mo)))
player.isonairvar = 10
else
player.isonairvar = $ - 1
end
if not (player.driftmobj2 and player.driftmobj2.valid) then
player.driftmobj2 = P_SpawnMobj(player.mo.x, player.mo.y, player.mo.z, MT_GFZFLOWER1)
player.driftmobj2.flags2 = $1|MF2_DONTDRAW
P_SetOrigin(player.driftmobj2, player.mo.x, player.mo.y, player.mo.z)
player.driftmobj2.fuse = 65
elseif (player.driftmobj2 and player.driftmobj2.valid)
P_SetOrigin(player.driftmobj2, player.mo.x, player.mo.y, player.mo.z)
end
player.prevpspeed2 = 10
//Special threat to EVERY character that breaks or have a weird function >:c
if player.boosting == true
//or DIDBOOST == true
player.beforeboostprevspd = 18
player.boostanglechangervar = $ + 1
else
player.beforeboostprevspd = $ - 1
player.boostanglechangervar = 0
end
if player.beforeboostprevspd == 18
or player.beforeboostprevspd == 0
player.localfriction2 = 32*FRACUNIT/32
elseif player.beforeboostprevspd < 17
and player.beforeboostprevspd > 0
player.localfriction2 = 29*FRACUNIT/32
end
if player.cmd.forwardmove == 0
and ((player.beforeboostprevspd < 17) or (player.beforeboostprevspd > 0))
player.localfriction2 = 29*FRACUNIT/32
elseif ((player.cmd.forwardmove ~= 0) or (player.cmd.sidemove ~= 0))
and ((player.beforeboostprevspd == 18) or (player.beforeboostprevspd <= 0))
player.localfriction2 = 32*FRACUNIT/32
end
if player.mo.skin == "modernsonic"
if player.boosting == false
and player.speed > 42*FRACUNIT
and P_IsObjectOnGround(player.mo)
player.localfriction2 = 30*FRACUNIT/32
//end
end
end
if player.mo.skin == "adventuresonic"
if mo.state == S_PLAY_ROLL
or ((mo.state == S_PLAY_SPINDASH) and (player.isondriftvar == 0))
and P_IsObjectOnGround(player.mo)
player.hspringcamc = $ + 1
else
player.hspringcamc = 0
end
end
if (not (P_IsObjectOnGround(player.mo)))
if player.airboost == true
player.aerealboostvar = $ + 1
else
player.aerealboostvar = 0
end
if player.aerealboostvar == 1
mo.angle = momxyangle
player.drawangle = mo.angle
end
end
if player.noxmomchar
and player.mo.skin == "modernsonic"
player.noxmomchar = 2
end
//if player.normalcamc == false
if player.analogsens == true
if P_IsObjectOnGround(player.mo)
if player.speed < 25*FRACUNIT
and player.cmd.forwardmove > 0
if player.cmd.sidemove > -10
and player.cmd.sidemove < 10
mo.movefactor = movingslowfactor + 1*FRACUNIT/2
player.localfriction2 = 32*FRACUNIT/32
mo.friction = player.localfriction2
end
end
end
end
/*if player.boostanglechangervar == 1
player.drawangle = mo.angle
if mo.msbaang
mo.msbaang = player.drawangle
end
end*/
//The camera part
//if (not (player.cmd.buttons & BT_CUSTOM3))
if P_IsObjectOnGround(player.mo)
and ((player.quickstep1 == 0) or (player.quickstep1 == nil) or (player.quickstep1 ~= 1))
and player.isondriftvar == 0
and player.hspringcamc == 0
if player.speed > 25*FRACUNIT
mo.angle = momxyangle
player.drawangle = mo.angle
if player.analogsens == true
if player.cmd.sidemove > -14
and player.cmd.sidemove < 14
mo.movefactor = movingslowfactor
else
mo.movefactor = movingfactor
end
else
mo.movefactor = movingfactor
end
mo.friction = player.localfriction2
end
player.normalcamc = true
else
player.normalcamc = false
end
if player.isonairvar == 10
if mo.state == S_PLAY_SPRING
player.aiming = vspringcamera
else
player.aiming = vnormalcamera
end
if player.stomping == true
player.aiming = vspringcamera
end
elseif player.isonairvar == 9
player.aiming = 0
end
//Drift part
if player.mo and player.mo.valid
and (not (player.pflags & PF_STASIS))
if ((player.cmd.buttons & BT_ATTACK) or (player.cmd.buttons & BT_FIRENORMAL) or (player.cmd.buttons & BT_SPIN))
and ((((player.cmd.sidemove > 25) or (player.cmd.sidemove < -25)) and (player.analogsens == true)) or (((player.cmd.sidemove > 20) or (player.cmd.sidemove < -20)) and (player.analogsens == false)) or (((player.cmd.sidemove > 20) or (player.cmd.sidemove < -20)) and (player.analogsens == nil)))
and P_IsObjectOnGround(player.mo)
and player.speed > 20*FRACUNIT
if player.mo.skin == "modernsonic"
and (not (player.cmd.buttons & BT_SPIN))
if player.boosting == true
mo.angle = momxyangle
mo.movefactor = 6*FRACUNIT/8
player.localfriction2 = 23*FRACUNIT/32
player.isondriftvar = 1
elseif player.boosting == false
mo.angle = momxyangle
mo.movefactor = 3*FRACUNIT/5
player.localfriction2 = 32*FRACUNIT/32
P_InstaThrust(player.mo, mo.angle, (FixedMul(42*FRACUNIT, player.mo.scale)+5*FRACUNIT)+cos(player.aiming))
player.isondriftvar = 1
end
else
mo.state = S_PLAY_ALLDRIFT
player.isdriftingvar = $ + 1
player.isdriftdustvar = $ + 1
if player.isdriftingvar > 6
S_StartSound(player.driftmobj2, sfx_drft2)
end
if player.isdriftdustvar == 2
local dust1 = P_SpawnMobjFromMobj(player.realmo, P_RandomRange(-10, 10) * FRACUNIT, P_RandomRange(-10, 10) * FRACUNIT, 0, MT_SPINDUST)
dust1.momx = P_RandomRange(-4, 4)*FRACUNIT
dust1.momy = P_RandomRange(-4, 4)*FRACUNIT
dust1.momz = P_RandomRange(0, 4)*FRACUNIT
dust1.destscale = FRACUNIT/2
local dust2 = P_SpawnMobjFromMobj(player.realmo, P_RandomRange(-10, 10) * FRACUNIT, P_RandomRange(-10, 10) * FRACUNIT, 0, MT_SPINDUST)
dust2.momx = P_RandomRange(-4, 4)*FRACUNIT
dust2.momy = P_RandomRange(-4, 4)*FRACUNIT
dust2.momz = P_RandomRange(0, 4)*FRACUNIT
dust2.destscale = FRACUNIT/2
local dust3 = P_SpawnMobjFromMobj(player.realmo, P_RandomRange(-10, 10) * FRACUNIT, P_RandomRange(-10, 10) * FRACUNIT, 0, MT_SPINDUST)
dust3.momx = P_RandomRange(-4, 4)*FRACUNIT
dust3.momy = P_RandomRange(-4, 4)*FRACUNIT
dust3.momz = P_RandomRange(0, 4)*FRACUNIT
dust3.destscale = FRACUNIT/2
local dust4 = P_SpawnMobjFromMobj(player.realmo, P_RandomRange(-10, 10) * FRACUNIT, P_RandomRange(-10, 10) * FRACUNIT, 0, MT_SPINDUST)
dust4.momx = P_RandomRange(-4, 4)*FRACUNIT
dust4.momy = P_RandomRange(-4, 4)*FRACUNIT
dust4.momz = P_RandomRange(0, 4)*FRACUNIT
dust4.destscale = FRACUNIT/2
local dust5 = P_SpawnMobjFromMobj(player.realmo, P_RandomRange(-10, 10) * FRACUNIT, P_RandomRange(-10, 10) * FRACUNIT, 0, MT_SPINDUST)
dust5.momx = P_RandomRange(-4, 4)*FRACUNIT
dust5.momy = P_RandomRange(-4, 4)*FRACUNIT
dust5.momz = P_RandomRange(0, 4)*FRACUNIT
dust5.destscale = FRACUNIT/2
end
if player.isdriftingvar >= 7
player.isdriftingvar = 0
end
if player.isdriftdustvar > 2
player.isdriftdustvar = 0
end
mo.angle = momxyangle
player.drawangle = momxyangle
if player.cmd.buttons & BT_SPIN
if player.speed < 55*FRACUNIT
and player.mo.skin ~= "adventuresonic"
P_Thrust(player.mo, mo.angle, (FixedMul(1*FRACUNIT, player.mo.scale)+3*FRACUNIT)+cos(player.aiming))
mo.movefactor = 3*FRACUNIT/5
player.localfriction2 = 32*FRACUNIT/32
else
P_InstaThrust(player.mo, mo.angle, (FixedMul(50*FRACUNIT, player.mo.scale)+5*FRACUNIT)+cos(player.aiming))
mo.movefactor = 6*FRACUNIT/8
player.localfriction2 = 23*FRACUNIT/32
end
else
mo.movefactor = 3*FRACUNIT/5
player.localfriction2 = 32*FRACUNIT/32
if player.speed > 70*FRACUNIT
P_InstaThrust(player.mo, mo.angle, (FixedMul(70*FRACUNIT, player.mo.scale)+5*FRACUNIT)+cos(player.aiming))
else
P_InstaThrust(player.mo, mo.angle, (FixedMul(42*FRACUNIT, player.mo.scale)+5*FRACUNIT)+cos(player.aiming))
end
end
player.isondriftvar = 1
if player.pflags & ~PF_SPINNING
player.pflags = $1 & ~PF_SPINNING
end
end
mo.friction = player.localfriction2
else
player.isondriftvar = 0
S_StopSound(player.driftmobj2)
end
end
//Insert here rail grind special threat to make it more functional lol
/*if mo.state == S_PLAYER_GRINDING
mo.angle = momxyangle
player.drawangle = momxyangle
player.localfriction2 = 29*FRACUNIT/32
end*/
if player.isonairvar > 10
player.isonairvar = 10
end
if player.cancelboostvar > 10
player.cancelboostvar = 10
end
if player.angleholdervar < 0
player.angleholdervar = 0
end
if player.aerealboostvar > 10
player.aerealboostvar = 10
end
end
end
end)
addHook("PlayerSpawn", function(p)
if io and p == consoleplayer and p.analogsens == nil
local file = io.openlocal("client/analogsens.dat")
if file
local string = file:read("*a")
if string == "1" or string == "true" or string == "gens" or string == "on"
COM_BufInsertText(p, "analogsens on")
elseif string == "0" or string == "false" or string == "vanilla" or string == "off"
COM_BufInsertText(p, "analogsens off")
elseif string == nil
COM_BufInsertText(p, "analogsens off")
end
file:close()
end
end
end)
addHook("PostThinkFrame", do
for player in players.iterate
if player.mo
local mo = player.mo
local fixedmove = R_PointToAngle2(0, 0, mo.player.cmd.forwardmove*FRACUNIT, -mo.player.cmd.sidemove*FRACUNIT)
local angle = R_PointToAngle2(mo.x, mo.y, (mo.x+mo.momx), (mo.y+mo.momy))
local inputangle = angle + fixedmove
local angleo50 = ANG64h - ANG10 - ANG1
local angleo51 = ANG64h - ANG10 - ANG2 - ANG1 - ANG1 - ANG1
local diparate = 1 + 1/4
if player.momentumkillercounter == nil
player.momentumkillercounter = 0
end
if player.momentumkillercounter2 == nil
player.momentumkillercounter2 = 0
end
if player.momentumkillervar == nil
player.momentumkillervar = 0
end
if (not (P_IsObjectOnGround(player.mo)))
player.wallcounterc = false
end
if player.mo.skin ~= "adventuresonic"
or player.mo.skin ~= "modernsonic"
MomentumLimiter(mo,svr)
end
/*if MomentumLimiter(mo,svr) == true
player.momentumkillercounter = $ + 1
else
player.momentumkillercounter = 0
end
if player.momentumkillercounter == 1
player.momentumkillercounter2 = 18
else
player.momentumkillercounter2 = $ - 1
end*/
//Momentum killer
//I hate mom mods -_-
/*insert momentum actual killer here*/
if ((player.cmd.buttons & BT_ATTACK) or (player.cmd.buttons & BT_FIRENORMAL) or (player.cmd.buttons & BT_SPIN))
and player.mo.state == S_PLAY_ALLDRIFT
if player.cmd.sidemove < 0
player.drawangle = $ + ANG30
elseif player.cmd.sidemove > 0
player.drawangle = $ - ANG30
end
end
end
end
end)
Last edited: