Author Topic: Client_AFKBot Improvements  (Read 1239 times)

I came up with this code in a few minutes.
Code: [Select]
//AfkBot
//This is a 'Medium' level script
//This was made by 'Alchemy'
//This script was made for 'Alchemy'
//=========================
//Functions
function afkBot()
{
%d = getRandom(1,2);
if(%d == 1)
{
afkBotForward();
}
else if(%d == 2)
{
afkBotBackward();
}
}
function afkBotForward()
{
%t = getRandom(1,3);
moveForward(1);
if(%t == 1)
{
schedule(999,0,AfkBotForwardStop);
}
else if(%t == 2)
{
schedule(1999,0,afkBotForwardStop);
}
else if(%t == 3)
{
schedule(2999,0,afkBotForwardStop);
}
}
function afkBotForwardStop()
{
%t = getRandom(1,3);
moveForward(0);
if(%t == 1)
{
schedule(1,0,afkBotYaw);
}
if(%t == 2)
{
schedule(1001,0,afkBotYaw);
}
if(%t == 3)
{
schedule(2001,0,afkBotYaw);
}
}
function afkBotYaw()
{
%y = getRandom(1,4);
%t = getRandom(1,3);
if(%y == 1)
{
yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25);
}
else if(%y == 2)
{
yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25);
}
else if(%y == 3)
{
yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25);
}
else if(%y == 4)
{
yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25);
}
if(%t == 1)
{
schedule(999,0,afkBotYawStop);
}
else if(%t == 2)
{
schedule(1999,0,afkBotYawStop);
}
else if(%t == 3)
{
schedule(2999,0,afkBotYawStop);
}
}
function afkBotYawStop()
{
%t = getRandom(1,3);
if(%t == 1)
{
schedule(999,0,afkBot);
}
else if(%t == 2)
{
schedule(1999,0,afkBot);
}
else if(%t == 3)
{
schedule(2999,0,afkBot);
}
}
function afkBotBackward()
{
%t = getRandom(1,3);
moveBackward(1);
if(%t == 1)
{
schedule(999,0,AfkBotBackwardStop);
}
else if(%t == 2)
{
schedule(1999,0,afkBotBackwardStop);
}
else if(%t == 3)
{
schedule(2999,0,afkBotBackwardStop);
}
}
function afkBotBackwardStop()
{
%t = getRandom(1,3);
moveBackward(0);
if(%t == 1)
{
schedule(1,0,afkBotYaw);
}
if(%t == 2)
{
schedule(1001,0,afkBotYaw);
}
if(%t == 3)
{
schedule(2001,0,afkBotYaw);
}
}
It works perfectly fine, but I need ways to make it seem more realistic. One thing I need help with is improving the turning (yaw). When it stops moving, it jerk turns my avatar to the right. I want it to turn smoothly to the right. Any suggestions?

Idk about realism but there's a lot of ways you could make the code less messy

Idk about realism but there's a lot of ways you could make the code less messy
How :c

How :c
How about combining all the
yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25);
's into one operation.

How about combining all the
yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25);
's into one operation.
Can't they are different turns.

Can't they are different turns.
Really because i see the same function with the same arguments repeated an excessive ammount of times on the same line.

I have a problem
Code: [Select]
//AfkBot
//This is a 'Medium' level script
//This was made by 'Alchemy'
//This script was made for 'Alchemy'
//=========================
//Functions
function afkBot()
{
%d = getRandom(1,2);
if(%d == 1)
{
afkBotForward();
}
else if(%d == 2)
{
afkBotBackward();
}
}
function afkBotForward()
{
%t = getRandom(1,3);
%j = getRandom(1,2);
moveForward(1);
if(%t == 1)
{
schedule(999,0,AfkBotForwardStop);
}
else if(%t == 2)
{
schedule(1999,0,afkBotForwardStop);
}
else if(%t == 3)
{
schedule(2999,0,afkBotForwardStop);
}
if(%j == 1);
{
afkBotJet();
}
elseIf(%j == 2);
{
return;
}
}
function afkBotForwardStop()
{
%t = getRandom(1,3);
moveForward(0);
if(%t == 1)
{
schedule(999,0,afkBotYaw);
}
if(%t == 2)
{
schedule(1999,0,afkBotYaw);
}
if(%t == 3)
{
schedule(2999,0,afkBotYaw);
}
}
function afkBotYaw()
{
%y = getRandom(1,4);
%t = getRandom(1,3);
if(%y == 1)
{
yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25);
}
else if(%y == 2)
{
yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25);
}
else if(%y == 3)
{
yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25);
}
else if(%y == 4)
{
yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25); yaw(25);
}
if(%t == 1)
{
schedule(999,0,afkBotYawStop);
}
else if(%t == 2)
{
schedule(1999,0,afkBotYawStop);
}
else if(%t == 3)
{
schedule(2999,0,afkBotYawStop);
}
}
function afkBotYawStop()
{
%t = getRandom(1,3);
if(%t == 1)
{
schedule(999,0,afkBot);
}
else if(%t == 2)
{
schedule(1999,0,afkBot);
}
else if(%t == 3)
{
schedule(2999,0,afkBot);
}
}
function afkBotBackward()
{
%t = getRandom(1,3);
moveBackward(1);
if(%t == 1)
{
schedule(999,0,AfkBotBackwardStop);
}
else if(%t == 2)
{
schedule(1999,0,afkBotBackwardStop);
}
else if(%t == 3)
{
schedule(2999,0,afkBotBackwardStop);
}
}
function afkBotBackwardStop()
{
%t = getRandom(1,3);
moveBackward(0);
if(%t == 1)
{
schedule(1,0,afkBotYaw);
}
if(%t == 2)
{
schedule(1001,0,afkBotYaw);
}
if(%t == 3)
{
schedule(2001,0,afkBotYaw);
}
}
function afkBotJet()
{
%t = getRandom(1,4);
jump(1);
schedule(1,0,jump,0);
jet(1);
if(%t == 1)
{
schedule(1999,0,jet,0);
}
else if(%t == 2)
{
schedule(4999,0,jet,0);
}
else if(%t == 3)
{
schedule(7999,0,jet,0);
}
else if(%t == 4)
{
schedule(10999,0,jet,0);
}
}
I've added in a function in the last few lines. It makes my player jet and stops it at random durations. At the first function, AFKBotForward, i've added in a check event to see if %j == 1, if it is, then it activated AFKBotJet. But when I executed this, I got an error around line 36, and I don't know what it means.

