For some reason, this:
[lua]
function ENT:UpdatePos( currentPlayer )
self:SetPos( currentPlayer:GetShootPos() + currentPlayer:GetAimVector() * 50 )
end
concommand.Add( "UpdateEntPos", function( currentPlayer ) ENT:UpdatePos( currentPlayer ) end )
[/lua]
gives me this error:
attempt to index global 'ENT' (a nil value)[entities\ia_item\cl_init.lua:16] attempt to index global 'ENT' (a nil value)
I am calling the console command on the server like this:
RunConsoleCommand( "UpdateEntPos", self.currentPlayer)
Any help would be good.
Are you trying to make the player move to this position? Or make an Entity move a player to this position?
make the entity move to this position.
currentPlayer is stored in a serverside script. I need to get currentPlayer to the clientside script above so that I can move the entity to the position provided.
Is ENT defined as a metatable?
Also I'm fairly certain that even if the syntax is perfect, entity:SetPos() isn't a clientside function, nor would it work that way. Why does this have to be done clientside?
It is a shared function I think, when I have that code there it doesn't lag as much as it does if I setPos on the server. and no ENT is not a metatable.
What you're trying to do won't work Duskling, use DTVars.
I have found this:
[url]http://bananatree.im/wiki/wiki.garrysmod.com/indexe043-2.html?title=Entity.DTVar[/url]
and I think I understand, but how would I make a DTVar that stores the player?
[editline]19th March 2012[/editline]
I seem to have figured something out, but it isn't working.
serverside ent:
[lua]
function ENT:Think()
if self.pickedUp == true then
self:SetNWBool( "entPickedUp", true )
self:SetDTVector(0,self.currentPlayer:GetShootPos() + self.currentPlayer:GetAimVector() * 50)
self:GetPhysicsObject():EnableGravity( false )
self:GetPhysicsObject():EnableMotion( false )
end
end
[/lua]
client ent:
[lua]
function ENT:Think()
print(self:GetDTVector(0))
if( self:GetNWBool("entPickedUp") ) then
print("picked up")
self:UpdatePos( self:GetDTVector(0) )
end
end
function ENT:UpdatePos( playerVector )
self:SetPos( playerVector )
end
[/lua]
the client is indeed moving the object, but the 2 problems still exist:
1. It is lagging again.
2. If one player picks it up, all players on the server are holding it.
Bump?
read the DTVar thread you supplied.
Read every word.
I used DTVector instead of DTVar?
yes, you should have. but still, read it. it says blatantly what you're doing wrong.
I stored a vector instead of a player?
Sorry but I really can't see what the problem is.
[QUOTE=Duskling;35235328]I stored a vector instead of a player?
Sorry but I really can't see what the problem is.[/QUOTE]
Firstly, you need to override the ENT:SetupDataTables() function to implement the initial variable assignment. From the looks of the wiki page, you can't simply assign a variable that hasn't existed before (when using DTVars). So you need some code that initializes them first.
[lua]
function ENT:SetupDataTables()
-- Something like this...
self:DTVar("Vector",0,"plyaimvector");
end
[/lua]
What the above code snippet does (presumably) is instantiates the variable so you can then set/get the values you need. So add that code somewhere first before continuing.
I have done that, but it still lags when being used. But it did fix the thing where all the players picked it up, now only one person can pick it up.
But the lag is still a big problem. How do I fix that?
Bump...
You can probably lero the vectors to look smooth.
I tried that before but it made no difference. I will try it again.
Sorry, you need to Log In to post a reply to this thread.