Hey there,
I got the problem that the game crashes on that line(shared.lua):
[CODE]if( ply:GetEyeTrace().Entity:IsPlayer() == true) then[/CODE]
I was changing some code and it just started. - It did not crash before. - What's wrong there?
If I delete that line it crashes on
[CODE]
local aply = ply:GetEyeTrace().Entity
if ( aply:GetPos():Distance(ply:GetPos()) < 70 ) then[/CODE]
Thanks,
DasNeo.
[QUOTE=DasNeo;45368775]If I delete that line it crashes on
[CODE]
local aply = ply:GetEyeTrace().Entity
if ( aply:GetPos():Distance(ply:GetPos()) < 70 ) then[/CODE]
[/QUOTE]
Then what?
What do you mean?
what code is there after the then
print("blub")
It does not print.
Define "crashes". Does the game close completely? Does a message appear?
It stops responding. Will the full code maybe help more?
[QUOTE=DasNeo;45370170]It stops responding. Will the full code maybe help more?[/QUOTE]
Maybe. It sound like you're doing something that breaks GetEyeTrace.
[editline]12th July 2014[/editline]
Actually, GetEyeTrace is coded in Lua, so therefore it shouldn't be able to crash like this.
[QUOTE=DasNeo;45370170]It stops responding. Will the full code maybe help more?[/QUOTE]
Yes.
[code]function sendTraitor( ply, aply, optn )
if( optn == 1 ) then
ply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle.")
aply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle.")
elseif ( optn == 2 ) then
ply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle..")
aply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle..")
elseif ( optn == 3 ) then
ply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle...")
aply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle...")
elseif ( optn == 4 ) then
ply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle....")
aply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle....")
willBreak = true
rcSucc = true
end
end
function SWEP:PrimaryAttack()
print("Test01")
IsinRange = false
rcSucc = false
willBreak = false
local ply = self.Owner
self.Weapon:EmitSound( Sound( "sound/ambient/town_child_scream1.wav" ) )
self.Weapon:SetNextPrimaryFire(CurTime()+(self.Primary.Delay))
print("Test02")
if( ply:GetEyeTrace().Entity:IsPlayer() == true) then // Here it's crashing
print("Test03")
local aply = ply:GetEyeTrace().Entity
if ( aply:GetPos():Distance(ply:GetPos()) < 70 ) then // Or here if I delete the other line
print("Test04")
if(aply:GetRole() != ROLE_TRAITOR) then
print("Test05")
ply:PrintMessage(HUD_PRINTTALK,"Aendere Rolle")
print("Test06")
timer.Simple(.5, sendTraitor, ply, aply, 1)
print("Test07")
timer.Simple(1, sendTraitor, ply, aply, 2)
print("Test08")
timer.Simple(1.5, sendTraitor, ply, aply, 3)
print("Test09")
timer.Simple(2, sendTraitor, ply, aply, 4)
while(aply:GetPos():Distance(ply:GetPos()) < 70) do
if( !IsinRange ) then
IsinRange = true
end
if ( willBreak == true ) then
break;
end
end
if ( willBreak == false ) then
rcSucc = false
IsinRange = false
end
if( rcSucc == true) then
aply:PrintMessage(HUD_PRINTTALK, "Du bist nun Traitor!")
aply:SetRole(ROLE_TRAITOR)
SendFullStateUpdate()
aply:AddCredits(GetConVarNumber("ttt_credits_starting"))
self:Remove()
end
end
end
end
end[/code]
There's more on the top but I guess it doesn't matter since it's just some SWEP-Stuff.
Sorry about the late response. Ply does not exist in the context you are using it. What is interesting is that it should be erroring about Ply being nil and that GetEyeTrace doesnt exist and so on. You also do not need the :IsPlayer() == true, since if its true, it will evaluate to true, so you have a bit of redundancy there.
That statement should be:
[code]
local tr = self.Owner:GetEyeTrace();
if (IsValid(tr.Entity) && tr.Entity:IsPlayer()) then
[/code]
Why does Ply not exist? local ply = self.Owner
Will your Code fix the problem? It worked before with my code but does not now.. :|
Thanks so far,
DasNeo.
Oh sorry I didn't see that.
I also noticed several problems with your code (some unrelated to this issue). timer.Simple does not take vararg anymore, also your while loop appears to be crashing your game.
You are also declaring "willBreak" to be false, but never setting it to true, then comparing it.
"timer.Simple does not take vararg anymore"
What do you mean? - Can't I give arguments with timer.Simple?
I'm setting "willBreak" true in the Timer.
But why didn't it print "Test03", "Test04" and so on? - It stopped before it could print taht.
The syntax for timer.Simple is (time, callback). You can no longer pass function parameters to timers you must make a new temporary function which calls your function with the correct parameters.
Your while loop is causing your SWEP to stop. It will run WHILE you are within a certain distance. Just a guess, but if you use this SWEP when you are far away from a player but still looking at them, this SWEP should not crash the server.
"The syntax for timer.Simple is (time, callback). You can no longer pass function parameters to timers you must make a new temporary function which calls your function with the correct parameters."
Hm, I don't really understand that. - Could you make an example?
Things like this:
[code]
timer.Simple(2, sendTraitor, ply, aply, 4)
[/code]
Are now:
[code]
timer.Simple(2, function() sendTraitor(ply, aply, 4) end)
[/code]
So far so good!
It works. - But there're a few things that are goin' wrong.
1. It spams every text 4 times and ply is getting the Message from aply (the last one).
[code]
function sendTraitor( ply, aply, optn )
if( optn == 1 and aply:GetPos():Distance(ply:GetPos()) < 70) then
ply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle.")
aply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle.")
elseif ( optn == 2 and aply:GetPos():Distance(ply:GetPos()) < 70) then
ply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle..")
aply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle..")
elseif ( optn == 3 and aply:GetPos():Distance(ply:GetPos()) < 70 ) then
ply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle...")
aply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle...")
elseif ( optn == 4 and aply:GetPos():Distance(ply:GetPos()) < 70) then
ply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle....")
aply:PrintMessage(HUD_PRINTTALK, "Ändere Rolle....")
aply:PrintMessage(HUD_PRINTTALK, "Du bist nun Traitor!")
aply:SetRole(ROLE_TRAITOR)
SendFullStateUpdate()
local colRed = Color(255,0,0,255)
aply:SetColor( colRed )
ply:SetColor( colRed )
timer.Simple(5, function() sendTraitor(ply, aply, 5) end)
self:Remove()
elseif ( optn == 5 ) then
local colNorm = Color(0,0,0,255)
ply:SetColor( colNorm )
aply:SetColor( colNorm )
end
end
function SWEP:PrimaryAttack()
local ply = self.Owner
self.Weapon:EmitSound( Sound( "sound/ambient/town_child_scream1.wav" ) )
self.Weapon:SetNextPrimaryFire(CurTime()+(self.Primary.Delay))
local tr = self.Owner:GetEyeTrace()
if (IsValid(tr.Entity) && tr.Entity:IsPlayer()) then
local aply = tr.Entity
if ( aply:GetPos():Distance(ply:GetPos()) < 70 ) then
if(aply:GetRole() != ROLE_TRAITOR) then
ply:PrintMessage(HUD_PRINTTALK,"Aendere Rolle")
timer.Simple(.5, function() sendTraitor(ply, aply, 1) end)
timer.Simple(1, function() sendTraitor(ply, aply, 2) end)
timer.Simple(1.5, function() sendTraitor(ply, aply, 3) end)
timer.Simple(2, function() sendTraitor(ply, aply, 4) end)
end
end
end[/code]
2. The Timer in sendTraitor is not working and it's saying that "SendFullStateUpdate()" is a nil value
[spoiler]
Aendere Rolle
Aendere Rolle
Aendere Rolle
Aendere Rolle
Ändere Rolle.
Ändere Rolle.
Ändere Rolle.
Ändere Rolle.
Ändere Rolle.
Ändere Rolle.
Ändere Rolle.
Ändere Rolle..
Ändere Rolle..
Ändere Rolle..
Ändere Rolle..
Ändere Rolle..
Ändere Rolle..
Ändere Rolle..
Ändere Rolle...
Ändere Rolle...
Ändere Rolle...
Ändere Rolle...
Ändere Rolle...
Ändere Rolle...
Ändere Rolle...
Ändere Rolle....
[/spoiler]
You are: TRAITOR
Ändere Rolle....
Ändere Rolle....
Du bist nun Traitor!
[ERROR] addons/rolechanger/lua/weapons/weapon_ttt_rolechanger/shared.lua:67: attempt to call global 'SendFullStateUpdate' (a nil value)
1. sendTraitor - addons/rolechanger/lua/weapons/weapon_ttt_rolechanger/shared.lua:67
2. unknown - addons/rolechanger/lua/weapons/weapon_ttt_rolechanger/shared.lua:93
Timer Failed! [Simple][@addons/rolechanger/lua/weapons/weapon_ttt_rolechanger/shared.lua (line 93)]
Ändere Rolle....
Ändere Rolle....
Du bist nun Traitor!
[ERROR] addons/rolechanger/lua/weapons/weapon_ttt_rolechanger/shared.lua:67: attempt to call global 'SendFullStateUpdate' (a nil value)
1. sendTraitor - addons/rolechanger/lua/weapons/weapon_ttt_rolechanger/shared.lua:67
2. unknown - addons/rolechanger/lua/weapons/weapon_ttt_rolechanger/shared.lua:93
Timer Failed! [Simple][@addons/rolechanger/lua/weapons/weapon_ttt_rolechanger/shared.lua (line 93)]
Ändere Rolle....
Ändere Rolle....
Du bist nun Traitor!
[ERROR] addons/rolechanger/lua/weapons/weapon_ttt_rolechanger/shared.lua:67: attempt to call global 'SendFullStateUpdate' (a nil value)
1. sendTraitor - addons/rolechanger/lua/weapons/weapon_ttt_rolechanger/shared.lua:67
2. unknown - addons/rolechanger/lua/weapons/weapon_ttt_rolechanger/shared.lua:93
Timer Failed! [Simple][@addons/rolechanger/lua/weapons/weapon_ttt_rolechanger/shared.lua (line 93)]
Thanks,
DasNeo! C:
It's writing the text 4 times because you are calling the function 4 times. Also:
[code]
function SWEP:PrimaryAttack()
if (CLIENT) then return; end
[/code]
You're the best!
Thanks! C:
Sorry, you need to Log In to post a reply to this thread.