NPC/Bots implementation in VCMP 0.4 Servers

Started by habi, Apr 01, 2022, 05:37 PM

Previous topic - Next topic

Sebastian

https://forum.vc-mp.org/?topic=8952

here is a short video I made while testing out the server
Pure Awesome!

Sebastian

#16
Now, regarding the plugin.
I've done some tries now to get the npc shooting at me, but with not much success.
I've used the examples from wiki, for both Melee attack and Ruger attack, but none of them really worked...

Mikimon

bro, u always improving something and surprising us a lot, thanks ;D ;D

habi


habi

#19
The function 'SendOnFootSyncData' is to be called with a timer.
Try something like
SetTimerEx( "ShootPlayer", 60, 0 );

So in 60ms interval, send packets continuously.

This will make player shoot.

Advanced: Take a note of no: bullets fired.

Logic

function ShootPlayer

Is Time to Reduce Ammo ?
Yes--> shots_fired++, ammo=ammo-1 ( to get and set use I_CURWEP_AMMO and 'GetLocalValue' fn. )
No-->nothing.

Is It time for Reloading  ?
Yes-->You know, some parameter true.
No-->parameter false.

I have made a sample script with comments and untested ( no time now ), from the demo server.here

The following table gives information of various weapons to npcs.
class WEAPON
{
    range=80;
    firingrate=250; //interval ms
    reload=500; //ms
    clipsize=30;
    damage=25;
    constructor( range, firingrate, reload, clipsize, damage)
    {
        this.range= range;
        this.firingrate=firingrate;
        this.reload=reload;
        this.clipsize=clipsize;
        this.damage=damage;
    }
};
Weapon<-array( 34 ); //minigun id is 33. plus 1 for weapon 0
Weapon[0] = WEAPON(2.4,250, 100, 1000, 8);
Weapon[1] = WEAPON(2.0,450, 100, 1000, 16);
Weapon[2] = WEAPON(1.8,250, 100, 1000, 45);
Weapon[3] = WEAPON(1.5,450, 100, 1000, 21);
Weapon[4] = WEAPON(1.5,450, 100, 1000, 21);
Weapon[5] = WEAPON(1.8,250, 100, 1000, 21);
Weapon[6] = WEAPON(2.0,450, 100, 1000, 21);
Weapon[7] = WEAPON(1.5,450, 100, 1000, 21);
Weapon[8] = WEAPON(1.9,250, 100, 1000, 24);
Weapon[9] = WEAPON(2.0,250, 100, 1000, 24);
Weapon[10] = WEAPON(2.1,250, 100, 1000, 30);
Weapon[11] = WEAPON(1.7,900, 100, 1000, 35);
Weapon[12] = WEAPON(30.0,100, 1, 1, 75);
Weapon[13] = WEAPON(30.0,100, 1, 1, 75);
Weapon[14] = WEAPON(30.0,100, 1, 1, 75);
Weapon[15] = WEAPON(25.0,100, 1, 1, 75);
Weapon[16] = WEAPON(30.0,100, 1, 1, 75);
Weapon[17] = WEAPON(30.0,210, 450, 17, 25);
Weapon[18] = WEAPON(30.0,630, 1000, 6, 135);
Weapon[19] = WEAPON(20.0,250, 450, 1, 80);
Weapon[20] = WEAPON(15.0,250, 750, 7, 100);
Weapon[21] = WEAPON(10.0,250, 250, 1, 120);
Weapon[22] = WEAPON(30.0,119, 500, 50, 20);
Weapon[23] = WEAPON(45.0,59, 500, 30, 20);
Weapon[24] = WEAPON(30.0,60, 500, 30, 15);
Weapon[25] = WEAPON(45.0,90, 500, 30, 35);
Weapon[26] = WEAPON(90.0,90, 1000, 30, 40);
Weapon[27] = WEAPON(90.0,150, 1000, 30, 35);
Weapon[28] = WEAPON(100.0,89, 1401, 1, 125);
Weapon[29] = WEAPON(100.0,180, 1401, 7, 125);
Weapon[30] = WEAPON(55.0,100, 1200, 1, 75);
Weapon[31] = WEAPON(5.1,100, 100, 500, 25);
Weapon[32] = WEAPON(75.0,119, 500, 100, 130);
Weapon[33] = WEAPON(75.0,30, 350, 500, 140);

/* Generated from server side code
function makecode()
{
for(local i=0; i< 34; i++)
{
    local string=format("Weapon[%d] = WEAPON(%0.1f,%d, %d, %d, %d);", i,
    GetWeaponDataValue( i, 2 ), GetWeaponDataValue( i, 3 ),
    GetWeaponDataValue( i, 4 ), GetWeaponDataValue( i, 5 ),
    GetWeaponDataValue( i, 6 ) );
    print(string);
}
}
*/

Yyg

#20
:)Hi habi, I would like to feedback a question

When I tried to use version 1.5, I found that any NPCS driving vehicles would not work
When I tried using the rec fix tool, he told me that the driving function did not need to be fixed
(Nothing to do for PLAYER_RECORDING_TYPE_DRIVER recordings)
(Even if you use the built-in taxi rec or nut, it doesn't work)

When I replaced npcclient.exe with the old version, everything worked fine
(cannot be played by this version of program)

Sebastian

Alright,  will test it this weekend
Thank you!

Sebastian

With your example code, I was finally able to make the npc shoot, which is satisfying!

though, I've realized that SetTimerEx doesn't work at all.
NPC Console opens and instantly closes.

PS: For who wants to see the NPC Console, use ShowNPCConsole() before connecting the npcs

habi

#23
Quote from: Yyg on Dec 09, 2022, 11:57 AM:)Hi habi, I would like to feedback a question

