I am trying to make a printer and I made a timer that every 10 seconds it will set moneyPrinted to moneyPrinted + some money. I want it to sent to client so client will know what to draw on the printer. Its not working
[CODE]
timer.Create("printMoney",10,0,function()
self.moneyPrinted = self.moneyPrinted + math.random(4987, 6231)
net.Start("sendMoney")
net.WriteInt(self.moneyPrinted)
net.Send(self)
end)
[/CODE]
ERROR
[CODE]
bad argument #2 to 'WriteInt' (number expected, got no value)
[/CODE]
[editline]18th November 2017[/editline]
oh wait...
OMG I AM A IDIOT
[editline]18th November 2017[/editline]
well I figured out the WriteInt part(I forgot the second argument xDD) but the net message still wont send to client.
[editline]18th November 2017[/editline]
Im getting this now :
[CODE]
net.Send: Entity is not a player!
[/CODE]
Can you show us what self refers to? And besides, you'd be better off using NetworkVars for this anyway.
And what is so funny?
This is a entity. I have init, shared, and cl_init .lua and I am trying to use Net messages to send the variable (self.moneyPrinted) from server to client. So that client can draw the amount of money on the ent.
[editline]18th November 2017[/editline]
Well I fixed it by using NetworkVar's Thanks @go4040
But now I got 1 more problem.
I made a timer.Create in ENT:Initialize and if I spawn 1 printer it works fine but if I spawn another it restarts the timer. How do I make a timer Local to THAT ent?
It restarts becuase you reassign it.
You can do it by other ways.
Question to you: There's no contidion when player can have two of them? If player can have more than 1, you need to make "channels".
I will help you. Show whole code of net using and explain what it needs to do
Make the unique identifier of the timer equal to either the name of the timer plus an incrementing value, or the name plus the entity index of the printer.
For the record, your original problem was because net.WriteInt(a,b) takes two arguments. `a` is the int to write and `b` is the max number of bits that are in the int. Then when you use net.ReadInt(b) you use the same number `b`. If you don't want to deal with this, you can use net.Write/ReadFloat().
timer.Create("printer_"..self:EntIndex(), time, reps, function() end)
Sorry, you need to Log In to post a reply to this thread.