GetEyeTrace | Creating a Breach SCP


if v:GetEyeTrace().Entity:GetNClass() == ROLE_SCP035

error
[ERROR] gamemodes/breach/gamemode/init.lua:217: attempt to call method ‘GetNClass’ (a nil value)

  1. unknown - gamemodes/breach/gamemode/init.lua:217

This is from me adding a new SCP to the game, the spawning, everything works but the timer witch allows me to check things.

Apparently over 12 files, there is a function called ply:GetNClass()
Have I set out the above properly?

[editline]16th February 2017[/editline]

The real problem is:
I dont know if I am using GetEyeTrace() properly.

[editline]16th February 2017[/editline]

This works


if v:Alive() and v:GetNClass() == ( ROLE_RES or ROLE_CLASSD ) then

You’re doing scriptfodder job again? Ok, i’ll try to not be an ass… Check if trace hits an entity then get its class


local ent = v:GetEyeTrace().Entity
if ent and ent:GetNClass() == ROLE_SCP035 then
   ...
end

Thanks! and I am just seeing how to add abilities to SCP’s.

[editline]16th February 2017[/editline]

By add I mean create my own breach characters then most likely when I figure it out make a forum about character creation.

If statements in GLua does not account for NULL.

Assuming that GetNClass is a method in the entity metatable of this addon/gamemode, this would be the function with correct validity checks:


local pEntity = v:GetEyeTrace().Entity

if (pEntity:IsValid() and pEntity:GetNClass() == ROLE_SCP035) then
   -- Code
end

[editline]16th February 2017[/editline]

Multiple check conditions cannot be done like that in Lua. Instead, you have to check each case individually:


if (v:Alive()) then
   local nClass = v:GetNClass()
   
   if (nClass == ROLE_RES or nClass == ROLE_CLASSD) then
      -- Code
   end
end

It now works acceptably, but error stays.
Anyway I can hide this, because it all works?

[editline]17th February 2017[/editline]


function GM:PlayerFootstep( ply, pos, foot, sound, volume, rf )
	if not ply.GetNClass then
		player_manager.RunClass( ply, "SetupDataTables" )
	end
	if not ply.GetNClass then return end
	if ply:GetNClass() == ROLE_SCP173 then
		if ply.steps == nil then ply.steps = 0 end
		ply.steps = ply.steps + 1
		if ply.steps > 6 then
			ply.steps = 1
			if SERVER then
				ply:EmitSound( "173sound"..math.random(1,3)..".ogg", 300, 100, 1 )
			end
		end
		return true
	end
	return false
end

From the breach gamemode…
shared.lua line 130, but it doesnt error but in init.lua its different.

[editline]17th February 2017[/editline]

I could try moving the items from init into shared?

[editline]17th February 2017[/editline]

Nope it errors because it dont work.

[editline]17th February 2017[/editline]

Full Code


 function GM:Think()
	for k,v in pairs( player.GetAll() ) do
		if v:Alive() and v:Team() == TEAM_SCI or TEAM_CLASSD then
			local ent = v:GetEyeTrace().Entity
		
			if ent and ent:GetNClass() == ROLE_SCP035 then
				print( v:Nick().." >> Stop, looking at me you faggot... " )
				v:Freeze( true )
				ent:SetWalkSpeed(120)
				ent:SetRunSpeed(240)
				ent:SetNWInt( "SCP_035_infected", 2 )
				timer.Create( "goodnight_SCP035", 3, 1, function()
					v:PrintMessage( HUD_PRINTTALK, "SCP_035: "..ent:Nick().." Just masked you, and has become CLASS D." )
					ent:SetWalkSpeed( 160 )
					ent:SetRunSpeed( 280 )
					ent:SetTeam( TEAM_CLASSD )
					ent:SetModel( "models/vinrax/player/035_player.mdl" )
					ent:Give("weapon_br_zombie")
					ent:SetHealth( 600 )
					v:Freeze(false)
					v:Kill()
					
					timer.Create( "wakeup_SCP035", 10, 0, function()
						
						for k,_ in pairs( player.GetAll() ) do
							if _:GetNWInt( "SCP_035_infected" ) == 2 then
								if _:Health() > 10 then
									_:SetHealth( _:Health() - 10 )
								else
									_:SetTeam(TEAM_SCP)
									_:SetModel("models/vinrax/player/035_player.mdl")
									_:SetHealth( 2000 )
									_:SetRunSpeed(10)
									_:SetMaxSpeed(10)
									_:SetNWInt( "SCP_035_infected", 1 ) 
								end
							end
						end
						
					end)
					
				end)
			end
		end
	end
