• trying to get players position
    10 replies, posted
trying to see if a player is within 10 of a certain coord but i get the error "attempt to call field 'GetPos' <a nil value> any clue as to how to get this to work? any and all help is appreciated. [code] pistachio.command:Create("scavenge", "", "Scavenge an area for items.", function(client, arguments) local pos1 = Vector(2258.769043,5173.314941,-131.968750) // boxes local ClosestDistance = 10 local Distance = player.GetPos():Distance(pos1) if (client:GetPrivateVar("karma") >= 1) then if (Distance < ClosestDistance) then client:ChatPrint("Scavenging...") client:Freeze(true) timer.Simple(5, function() local RandAmount = math.floor(math.Rand(1,3)) if(RandAmount == 1) then local RandAmount2 = math.floor(math.Rand(1,5)) client:AddMoney(RandAmount2); client:ChatPrint("You can't gather that!") end; if(RandAmount == 2) then client:AddItem("weapon_pickaxe") client:ChatPrint("You found a pickaxe!") end; if(RandAmount == 3) then client:Health(-5); client:ChatPrint("A rabid mouse bit your hand!") end; client:Freeze(false) end) else client:ChatPrint("You are not near the scavenging area") end; else client:Notify("You dont have enough Karma!"); end; end); [/code]
player[b].[/b]GetPos()
I tried using that
[QUOTE=FrankPetrov;40239161]I tried using that[/QUOTE] That's what's wrong. You're trying to access a metatable function directly. Use player:GetPos()
so what should i change "local Distance = player.GetPos():Distance(pos1)" to? i need it to check if a player is within so far of the area. I'm not only trying to get the player's position... Sorry if i'm seeming stupid about this, your words are just too vague to me.
[QUOTE=FrankPetrov;40239327]so what should i change "local Distance = player.GetPos():Distance(pos1)" to? i need it to check if a player is within so far of the area. I'm not only trying to get the player's position... Sorry if i'm seeming stupid about this, your words are just too vague to me.[/QUOTE] player:GetPos(), not player.GetPos()
[QUOTE=FrankPetrov;40239327]so what should i change "local Distance = player.GetPos():Distance(pos1)" to? i need it to check if a player is within so far of the area. I'm not only trying to get the player's position... Sorry if i'm seeming stupid about this, your words are just too vague to me.[/QUOTE] I told you. player:GetPos() instead of player.GetPos() The difference is that lua automatically sets the "self" variable when you use a colon. It's Syntactic sugar for: player.GetPos(player)
[QUOTE=NightmareX91;40239401]player:GetPos(), not player.GetPos()[/QUOTE] still says its a nil value though
[QUOTE=FrankPetrov;40239435]still says its a nil value though[/QUOTE] It's because 'player' isn't declared. You have 'client' as an argument, but used 'player' instead.
player.GetPos doesn't exist. client:GetPos().
Awesome. got it to work thanks a lot everyone!
Sorry, you need to Log In to post a reply to this thread.