bad argument #2 to 'HeadPos' (number expected, got nil)
17 replies, posted
Hey guys, I have been trying to make some ESP for fun for my build server, But I have been getting some LUA Errors
The error is
[ERROR] lua/kittix.lua:130: bad argument #2 to 'HeadPos' (number expected, got nil)
1. HeadPos - [C]:-1
2. Visible - lua/kittix.lua:130
3. fn - lua/kittix.lua:190
4. unknown - addons/ulib/lua/ulib/shared/hook.lua:183
When i turn on my ESP/Health and Skeletons.
[CODE]local function HeadPos(ply)
if ValidEntity(ply) then
local hbone = ply:LookupBone("ValveBiped.Bip01_Head1")
return ply:GetBonePosition(hbone)
else return end
end
local function Visible(ply)
local trace = {start = LocalPlayer():GetShootPos(),endpos = HeadPos(ply),filter = {LocalPlayer(), ply}}
local tr = util.TraceLine(trace)
if tr.Fraction == 1 then
return true
else
return false
end
end
local function IsSteamFriend( ply )
return ply:GetFriendStatus() == "friend"
end
local function FillRGBA(x,y,w,h,col)
surface.SetDrawColor( col.r, col.g, col.b, col.a );
surface.DrawRect( x, y, w, h );
end
local function OutlineRGBA(x,y,w,h,col)
surface.SetDrawColor( col.r, col.g, col.b, col.a );
surface.DrawOutlinedRect( x, y, w, h );
end
local function DrawCrosshair()
local w = ScrW() / 2;
local h = ScrH() / 2;
FillRGBA( w - 5, h, 11, 1, Color( 0, 255, 0, 255 ) );
FillRGBA( w, h - 5, 1, 11, Color( 0, 255, 0, 255 ) );
end
function DrawESP()
if GetConVarNumber( "Kittix_ESP_Main" ) >= 1 then
for k, v in pairs(ents.GetAll()) do
if( ValidEntity(v) and v ~= LocalPlayer() ) then
if( v:IsNPC() ) then
local drawColor = Color(255, 255, 255, 255);
local drawPosit = v:GetPos():ToScreen();
if( Visible(v) ) then
drawColor = Color( 0, 255, 0, 255 );
else
drawColor = Color( 255, 0, 0, 255 );
end
local textData = {}
textData.pos = {}
textData.pos[1] = drawPosit.x;
textData.pos[2] = drawPosit.y;
textData.color = drawColor;
textData.text = v:GetClass();
textData.font = "ESPFont";
textData.xalign = TEXT_ALIGN_CENTER;
textData.yalign = TEXT_ALIGN_CENTER;
draw.Text( textData );
elseif( v:IsPlayer() and v:Health() > 0 and v:Alive() ) then
local drawColor = Color( 0, 255, 0, 255 )
local drawPosit = v:GetPos():ToScreen();
if( Visible(v) ) then
drawColor.a = 255;
else
drawColor.r = 255 - drawColor.r;
drawColor.g = 0 - drawColor.g;
drawColor.b = 0 - drawColor.b;
end
local textData = {}
textData.pos = {}
textData.pos[1] = drawPosit.x;
textData.pos[2] = drawPosit.y;
textData.color = drawColor;
textData.text = v:GetName();
textData.font = "ESPFont";
textData.xalign = TEXT_ALIGN_CENTER;
textData.yalign = TEXT_ALIGN_CENTER;
draw.Text( textData );
local max_health = 100;
if( v:Health() > max_health ) then
max_health = v:Health();
end
local mx = max_health / 1.3;
local mw = v:Health() / 1.3;
local drawPosHealth = drawPosit;
drawPosHealth.x = drawPosHealth.x - ( mx / 2 );
drawPosHealth.y = drawPosHealth.y + 15;
FillRGBA( drawPosHealth.x - 1, drawPosHealth.y - 1, mx + 2, 3 + 2, Color( 0, 0, 0, 255 ) );
FillRGBA( drawPosHealth.x, drawPosHealth.y, mw, 3, drawColor );
end
end
end
end
end
function DrawXHair()
DrawCrosshair();
end
hook.Add( "HUDPaint", "DrawESP", DrawESP );
hook.Add( "HUDPaint", "DrawXHair", DrawXHair );[/CODE]
That is s0biets esp modified by me, if anyone could help that would be good. Thanks for reading
Ive never heard of a headpos function and for whatever reason but here, quit using that and use this to get headpos
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index22b6.html[/url]
Read the example.
[editline]17th August 2014[/editline]
Ugh. My phone is so difficult to work with. Im done editing that post. Replace your locsl function contents with the example contents in the link I provided
[QUOTE=LauScript;45717495]Ive never heard of a headpos function and for whatever reason but here, quit using that and use this to get headpos
[url]http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index22b6.html[/url]
Read the example.
[editline]17th August 2014[/editline]
Ugh. My phone is so difficult to work with. Im done editing that post. Replace your locsl function contents with the example contents in the link I provided[/QUOTE]
I replaced the original bonepos thing with [CODE]local function HeadPos( ply, cmd, arg )
local BoneIndx = ply:LookupBone("ValveBiped.Bip01_Head1")
local BonePos , BoneAng = ply:GetBonePosition( BoneIndx )
ply:PrintMessage( HUD_PRINTCONSOLE , "HeadPos = ".. tostring(BonePos) .."HeadAng = ".. tostring(BoneAng) )
end[/CODE]
and now im getting
[ERROR] lua/kittix.lua:123: bad argument #1 to 'GetBonePosition' (number expected, got nil)
1. GetBonePosition - [C]:-1
2. HeadPos - lua/kittix.lua:123
3. Visible - lua/kittix.lua:127
4. fn - lua/kittix.lua:187
5. unknown - addons/ulib/lua/ulib/shared/hook.lua:183
which is at this line [CODE]local BonePos , BoneAng = ply:GetBonePosition( BoneIndx )[/CODE]
Get rid of the printmessage line and do
return BonePos;
[editline]17th August 2014[/editline]
And remove the cmd and args arguments those are for console commands
[QUOTE=LauScript;45717588]Get rid of the printmessage line and do
return BonePos;
[editline]17th August 2014[/editline]
And remove the cmd and args arguments those are for console commands[/QUOTE]
I did that, It still does
[ERROR] lua/kittix.lua:273: bad argument #1 to 'GetBonePosition' (number expected, got no value)
1. GetBonePosition - [C]:-1
2. Skeleton - lua/kittix.lua:273
3. fn - lua/kittix.lua:282
4. unknown - addons/ulib/lua/ulib/shared/hook.lua:183
for some reason :(
local BoneIndx = ply:LookupBone("ValveBiped.Bip01_Head1")
returns nil because ply doesn't have that bone.
[editline]17th August 2014[/editline]
From that
local BonePos , BoneAng = ply:GetBonePosition( BoneIndx )
errors, because it expects a number, but gets nil value
[QUOTE=Robotboy655;45717638]local BoneIndx = ply:LookupBone("ValveBiped.Bip01_Head1")
returns nil because ply doesn't have that bone.
[editline]17th August 2014[/editline]
From that
local BonePos , BoneAng = ply:GetBonePosition( BoneIndx )
errors, because it expects a number, but gets nil value[/QUOTE]
How would I fix that?
Stop trying to lookup non existent bones.
[QUOTE=Robotboy655;45717663]Stop trying to lookup non existent bones.[/QUOTE]
What about ValveBiped.Bip01_Neck1?
I don't know, make sure the model "ply" uses has those bones and make sure ply is valid by doing IsValid( ply ) before attempting to get its bone.
ValveBiped.Bip01_Head1 does infact exist on player models, if your ply is a player, make sure it is valid first.
[QUOTE=Robotboy655;45717698]I don't know, make sure the model "ply" uses has those bones and make sure ply is valid by doing IsValid( ply ) before attempting to get its bone.
ValveBiped.Bip01_Head1 does infact exist on player models, if your ply is a player, make sure it is valid first.[/QUOTE]
Is there any way I can fix this to work with every model?
Use a different bone.
Or dont use bones at all (doit)
[QUOTE=LauScript;45717828]Use a different bone.
Or dont use bones at all (doit)[/QUOTE]
I don't know how ;_;
There Is a few ways. Why does it have to be there head?
[QUOTE=LauScript;45718006]There Is a few ways. Why does it have to be there head?[/QUOTE]
I don't know, Like I said I used s0biet's esp thing from 2009
I mean unless it's an aimbot idk what you would need it for
[QUOTE=LauScript;45718231]I mean unless it's an aimbot idk what you would need it for[/QUOTE]
[CODE]local function HeadPos( ply )
IsValid( ply )
local BoneIndx = ply:LookupAttachment("eyes")
local BonePos , BoneAng = ply:GetBonePosition( BoneIndx )
return BonePos;
end[/CODE]
I think its working, now i need to fix skeletons
Should be if ( isvalid ) then ..... end
But yes.
Sorry, you need to Log In to post a reply to this thread.