[TUT/FS]: How to get almost life-like moving bots. (0.2X no use in 0.3!)
#1

First, it is wise to create a new blank script with PAWNO.

EDIT: Las Venturas version added! 26/08/09!
See link at very bottom of post.

Tutorial for Red County Version:
At the top, lets forward the custom callbacks we will make later on in the script.
Put this at the top of your script underneath #include's;

pawn Код:
forward BotSwitch(playerid);
forward BotSwitch2(playerid);
forward FinalBotSwitch(playerid);
forward BotEnd(playerid);
Those are just examples for now, you can really change them if you know what you're doing.
Underneath that, lets create a variable to not let the player spam viewing the bots so he gets like 99999 bots at once. (This WILL lag the server like hell, executing loads of timers at once).
Put this under those forwards mentioned earlier;

pawn Код:
new IsOnBots[MAX_PLAYERS]; // this variable is automatically set to 0 (false) when created.
This variable in the quote above will be assigned to 1 (true) later on in the script, so just leave its use for now.

Next we will need to create variables for timers we will have to create later on, so it's easier to kill them when we stop the bots etc;

pawn Код:
new Bot1, Bot2;
Next, let's make our bots command, so the player can see them.
Put this under the OnPlayerCommandText callback;

pawn Код:
if(strcmp(cmdtext, "/bots", true) == 0)
{
  if(IsOnBots[playerid] == 0)
  {
    SetPlayerInterior(playerid, 12);
    SetPlayerPos(playerid, 1131.6519, -6.1646, 1000.6797);
    SetPlayerFacingAngle(playerid, 34.4670);
    SetTimerEx("BotSwitch", 1500, false, "i", playerid);
    SetTimerEx("FinalBotSwitch", 15000, false, "i", playerid);
    IsOnBots[playerid] = 1;
  }
  else
  {
    SendClientMessage(playerid, 0xAFAFAFAA, "[ERROR]: You are already viewing bots.");
  }
  return 1;
}
Alright, now that we have done our command, lets create what it executes through the "BotSwitch" and "FinalBotSwitch" timer, we will need to create this out of OnPlayerCommandText, just paste the following callback and the following ones at the bottom of your script;

pawn Код:
public BotSwitch(playerid)
{
  SetPlayerInterior(playerid, 0);
  TogglePlayerControllable(playerid, false);
  Bot1 = SetTimerEx("BotSwitch2", 750, false, "i", playerid);
  return 1;
}
This code will quickly set the player's interior to 0 which will create the bot's movement and coordination, then the code set a timer to set it back to it's original interior, which was 12 (the casino interior).

Next we will create the code to switch the player's interior back to 12, which is what the "BotSwitch2" timer does mentioned in the code above;

pawn Код:
public BotSwitch2(playerid)
{
  SetPlayerInterior(playerid, 12);
  TogglePlayerControllable(playerid, true);
  Bot2 = SetTimerEx("BotSwitch", 4000, false, "i", playerid);
  return 1;
}
This code will set the player's interior back to 12, and will create new bots automatically to get more of them when we teleport the player onto land.

The "BotSwitch" timer will execute the callback "BotSwitch(playerid)", so it will create lots of bots in the casino interior and make them fall through the floor, thus making them appear on land, because we don't want the player to see 2 bots walking around, we want 5-10 of them.

Now, on the command code we set this timer;
pawn Код:
SetTimerEx("FinalBotSwitch", 15000, false, "i", playerid);
This will kill the repeating stages of switching interiors and place the player on land so he can view bots walking around, instead of the casino. So now we will create the "FinalBotSwitch" code;

pawn Код:
public FinalBotSwitch(playerid)
{
  SetPlayerInterior(playerid, 0);
  SetPlayerPos(playerid, 1119.9685, 10.6820, 62.1944);
  TogglePlayerControllable(playerid, true);
  KillTimer(Bot1);
  KillTimer(Bot2);
  SetTimerEx("BotEnd", 60000, false, "i", playerid);
  return 1;
}
This sets the last timer we will be using named "BotEnd", this will stop the player from viewing bots.

