Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
« Previous 1 … 14 15 16 17 18 Next »
Problems with an emitter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linear Mode
Problems with an emitter
19-04-2015, 01:51 PM,
#4
Person8880 Offline
gpj.ecafllorT
*******
Posts: 2,407
Threads: 45
Joined: Sep 2013
RE: Problems with an emitter
That's because you're using a net hook to try and receive a DTVar, when a DTVar is implicitly networked in the background once set, not explicitly sent.
hook("net","RecieveString",function(Length)
On = net.getDTVar("Int",1)
end)
This bit does nothing. The net hook is for receiving network messages when using something like
if net.start() then
net.writeBit( true )
net.broadcast()
end
Placing net.setDTVar() inside a block like this does nothing, it's not sent in the message. Only data written to the message using the net.write* functions is sent.

To solve your problem, you need to rethink what's actually going on. Your code runs once, when the chip is first loaded. The client and server instances are not run at the same point in time. The client instance will load some measure of time later, depending on transferring speed of the code to each client.

At the moment your code runs, the DTVar may be available and correct, or it might not. Therefore, the safe and best way to deal with this (and to detect when it changes!), is to be checking the DTVar value in the render hook so it's always using the most up to date Alpha value.

--@name Field Door HP
--@author TheNextDecade
--@sharedscreen

if SERVER then
wire.createInputs({"Active","HP"},{"normal","normal"})
hook("input","ActiveChange",function(Input,Value)
if Input == "Active" then
--NOTE: No net.start()/net.broadcast(), DTVars aren't sent as messages, they're persistently networked values.
net.setDTVar("Int", 1, Value)
end
end)
else
function Drawer(posy,posx,col,hp)
render.setColor(col[1]-100,col[2]-100,col[3]-100,col[4])
render.drawFilledCircle(60,63,22,22)
render.setColor(col[1]-150,col[2]-150,col[3]-150,col[4])
render.drawCircle(60,63,22,22)
render.setColor(col[1],col[2],col[3],col[4])
local Perc = 40/100*hp
render.drawRect(55,43,10,Perc)
render.drawRectOutline(55,43,10,40)
end
Itself = entsConfusedelf()

hook("render","Render",function()
--Read the DTVar to make sure we're always up to date (reading DTVars is super cheap so there's no worry about performance)
local On = net.getDTVar("Int",1)

--Now sort out the alpha from the current value of On
local Alpha
if On == 1 then
Alpha = 200
else
Alpha = 1
end

--Finally, draw. Note that render.clear() does nothing in 3D2D, you always have to redraw if you want anything to show up.
render.start3D2D(Itself:pos(),Itself:ang(),1)
Drawer(60,63,{150,250,150,Alpha},100)
render.end3D2D()
end)
end
Find
Reply
« Next Oldest | Next Newest »


Messages In This Thread
Problems with an emitter - by Destiny's Player - 18-04-2015, 10:19 PM
RE: Problems with an emitter - by Person8880 - 19-04-2015, 11:28 AM
RE: Problems with an emitter - by Destiny's Player - 19-04-2015, 01:20 PM
RE: Problems with an emitter - by Person8880 - 19-04-2015, 01:51 PM
RE: Problems with an emitter - by Destiny's Player - 19-04-2015, 09:05 PM
RE: Problems with an emitter - by TheOneAndOnlyTee - 20-04-2015, 01:10 AM
RE: Problems with an emitter - by Person8880 - 20-04-2015, 07:33 PM
RE: Problems with an emitter - by Destiny's Player - 20-04-2015, 08:36 PM
RE: Problems with an emitter - by TheOneAndOnlyTee - 21-04-2015, 02:42 PM
RE: Problems with an emitter - by Destiny's Player - 21-04-2015, 02:51 PM
RE: Problems with an emitter - by LocInt - 21-04-2015, 05:32 PM
RE: Problems with an emitter - by Person8880 - 21-04-2015, 05:52 PM
RE: Problems with an emitter - by Destiny's Player - 21-04-2015, 06:23 PM
RE: Problems with an emitter - by Person8880 - 21-04-2015, 08:06 PM
RE: Problems with an emitter - by Destiny's Player - 21-04-2015, 08:22 PM
RE: Problems with an emitter - by Iajret - 21-04-2015, 09:41 PM
RE: Problems with an emitter - by LocInt - 22-04-2015, 05:18 AM
RE: Problems with an emitter - by Person8880 - 22-04-2015, 05:41 PM

  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.