When I tried to use version 1.5, I found that any NPCS driving vehicles would not work.




(cannot be played by this version of program)
Hi Yyg. It was a condition which escaped my notice.
The '. rec' files are binary files. The first byte of all of them was E8 in previous version.
Version 1.5 require it to be E9.
I request you to make this change in the first byte of driving recordings using a 'hex-editor', for the time being.

The first four bytes E8 03 = 1000 (decimal)
E9 03 = 1001

habi

Quote from: Sebastian on Dec 09, 2022, 09:06 PMWith your example code, I was finally able to make the npc shoot, which is satisfying!

though, I've realized that SetTimerEx doesn't work at all.
NPC Console opens and instantly closes.
Hi seby. nice to hear that npcs is shooting.

NPC Console opens and normally close only when disconnected from server.

I will check what is the problem with SetTimerEx

Yyg

Quote from: habi on Dec 10, 2022, 02:12 PM
Quote from: Yyg on Dec 09, 2022, 11:57 AM:)Hi habi, I would like to feedback a question

When I tried to use version 1.5, I found that any NPCS driving vehicles would not work.




(cannot be played by this version of program)
Hi Yyg. It was a condition which escaped my notice.
The '. rec' files are binary files. The first byte of all of them was E8 in previous version.
Version 1.5 require it to be E9.
I request you to make this change in the first byte of driving recordings using a 'hex-editor', for the time being.

The first four bytes E8 03 = 1000 (decimal)
E9 03 = 1001

Thanks habi, it worked! The vehicle is moving again! :)

Yyg

Hello Habi, the new NPC features are very interesting!

But I still have a few issues, I try to get the NPC to sit in my car (player.PutInVehicleSlot), it seems to work, but the NPC will no longer do a stream update (Pos locked) and when I drive the car a certain distance, the NPC will disappear and return to the point where it was boarded.

After my tests, when the NPC is PutInVehicleSlot, his player.Vehicle == null and player.Pos stays in the boarding Position
It seems impossible to do a "on-board" Update Vehicle Pos in NPCScript, and when I try something like SetMyPos(), the NPC just leaves the vehicle.

Maybe I'm getting something wrong, but are there any examples where an NPC can get in my car, no matter where I drive it?

Sebastian

I have faced a similar behavior when setting a rolling animation to the npc.
Basically,  the npc doesn't update position if the animation actually features movement.

Just mentioning it here,  maybe there will be some fix for it.  In my case,  I am updating pos manually,  as a work around.

As for your case,  I think we need some state which will let server know when a npc is getting inside car,  to update it's position. But it's tricky,  because if (behind the scenes)  npc becomes the owner of vehicle,  and sync will be sent from it's point of view only,  there will actually never be syncs sent.

habi

#28
Quote from: Yyg on Dec 12, 2022, 08:07 AMHello Habi, the new NPC features are very interesting!

But I still have a few issues, I try to get the NPC to sit in my car (player.PutInVehicleSlot), it seems to work, but the NPC will no longer do a stream update (Pos locked) and when I drive the car a certain distance, the NPC will disappear and return to the point where it was boarded.d player.Pos stays in the boarding Position
It seems impossible to do a "on-board" Update Vehicle Pos in NPCScript, and when I try something like SetMyPos(), the NPC just leaves the vehicle.

Maybe I'm getting something wrong, but are there any examples where an NPC can get in my car, no matter where I drive it?
Thank you Yyg. I understand the problem with putting NPCs inside Vehicles.
We have not implemented this feature it. Syncing NPC in vehicle needs a new function as the existing function 'SendOnFootSyncData' can sync only On foot values.
I think VCMP automatically set player state and position from the last sync packet if new packets are not received for some time.
So syncing npc then require either 1. One vehicle sync packet or 2. Continous vehicle sync packets.

In current version as mentioned before, sending vehicle sync packets directly is not possible.

Server getting no vehicle sync packets from npc may be the reason of player.Vehicle value equal null.

SetMyPos function will fail too because it sends On-Foot update packets only.

This issue needs to be taken care in the next version.

Yyg

Quote from: habi on Dec 19, 2022, 08:15 AM
Quote from: Yyg on Dec 12, 2022, 08:07 AMHello Habi, the new NPC features are very interesting!

But I still have a few issues, I try to get the NPC to sit in my car (player.PutInVehicleSlot), it seems to work, but the NPC will no longer do a stream update (Pos locked) and when I drive the car a certain distance, the NPC will disappear and return to the point where it was boarded.d player.Pos stays in the boarding Position
It seems impossible to do a "on-board" Update Vehicle Pos in NPCScript, and when I try something like SetMyPos(), the NPC just leaves the vehicle.

Maybe I'm getting something wrong, but are there any examples where an NPC can get in my car, no matter where I drive it?
Thank you Yyg. I understand the problem with putting NPCs inside Vehicles.
We have not implemented this feature it. Syncing NPC in vehicle needs a new function as the existing function 'SendOnFootSyncData' can sync only On foot values.
I think VCMP automatically set player state and position from the last sync packet if new packets are not received for some time.
So syncing npc then require either 1. One vehicle sync packet or 2. Continous vehicle sync packets.

In current version as mentioned before, sending vehicle sync packets directly is not possible.

Server getting no vehicle sync packets from npc may be the reason of player.Vehicle value equal null.

SetMyPos function will fail too because it sends On-Foot update packets only.

This issue needs to be taken care in the next version.
Thanks Habi, great feat! This could be very interesting
Thanks also to Sebastian for his answer

Good Luck!