Benny/gamemodes/benny/gamemode/player.lua

425 lines
9.9 KiB
Lua
Raw Permalink Normal View History

2024-03-07 21:19:30 -05:00
---------------------
-- Your Name is Benny
---------------------
function GM:PlayerInitialSpawn( ply, transiton )
if BennyGame:GetType() == BG_GTYPE_MP then
ply:SetTeam( BennyGame:BestAutoJoinTeam() )
else
ply:SetTeam( 7 )
end
end
2024-03-07 21:19:30 -05:00
function GM:PlayerSpawn( ply )
player_manager.SetPlayerClass( ply, "player_benny" )
2024-09-21 14:07:03 -04:00
ply:SetViewOffset( Vector( 0, 0, 52 ) )
ply:SetViewOffsetDucked( Vector( 0, 0, 52 ) )
2024-03-07 21:19:30 -05:00
ply:Give( "itemhandler" )
2024-09-20 16:20:22 -04:00
ply:Give( "goat_1" )
ply:Give( "goat_2" )
ply:Give( "goat_3" )
ply:Give( "goat_4" )
ply:Give( "goat_5" )
ply:Give( "goat_6" )
ply:Give( "goat_7" )
ply:Give( "goat_8" )
ply:Give( "goat_9" )
ply:Give( "goat_0" )
ply:SetActiveWeapon( ply:GetWeapon( "itemhandler" ) )
2024-03-07 21:19:30 -05:00
ply:SetStamina( 1 )
ply:SetCrouchedWalkSpeed( 0.3 )
ply:SetDuckSpeed( 0.1 )
ply:SetUnDuckSpeed( 0.1 )
ply:SetSlowWalkSpeed( 100 )
ply:SetWalkSpeed( 200 )
ply:SetRunSpeed( 200 )
ply:SetStepSize( 18 )
ply:SetCanZoom( false )
2024-04-06 09:30:09 -04:00
ply:SetHealth_Blood( 1000 )
ply:SetHealth_Stamina( 1000 )
2024-03-07 21:19:30 -05:00
ply:MakeCharacter()
end
function GM:PlayerPostThink( ply )
if ply:GetTouchedObjective():IsValid() then
if ply:GetTouchedObjectiveTime()+0.1 <= CurTime() then
ply:SetTouchedObjective( NULL )
end
end
end
2024-03-07 22:34:29 -05:00
function GM:PlayerNoClip()
return true
end
2024-03-07 21:19:30 -05:00
local PT = FindMetaTable( "Player" )
concommand.Add("b-cheat_setxp", function( ply, cmd, args )
if !ply or !ply:IsValid() then return end
ply:SetLevel_XP( args[1] )
end)
concommand.Add("b-cheat_rewardxp", function( ply, cmd, args )
if !ply or !ply:IsValid() then return end
ply:RewardXP( args[1] )
end)
function PT:RewardXP( amt )
if CLIENT then return end
--self.amountcollected = (self.amountcollected or 0) + amt
self:SetLevel_XP( self:GetLevel_XP() + amt )
--self:ChatPrint( "Rewarded " .. amt .. " XP" )
end
function PT:RewardScore()
if CLIENT then return end
end
2024-03-07 21:19:30 -05:00
local bgl = {
["benny"] = {
[0] = Vector( 0.275, 0.7, 0.7 ),
[1] = 17,
[2] = 7,
[3] = 2,
[4] = 11,
[5] = 3,
[6] = 0,
[7] = 0,
[8] = 3,
[9] = 0,
[10] = 0,
[11] = 0,
[12] = 3,
[13] = 0,
},
["nikki"] = {
[0] = Vector( 0.9, 0.3, 0.9 ),
[1] = 17,
[2] = 7,
[3] = 2,
[4] = 11,
[5] = 3,
[6] = 0,
[7] = 0,
[8] = 2,
[9] = 1,
[10] = 5,
[11] = 0,
[12] = 3,
[13] = 0,
},
["igor"] = {
[0] = Vector( 0.776, 0.929, 0.89 ),
[1] = 4,
[2] = 6,
[3] = 2,
[4] = 3,
[5] = 1,
[6] = 0,
[7] = 2,
[8] = 3,
[9] = 3,
[10] = 6,
[11] = 2,
[12] = 1,
[13] = 0,
},
["yanghao"] = {
[0] = Vector( 0.627, 0.21, 0.186 ),
[1] = 13,
[2] = 2,
[3] = 0,
[4] = 3,
[5] = 0,
[6] = 1,
[7] = 3,
[8] = 0,
[9] = 3,
[10] = 4,
[11] = 0,
[12] = 0,
[13] = 0,
},
["mp_cia"] = {
[0] = Vector( 1, 1, 1 )
},
["mp_plasof"] = {
[0] = Vector( 1, 1, 1 )
},
["mp_militia"] = {
[0] = Vector( 1, 1, 1 )
},
["mp_natguard"] = {
[0] = Vector( 1, 1, 1 )
},
["mp_viper"] = {
[0] = Vector( 1, 1, 1 )
},
["mp_halo"] = {
[0] = Vector( 1, 1, 1 )
},
}
function PT:MakeCharacter()
local char = "benny"
2024-04-06 09:30:09 -04:00
--self:SetModel( "models/player/infoplayerrealism.mdl" )
self:SetModel( "models/benny/player/benny_placeholder3.mdl" )
--self:SetPlayerColor( bgl[char][0] )
--self:SetBodygroup( 0, 0 )
--self:SetSkin( 3 )
--for i, v in ipairs( bgl[char] ) do
-- self:SetBodygroup( i, v )
--end
2024-03-07 21:19:30 -05:00
end
2024-03-12 18:43:31 -04:00
function PT:HandlerCheck()
2024-03-07 21:19:30 -05:00
local wep = self:GetActiveWeapon()
return ( wep:IsValid() and wep:GetClass() == "itemhandler" and wep.GetActiveR ) and wep or false
end
2024-03-23 21:18:11 -04:00
-- Temporary
function GM:UpdateAnimation( ply, vel, maxseqgroundspeed )
2024-04-06 09:30:09 -04:00
ply:SetPlaybackRate( 1 )
local normal = vel:GetNormalized()
local len2d = vel:Length2D()
normal:Rotate( Angle( 0, -ply:EyeAngles().y, 0 ) )
2024-04-07 19:04:18 -04:00
local speed = (len2d/200)
2024-08-30 18:30:03 -04:00
--print( string.format( "x: %G, y: %G", normal.x, normal.y ))
local biggerone = math.max( math.abs(normal.x), math.abs(normal.y) )
local needer = 1+((1-biggerone)/biggerone)
normal.x = normal.x * needer
normal.y = normal.y * needer
local diveend = ply:GetLayerSequence( GESTURE_SLOT_JUMP ) == ply:LookupSequence("dive_end_handgun")
local divestart = ply:GetLayerSequence( GESTURE_SLOT_JUMP ) == ply:LookupSequence("dive_start_handgun")
if ply:GetInDive() or diveend then speed = 1 end
2024-04-07 19:04:18 -04:00
ply:SetPoseParameter( "move_x", normal.x * speed )
ply:SetPoseParameter( "move_y", normal.y * speed )
2024-04-06 09:30:09 -04:00
2024-08-30 18:30:03 -04:00
local magic = ply:EyeAngles().y
magic = -(magic - ply:GetRenderAngles().y)
--magic = magic % 180
if magic < -180 then
magic = magic + 360
elseif magic > 180 then
magic = magic - 360
end
magic = magic * 0.75
ply:SetPoseParameter( "aim_p", -ply:EyeAngles().p/90 )
ply:SetPoseParameter( "aim_y", 0 )--magic/90 )
ply:SetAllowFullRotation( false )
--ply:SetAngles( Angle( 0, ply:EyeAngles().y, 0 ) )
ply:SetRenderAngles( Angle( 0, ply:EyeAngles().y, 0 ) )
if diveend then
local magicnumber = ply:GetLayerCycle( GESTURE_SLOT_JUMP )
magicnumber = math.Remap( magicnumber, 0.5, 0.75, 1, 0 )
magicnumber = math.Clamp( magicnumber, 0, 1 )
ply:AnimSetGestureWeight( GESTURE_SLOT_JUMP, magicnumber )
elseif divestart then
local magicnumber = ply:GetLayerCycle( GESTURE_SLOT_JUMP )
magicnumber = math.Remap( magicnumber, 0.1, 0.6, 1, 0 )
magicnumber = math.Clamp( magicnumber, 0, 1 )
ply:AnimSetGestureWeight( GESTURE_SLOT_JUMP, magicnumber )
else
ply:AnimSetGestureWeight( GESTURE_SLOT_JUMP, 1 )
end
2024-04-06 09:30:09 -04:00
--local dir = ply:GetVelocity():GetNormalized()
--local dira
--if dir:IsZero() or ply:GetVelocity():Length2D() < 50 then
-- dira = ply:EyeAngles().y
--else
-- dira = dir:Angle().y
--end
--ply:SetAngles( Angle( 0, dira, 0 ) )
end
ANIM_IDLE = 0
ANIM_IDLE_RIFLE = 1
ANIM_IDLE_DUCK = 2
ANIM_RUN = 3
ANIM_RUN_RIFLE = 4
2024-03-23 21:18:11 -04:00
2024-04-06 09:30:09 -04:00
local Animations = {
["idle"] = {
["none"] = "idle",
["handgun"] = "idle_handgun",
["rifle"] = "idle_rifle",
},
["run"] = {
["none"] = "run",
["handgun"] = "run_handgun",
["rifle"] = "run_rifle",
},
}
function GM:CalcMainActivity( ply, velocity )
local plyTable = ply:GetTable()
plyTable.CalcIdeal = -1
local w = ply:HandlerCheck()
local wpntype = "none"
if w then
if w:ItemR() and w:ItemR().Class.HoldType then
wpntype = w:ItemR().Class.HoldType
end
end
plyTable.CalcSeqOverride = ply:LookupSequence( Animations["idle"][wpntype] )
if ply:Crouching() then
plyTable.CalcSeqOverride = ply:LookupSequence( "idle_duck" )
2024-03-23 21:18:11 -04:00
end
2024-04-06 09:30:09 -04:00
self:HandlePlayerLanding( ply, velocity, plyTable.m_bWasOnGround )
if true or !( self:HandlePlayerNoClipping( ply, velocity, plyTable ) ||
self:HandlePlayerDriving( ply, plyTable ) ||
self:HandlePlayerVaulting( ply, velocity, plyTable ) ||
self:HandlePlayerJumping( ply, velocity, plyTable ) ||
self:HandlePlayerSwimming( ply, velocity, plyTable ) ||
self:HandlePlayerDucking( ply, velocity, plyTable ) ) then
local len2d = velocity:Length2D()
if ( len2d > 10 ) then plyTable.CalcSeqOverride = ply:LookupSequence( Animations["run"][wpntype] ) end
2024-03-23 21:18:11 -04:00
end
2024-04-07 19:04:18 -04:00
if ply:GetInDive() then
2024-08-30 18:30:03 -04:00
plyTable.CalcSeqOverride = ply:LookupSequence( "dive_idle_handgun" )
2024-04-07 19:04:18 -04:00
end
2024-03-23 21:18:11 -04:00
2024-04-06 09:30:09 -04:00
plyTable.m_bWasOnGround = ply:IsOnGround()
plyTable.m_bWasNoclipping = ( ply:GetMoveType() == MOVETYPE_NOCLIP && !ply:InVehicle() )
return plyTable.CalcIdeal, plyTable.CalcSeqOverride
2024-03-23 21:18:11 -04:00
end
function GM:HandlePlayerJumping( ply, vel )
return false
end
function GM:HandlePlayerVaulting( ply, vel )
return false
end
function GM:HandlePlayerLanding( ply, vel, onground )
return false
end
function GM:HandlePlayerNoClipping( ply, vel )
return false
2024-04-06 09:30:09 -04:00
end
hook.Add( "EntityTakeDamage", "EntityDamageExample", function( target, dmginfo )
if target:IsPlayer() then
dmginfo:ScaleDamage( 0 )
end
end )
if CLIENT then
hook.Add("CreateMove", "Benny_CreateMove_Controls", function( cmd )
if !gui.IsGameUIVisible() then
if input.IsButtonDown( KEY_E ) then
cmd:AddKey( IN_WEAPON1 )
end
if input.IsButtonDown( KEY_Q ) then
cmd:AddKey( IN_WEAPON2 )
end
if input.IsButtonDown( KEY_C ) then
cmd:AddKey( IN_GRENADE1 )
end
if input.IsButtonDown( KEY_Z ) then
cmd:AddKey( IN_GRENADE2 )
end
if input.IsButtonDown( KEY_R ) then
cmd:AddKey( IN_ALT1 )
end
if input.IsButtonDown( KEY_T ) then
cmd:AddKey( IN_ALT2 )
end
if input.IsButtonDown( KEY_X ) then
cmd:AddKey( IN_BULLRUSH )
end
2024-04-06 09:30:09 -04:00
end
end)
end
hook.Add("Move", "Benny_Move", function( ply, mv )
2024-04-07 19:04:18 -04:00
if mv:KeyDown( IN_SPEED ) and !ply:GetInDive() and (ply:GetDivedAt() + 0.5 <= CurTime()) then
2024-04-06 09:30:09 -04:00
local cool = Vector( mv:GetForwardSpeed(), -mv:GetSideSpeed(), 0 )
cool:Normalize()
cool:Rotate( Angle( 0, mv:GetMoveAngles().y, 0 ) )
cool:Mul( 250 )
cool.z = 150
mv:SetVelocity( cool )--(Angle( -30, ply:EyeAngles().y, 0 ):Forward()*250) )
ply:SetGroundEntity( NULL )
ply:SetInDive( true )
ply:SetDivedAt( CurTime() )
if SERVER or CLIENT and IsFirstTimePredicted() then
ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_JUMP, ply:LookupSequence( "dive_start_handgun" ), 0, true )
end
2024-04-06 09:30:09 -04:00
if (SERVER) or (CLIENT and IsFirstTimePredicted()) then
local rfil = nil
if SERVER then
rfil = RecipientFilter()
rfil:AddPAS(ply:GetPos())
rfil:RemovePlayer( ply )
end
ply:EmitSound("weapons/slam/throw.wav", 70, 100, .25, nil, nil, nil, rfil)
end
end
if ply:OnGround() and ply:GetInDive() then
if (SERVER) or (CLIENT and IsFirstTimePredicted()) then
local rfil = nil
if SERVER then
rfil = RecipientFilter()
rfil:AddPAS(ply:GetPos())
rfil:RemovePlayer( ply )
end
ply:EmitSound("npc/combine_soldier/gear1.wav", 70, 100, .25, nil, nil, nil, rfil)
end
ply:SetInDive(false)
2024-04-07 19:04:18 -04:00
ply:SetDivedAt( CurTime() )
if SERVER or CLIENT and IsFirstTimePredicted() then
ply:AddVCDSequenceToGestureSlot( GESTURE_SLOT_JUMP, ply:LookupSequence( "dive_end_handgun" ), 0, true )
end
2024-08-30 18:30:03 -04:00
mv:SetVelocity( mv:GetVelocity() + Vector( 0, 0, 120 ) )
ply:SetGroundEntity( NULL )
2024-04-06 09:30:09 -04:00
end
2024-04-07 19:04:18 -04:00
--if !ply:OnGround() and ply:GetInDive() then
-- local da = ply:GetDivedAt()
-- local supertime = math.Remap( CurTime(), da + 0.5, da + 1, 300, 0 )
-- supertime = math.Clamp( supertime, 0, 300 )
-- local vel = mv:GetVelocity()
-- vel.z = vel.z + supertime*FrameTime()
-- mv:SetVelocity( vel )
--end
2024-04-06 09:30:09 -04:00
end)