Making a barrel controlled by levers
Hi!
I have an idea of two levers controlling one small barrel using propimpulse. I have the script for controlling it but the problem is that I want a repeating script, like "as long as i hold down the lever it should go down. And not just go down using one propimpulse for each time i press down the lever. I hope you can understand and help me out on this one.
void OnStart()
{
SetEntityConnectionStateChangeCallback("leverupdown", "movebarrel1");
SetEntityConnectionStateChangeCallback("leverleverleftright", "movebarrel2");
}
void movebarrel2(string &in asEntity, int alState)
{
if (alState == 1)
{
AddPropImpulse("barrel", 1.5, 0, 0, "world");
AddTimer("", 0.2f, "repeatmovebarrel2");
}
if (alState == -1)
{
AddPropImpulse("barrel", -1.5, 0, 0, "world");
AddTimer("", 0.2f, "repeatmovebarrel2");
}
}
void repeatmovebarrel2(string &in asTimer, int alState)
{
GetLeverState("leverleverleftright");
{
if (alState == 1)
{
AddPropImpulse("barrel", 1.5, 0, 0, "world");
AddTimer("", 0.2f, "repeatmovebarrel2");
}
if (alState == -1)
{
AddPropImpulse("barrel", -1.5, 0, 0, "world");
AddTimer("", 0.2f, "repeatmovebarrel2");
}
}
}
void movebarrel1(string &in asEntity, int alState)
{
if (alState == 1)
{
AddPropImpulse("barrel", 0, 0, 1.5, "world");
AddTimer("", 0.2f, "repeatmovebarrel1");
}
if (alState == -1)
{
AddPropImpulse("barrel", 0, 0, -1.5, "world");
AddTimer("", 0.2f, "repeatmovebarrel1");
}
}
void repeatmovebarrel1(string &in asTimer, int alState)
{
GetLeverState("leverupdown");
{
if (alState == 1)
{
AddPropImpulse("barrel", 0, 0, 1.5, "world");
AddTimer("", 0.2f, "repeatmovebarrel1");
}
if (alState == -1)
{
AddPropImpulse("barrel", 0, 0, -1.5, "world");
AddTimer("", 0.2f, "repeatmovebarrel1");
}
}
}
I forgot to tell you that this script doesn't work, it acts like the second one mentioned above with only one propimpulse.
(This post was last modified: 01-16-2012, 11:23 PM by Yrasin.)
|