Please or Register to create posts and topics.

Scripting Refire

Page 1 of 2Next

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?

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);
}
Falsi sumus crusto!

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?

Velocity is global, but you can get the Euler angles of the entity and use them to make a rotation matrix.

Falsi sumus crusto!

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.

Goldenknighttim 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.

Falsi sumus crusto!

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.

Goldenknighttim 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.

Falsi sumus crusto!

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.

SetVelocity will work on any object which is physically simulated and thus can have velocity. So yes, a func_physbox would work.

Falsi sumus crusto!
Page 1 of 2Next