Scripting Refire
Quote from Goldenknighttim on July 15, 2014, 7:30 amHey guys,
I'm pretty new to writing scripts, but I have one in mind that I think would be pretty cool. For this script, I want to keep a variable up to date on the position of an object. My current plan is to write the script in a way that expects a logic_timer to continually run the script. However, I would rather do as much of this in the actual script as possible. Is there a way to get a script to refire at a steady interval by only using the script itself?
Hey guys,
I'm pretty new to writing scripts, but I have one in mind that I think would be pretty cool. For this script, I want to keep a variable up to date on the position of an object. My current plan is to write the script in a way that expects a logic_timer to continually run the script. However, I would rather do as much of this in the actual script as possible. Is there a way to get a script to refire at a steady interval by only using the script itself?
Quote from FelixGriffin on July 15, 2014, 9:30 amThere is, in fact. VALVe used something called a "think function" in their scripts, but the following does the same thing and is rather easier to work with.
- Code: Select all
function refire(){
EntFireByHandle(self,"RunScriptCode","refire();",0.1,null,null);
}
There is, in fact. VALVe used something called a "think function" in their scripts, but the following does the same thing and is rather easier to work with.
- Code: Select all
function refire(){
EntFireByHandle(self,"RunScriptCode","refire();",0.1,null,null);
}
Quote from Goldenknighttim on July 15, 2014, 10:28 amLol, that's brilliant. Thanks.
I have another question though. In the same script, I want to get an object to move forward. There is a SetVelocity() function. How do I deturmine whether the specified vector is local to the entity, or a global vector?
Lol, that's brilliant. Thanks.
I have another question though. In the same script, I want to get an object to move forward. There is a SetVelocity() function. How do I deturmine whether the specified vector is local to the entity, or a global vector?
Quote from FelixGriffin on July 15, 2014, 11:08 pmVelocity is global, but you can get the Euler angles of the entity and use them to make a rotation matrix.
Velocity is global, but you can get the Euler angles of the entity and use them to make a rotation matrix.
Quote from Goldenknighttim on July 16, 2014, 6:43 amThanks Felix, but all I got from that was that velocity is always global. That's fine though, I've got another idea for moving an object in a locally oriented direction. It's based on the assumption that SetOrigin() can be used to move an object around. I'll test that out later this morning.
Thanks Felix, but all I got from that was that velocity is always global. That's fine though, I've got another idea for moving an object in a locally oriented direction. It's based on the assumption that SetOrigin() can be used to move an object around. I'll test that out later this morning.
Quote from FelixGriffin on July 16, 2014, 9:15 amGoldenknighttim wrote:Thanks Felix, but all I got from that was that velocity is always global. That's fine though, I've got another idea for moving an object in a locally oriented direction. It's based on the assumption that SetOrigin() can be used to move an object around. I'll test that out later this morning.You can use SetOrigin, but it'll be jerky and can put the object inside walls. Changing velocity is better.
You can use SetOrigin, but it'll be jerky and can put the object inside walls. Changing velocity is better.
Quote from Goldenknighttim on July 16, 2014, 10:15 amI did use SetOrigin() this morning, and that's exactly what happened. But I found that I could make it smoother by setting the refire rate to a higher rate, and I plan to use the TraceLine function to tell whether it runs into a wall, and if there is ground beneath it. Unfortunately, setvelocity does not work at all. I'm using a pedistal button entity for testing. I'm guessing that setvelocity only works with a few entities.
I did use SetOrigin() this morning, and that's exactly what happened. But I found that I could make it smoother by setting the refire rate to a higher rate, and I plan to use the TraceLine function to tell whether it runs into a wall, and if there is ground beneath it. Unfortunately, setvelocity does not work at all. I'm using a pedistal button entity for testing. I'm guessing that setvelocity only works with a few entities.
Quote from FelixGriffin on July 16, 2014, 11:03 pmGoldenknighttim wrote:I did use SetOrigin() this morning, and that's exactly what happened. But I found that I could make it smoother by setting the refire rate to a higher rate, and I plan to use the TraceLine function to tell whether it runs into a wall, and if there is ground beneath it. Unfortunately, setvelocity does not work at all. I'm using a pedistal button entity for testing. I'm guessing that setvelocity only works with a few entities.TraceLine is glitchy and only detects world brushes (as well as one particular brush entity, but that's another bug).
SetVelocity only works on things which can move. Pedestal buttons cannot unless they are parented.
TraceLine is glitchy and only detects world brushes (as well as one particular brush entity, but that's another bug).
SetVelocity only works on things which can move. Pedestal buttons cannot unless they are parented.
Quote from Goldenknighttim on July 17, 2014, 6:53 amOk, so an object parented to an invisible func_physbox would work with SetVelocity?
I already finished the code, but as it is, it would go through other entities, so some editing would help.
Ok, so an object parented to an invisible func_physbox would work with SetVelocity?
I already finished the code, but as it is, it would go through other entities, so some editing would help.
Quote from FelixGriffin on July 17, 2014, 10:31 amSetVelocity will work on any object which is physically simulated and thus can have velocity. So yes, a func_physbox would work.
SetVelocity will work on any object which is physically simulated and thus can have velocity. So yes, a func_physbox would work.