Trying to fix the slot machines in Elevator: Source

Hey everyone,

So pretty much the Slot Machines on Elevator: Source are broken (at least for me they are). It’s probably a stupidly simple fix but I’m not very good with LUA myself so I have no idea on how to fix it.

The exact error (that repeats itself when you use the machine) is as follows:


[ERROR] gamemodes/elevator/entities/entities/slotmachine/init.lua:245: attempt to index local 'ply' (a nil value)
  1. SendPlaying - gamemodes/elevator/entities/entities/slotmachine/init.lua:245
   2. unknown - gamemodes/elevator/entities/entities/slotmachine/init.lua:183


Here is lines 159 to 206:


/*---------------------------------------------------------    
Initial Player Interaction
---------------------------------------------------------*/
function ENT:Use( ply )


    if !IsValid(ply) || !ply:IsPlayer() then
        return
    end
    
    if ( ply:GetBilliardTable() ) then
        GAMEMODE:PlayerMessage( ply, "Warning!", "You cannot play slots while you are in a billiards game.
You must quit your billiards game!" )
        return
    end
    
    if !self:IsInUse() then
        self:SetupVehicle()
    
        if !IsValid(self.chair) then return end -- just making sure...
    
        ply.SeatEnt = self.chair
        ply.EntryPoint = ply:GetPos()
        ply.EntryAngles = ply:EyeAngles()
        
        ply:EnterVehicle( self.chair )
        self:SendPlaying( ply ) -- An error occurs here.
    else
        return
    end
    
end


hook.Add( "PlayerLeaveVehicle", "ResetCollisionVehicle", function( ply )


    ply:SetCollisionGroup( COLLISION_GROUP_DEBRIS_TRIGGER )


end )


hook.Add( "CanPlayerEnterVehicle", "PreventEntry", function( ply, vehicle )


    if ( ply:GetBilliardTable() ) then
        GAMEMODE:PlayerMessage( ply, "Warning!", "You cannot play slots while you are in a billiards game.
You must quit your billiards game!" )
        return false
    end
    
    return true


end )



And here is lines 237 to 255


function ENT:SendPlaying()    
    if ( !IsValid( self ) || !IsValid(self.chair) ) then return end


    self.SlotsPlaying = self.chair:GetDriver():EntIndex()
    self.LastSpin = CurTime()
    
    local ply = self:GetPlayer()
    ply.SlotMachine = self -- Another error here!
    
    local rf = RecipientFilter()
    rf:AddPlayer( ply )
    
    umsg.Start("slotsPlaying", rf)
        umsg.Short( self:EntIndex() )
    umsg.End()
    
end


So yeah I can’t spot what the problem is because I don’t really know what I’m looking for or what to change and I would really like to see the slot machines work again, so any help will be much obliged!

[lua]function ENT:Use( ply )

self:SendPlaying( ply ) – Use() expects SendPlaying() to take a player argument…

end

function ENT:SendPlaying() – …when it actually doesn’t

local ply = self:GetPlayer() – and Use() didn’t store the player on the object, so GetPlayer() returns nil
ply.SlotMachine = self – and we try to index a field on an object that doesn’t exist
end[/lua]

Well, there’s your problem.

Judging by the mismatched methods of passing player objects around it seems like the SENT was in the middle of being edited and one function or the other never got updated.

umm I though i would say it here instead of making a new thread since this is the same problem i am having now. When you are explaining the problem do you have the solution on how i could get it to work just new to LUA like what function would i need to fix this.