I heard something about the amount turned by the yaw function not being linear; Passing an argument twice as large doesn't turn twice as far.
Perhaps I was confusing it with another similar function

If you want something that moves realistically, you're looking at a lot more than a practice script. I'd suggest something simple.
I'll see how much I can clean this up, though; combining all the functions into one, chosen by a switch, multiplying %t by 1000 and scheduling for that instead of using ifs, etc
« Last Edit: July 30, 2012, 06:09:02 PM by Headcrab Zombie »

I have another question (+ headcrab zombie can you help me on my jetting addition)

Anyways, the other question, how would I, client-sidely, detect if there is a brick in any direction I want (EX: i want to detect if there is a brick infront of me, or behind me, or to the left/right of me?)

god damn that is an ugly mess of repeated yaws

why not make a loop (this is psuedo-code) <--- aka I'm a bit rusty at torque

function yawLoop(%t, %amt)
{
    for(i = 1; i < %t; i++)
    {
        yaw(%amt);
    }
}

and then calling yawLoop(5, 25); would do yaw(25); 5 times.
« Last Edit: July 30, 2012, 06:10:52 PM by SpreadsPlague »

god damn that is an ugly mess of repeated yaws

why not make a loop (this is psuedo-code)

function yawLoop(%t, %amt)
{
    for(i = 0; i < %t; i++)
    {
        yaw(%amt);
    }
}
Or just add up all the 25's and put that in.

god damn that is an ugly mess of repeated yaws

why not make a loop (this is psuedo-code) <--- aka I'm a bit rusty at torque

function yawLoop(%t, %amt)
{
    for(i = 1; i < %t; i++)
    {
        yaw(%amt);
    }
}

and then calling yawLoop(5, 25); would do yaw(25); 5 times.
Somehow, when I put that in, it gives me Syntax Error in Input.

Somehow, when I put that in, it gives me Syntax Error in Input.
Thats because there was. He forgot to put a % before i.

function yawLoop(%t, %amt)
{
    for(%i = 1; %i < %t; %i++)
    {
        yaw(%amt);
    }
}

Also
Or just add up all the 25's and put that in.

Something like this looks a lot cleaner:
Combined all functions into one, with a switch.
Instead of having a random number of seconds, then using if...else to schedule according to the time, just use the random generated number as the time
Combined forgetton of yaw calls into one
Code: [Select]
function afkBot(%dir)
{
cancel($afkBot);

%time = getRandom(1000,3000);
%dir = getRandom(0,4);

switch(%dir)
{
case 0:
moveForward(1);
schedule(%time,0,moveForward,0);
case 1:
moveRight(1);
schedule(%time,0,moveRight,0);
case 2:
moveBackward(1);
schedule(%time,0,moveBackward,0);
case 3:
moveLeft(1);
schedule(%time,0,moveLeft,0);
case 4:
jet(1);
schedule(%time,0,jet,0);
}

yaw(getRandom(80,800));

%time += getRandom(1000,3000)
$afkBot = schedule(%time,0,afkBot,%dir);
}

Anyways, the other question, how would I, client-sidely, detect if there is a brick in any direction I want (EX: i want to detect if there is a brick infront of me, or behind me, or to the left/right of me?)
I'm not sure of a way that's not hacky

Somehow, when I put that in, it gives me Syntax Error in Input.
Because:
this is psuedo-code
pseudo-code means it's not actual code, it's just meant to give you the idea of the logic

Something like this looks a lot cleaner:
Combined all functions into one, with a switch.
Instead of having a random number of seconds, then using if...else to schedule according to the time, just use the random generated number as the time
Combined forgetton of yaw calls into one
Code: [Select]
function afkBot(%dir)
{
cancel($afkBot);

%time = getRandom(1000,3000);
%dir = getRandom(0,4);

switch(%dir)
{
case 0:
moveForward(1);
schedule(%time,0,moveForward,0);
case 1:
moveRight(1);
schedule(%time,0,moveRight,0);
case 2:
moveBackward(1);
schedule(%time,0,moveBackward,0);
case 3:
moveLeft(1);
schedule(%time,0,moveLeft,0);
case 4:
jet(1);
schedule(%time,0,jet,0);
}

yaw(getRandom(80,800));

%time += getRandom(1000,3000)
$afkBot = schedule(%time,0,afkBot,%dir);
}
I'm not sure of a way that's not hacky
Because:pseudo-code means it's not actual code, it's just meant to give you the idea of the logic
Thanks, but it gives me syntax errors, at the 2nd to last line where you define $afkBot