Now we will need to create that code;

pawn Код:
public BotEnd(playerid)
{
  SpawnPlayer(playerid);
  SendClientMessage(playerid, 0xAFAFAFAA, "[INFO]: Bots have been automatically stopped.");
  IsOnBots[playerid] = 0;
  return 1;
}
And that's about it! Now when a player types /bots, he will be teleported to a casino with standing still bots, then they will fall through the ground a few times, then the script will automatically set the player to normal land, thus seeing bots walking around the streets!

Although it all seems fine and dandy, there are a few downsides to this script;

Quote:

If you go out of range the bots disappear.
You can't kill them unless you hit them with a spray can (mace).
You can only view the bots for 1 minute, but that is easy to change, just change the defination of milliseconds in the "BotEnd" timer mentioned in the "/bots" command.

That's all I think, I hope this helped!

A couple of pictures:



Please note: I am not the founder of how to get bots, but I did create this snippet myself so they go on land, but all thanks to http://forum.sa-mp.com/index.php?topic=105658.0

Downloads (Optional):

Red County version (this version is the tutorial):
Click me for download.

Las Venturas version (updated to Las Venturas):
Click me for download.
Reply
#2

Hehe it's nice.
I still think that in 0.3. there will be moveable bots, and you can control them and more.
Reply
#3

Hopefully, I like this little snippet though, I saw the video and thought, lets see if I can do my own version and try to coordinate them for the streets, and it kind of worked, so I thought I'd release this. :P
Hope it's okay. (:
Reply
#4

Looks good, thanks
Reply
#5

No problem.
Reply
#6

That's really nice.

Is it possible to get more bots? What do I have to change to get like ~20 of them?
Well, is it maybe possible to control the bot's somehow? So they do exactly the same things I do?
Reply
#7

Cool..
Hope to see servers with these bots soon..
Reply
#8

Quote:
Originally Posted by .W.[adream-rp.com
]
That's really nice.
Thanks.

Quote:
Originally Posted by .W.[adream-rp.com
]
Is it possible to get more bots? What do I have to change to get like ~20 of them?
Yes, change the defination of milliseconds in this timer;
pawn Код:
SetTimerEx("FinalBotSwitch", 15000, false, "i", playerid);
Quote:
Originally Posted by .W.[adream-rp.com
]
Well, is it maybe possible to control the bot's somehow? So they do exactly the same things I do?
No, as far as I know. =/
Reply
#9

Nice, but you should make it so you can spawn it anywhere by doing /botspawn, and it spawns a bot infront of you.
Reply
#10

yes but they cant do nothing? but just walk?
Reply
#11

Quote:
Originally Posted by Shady91
yes but they cant do nothing? but just walk?
You can shoot at them and they'll run away, you can aim at them and they will put their hands up.
Not tried running them over, but it's the closest thing you'll get to bots legally at the moment, so you'll have to appreciate it. :P

Quote:
Originally Posted by Memoryz
Nice, but you should make it so you can spawn it anywhere by doing /botspawn, and it spawns a bot infront of you.
No sorry.
Reply
#12

would be cool to make it so that everyone could see them ill try but i dont no if its possible
Reply
#13

Everyone can see them, but it's just about the sync of where they are.
Reply
#14

ok , but if you try Red Dragos Casino ?

Because that have more Actors ...
Reply
#15

You could actually, I'll try to make a new snippet later on next week, or somebody can for me.
Reply
#16

Never knew that. Funny how they run away shouting lol
Reply
#17

I don't understand why they walk
can anyone explain me please?
Reply
#18

Yeah I would like to know too.
I'm trying to figure out what the code does, but don't understand where the bots comes from, in the first place!
Reply
#19

from the casino
Reply
#20

Basically what this snippet does, is it teleports you to the interior of a specific casino, then changes your interior back to 0, so the bots fall through, but then the code sets your interior back to the casino one, so you don't fall through but the bots do.

So after a certain amount of time, the snippet sets you on the ground below the interior position, where the bots have fallen to, and the bots automatically coordinate to the streets.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)