end	

Oh my, that gamemode is poorly written. What is the exact error? What exactly are you trying to do?

Are you serious? I stated the error above!

[ERROR] gamemodes/breach/gamemode/init.lua:217: attempt to call method ‘GetNClass’ (a nil value)

  1. unknown - gamemodes/breach/gamemode/init.lua:217

that GetNClass is called numerous of times inside of this folder

[editline]17th February 2017[/editline]

Maybe its running to early. I found this:


if not ply.GetNClass then
		player_manager.RunClass( ply, "SetupDataTables" )
	end
        if not ply.GetNClass then return end

Oh, I thought you posted the gamemode code lol.

Reading over YOUR code, did you read what code_gs stated? “If statements in GLua does not account for NULL.” You need to check if the entity is valid using Entity:IsValid(). Your code does not currently do that.

Alright thanks.

[editline]17th February 2017[/editline]

Still doesnt work…

Please stop asking help with sf jobs, https://scriptfodder.com/jobs/view/15403 and i doubt its a coincidence u have also this guy in friends.

He’s getting paid to make facepunch threads asking for help for his job owner, it’s a new subcategory in SF jobs! :v:

Oh my god, why does no one ever understand.
ITS
NOT
A
JOB.

I don’t get paid for these things, I just like figuring them out, then showing other people.
I want both of you Swad and Steppu, with your 2 shitty lua minds together to make what I could never. Another SCP in the game, if you can do this, then it proves you can actually type these messages that have absolutely NO RELEVANCE to this conversation, with your banna man meme and smiley face, don’t ever reply again without finishing the project.

Oh and btw, I will pay you for this.
100 Rupee’s for this project. EACH.

[editline]17th February 2017[/editline]

As well, I have found that the error can/has been coming from reading the Entity.


	if (v:Alive()) then
		local nClass = v:GetNClass()
		if (nClass == ROLE_RES or nClass == ROLE_CLASSD) then
			local pEntity = v:GetEyeTrace().Entity

			if (pEntity:IsValid() and pEntity:GetNClass() == ROLE_SCP035) then

Alright.
So reading (player):GetNClass() works perfectly using player data.
But using “pEntity” or v:GetEyeTrace().Entity is not working because the entity is not being outputted right.
If I am correct, I need to define what the player is looking at before I define the function?
However I do this, I have no idea.
Any suggestions defining the Entity I am looking at?

What v:GetEyeTrace().Entity is currently outputting:
Entity [1][ Player [1] ] something like that, like its outputting a table?
Not being able to use the simpleness, of complicated outputs from the player.
I could try networking the player someone looks at? But that will be too confusing for the game, as that I mean: (Jacob looks at SCP035) Networked Jacob with a bit that he looked at that player. Then the table reads it, and if its SCP035 some shit happens. I have no idea.

Anyone know?


(User was banned for this post ("Flaming" - Hezzy))

hey you should split the money you’re going to make off of this with the people who spoonfed you ideas and potential solutions

Or atleast try learning lua, i doubt its so hard that it takes over 3 years to learn simple things (sf profile says he has over 3 years lua experience)

Well no one has really spoon fed me anything, because the current solutions don’t work.
So you can’t say much :frowning:

And this, is an error.
Not something you can just learn?
And yes I have had 3 years of lua experience.
Doesn’t me, that I “should” know why my gamemode edit is not working.
All I want is just help with getting what someone is looking at to player data, if you want to sound smart, why don’t you just give me it? Straight up, and Ill pay you both for the “money” I make off Scriptfodder.
100 Rupee = 1.49 USD
then I will give you both 74.5c each.

You will give us 1.5 dollars from 20? Doesnt sound like a good deal

Its not a job!
F@!# sake.

[editline]17th February 2017[/editline]

Look, I am going to give up.
You win.
You are truly, the dumbest person on facepunch.
I don’t want to fight with anyone on here.
I just want answers, sorry if you got off to a wrong start.
But flaming here is not useful, as all I wanted was help with the most simple erorr in all time.

How to get an ENTITY using GetEyeTrace, then using that entity in a function.

Player:GetEyeTrace

Ill just contact the owner of breach.
Thanks for not trying guys!
And thanks to the first 3 people actually contributing to the error.

[editline]17th February 2017[/editline]

Oh and we already tried this.
Nice try!
Have read, /\

I literally sent u the answer