NPC/Bots implementation in VCMP 0.4 Servers

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

Previous topic - Next topic

habi2

#135
NPCClient v1.8 Beta 4 Released

We're releasing the latest beta for NPCClient, version 1.8 Beta 4, with several improvements and bug fixes:

  • Fixed Vehicle Driver not reset on player exit (GetVehicleDriver).
  • Added FireBullet function to enable NPC shooting.
  • API updated to 1.8.
  • Resolved issues with NPC entering vehicles as drivers and closing doors on exit.
  • NPCClient now supports store-file downloads with the option `-d` or `-D`.
  • Added GetStoreURL() for retrieving store-url of server (if http-downloads enabled in server)
  • Added manual NPC spawn option using `-M` or `--Manual-Spawn`. This prevents npc from automatically spawning.
  • Fixed crash issue with API (plugin.h).
  • New npc table in Squirrel script with functions: `npc.fire()`, `npc.punch()`, `npc.wep()`, `npc.prewep()`, `npc.sit()`, and `npc.stand()`.

Downloads:
Operating SystemVersionLink
Windows0.4.7.1npc_vcmp_0471_windows_v1.8-beta-4.zip
Linux x640.4.7.1npc_vcmp_0471_linux_x64_v1.8-beta-4.zip
Linux x860.4.7.1npc_vcmp_0471_linux_x86_v1.8-beta-4.zip
Windowsrel006npc_vcmp_rel006_windows_v1.8-beta-4.zip
Linux x64rel006npc_vcmp_rel006_linux_x64_v1.8-beta-4.zip
Linux x86rel006npc_vcmp_rel006_linux_x86_v1.8-beta-4.zip
Windows/Linux (rel004)rel004npc_vcmp_rel004_win_lin_v1.8-beta-4.zip
Source CodeAllNPC-VCMP-master-v1.8-beta-4.zip
API Plugin1.8npc_vcmp_plugin_API_1_8.zip
Windows (Setup)rel004, rel006, 0.4.7.1npcclient_v1.8_beta4_setup.exe

Thank you for testing and providing feedback!

Release Notes

PSL

Hey, Habi! Congratulations on your successful launch of NPC plug-in 1.8p4 version ah, along the way watching you constantly update and improve this plug-in, really admire your persistence and efforts. I know that every update is not easy, and I must have paid a lot of effort behind it. I believe that this new version will be loved and recognized by more players, you can boldly go ahead, I will always support you!

MEGAMIND

habi soon making npc.ai();

great work man.. keep vcmp alive..

habi2

Hi PSL,
Thank you for such encouraging words. It is because of you and other friend's interest that the project is still alive.
I will see what can be done to make npc more better.

Hi Megamind,
Quote from: MEGAMIND on Oct 26, 2024, 07:26 AMhabi soon making npc.ai();

great work man.. keep vcmp alive..
Thank you

MEGAMIND

How does the npc gets a skin ?
npc_pos <- Vector(-1750.44, -277.178, 14.8683);
function OnNPCScriptLoad( params )
{

print("npcidle: running\n");
}


function OnNPCClassSelect()
{
    if(GetPlayerTeam(GetMyID())==210)
      RequestSpawn();
    else
      RequestClass(CLASS_NEXT);
    return 1
}

function OnNPCSpawn()
{


     SendChat("I have spawned");

SetTimerEx("SetMyPos",700, 1, npc_pos );
SetMyPos(npc_pos);

}

server side
function onPlayerRequestClass( player, classID, team, skin )
{
AddClass(28, RGB( 124, 121, 121 ),212,Vector(-923.882, 406.665, 11.247), 188.3568,25,320,21,320,102,450);
}
@habi2

habi2

Hi Megamind

The npc doesn't get skin. The npc04 plugin has code inside it for setting skin. It sets skin if any npc sends a setskin command. And when needed, our npc do send such commands.

MEGAMIND

#141
Quote from: habi2 on Nov 07, 2024, 12:07 PMHi Megamind

The npc doesn't get skin. The npc04 plugin has code inside it for setting skin. It sets skin if any npc sends a setskin command. And when needed, our npc do send such commands.
how do i set the skin to it

working on npcAI(text,player,tone);

habi2

Quote from: MEGAMIND on Nov 07, 2024, 12:26 PMhow do i set the skin to it
You can set the skin of npc when using ConnectNPCEx
ConnectNPCEx("[npc]robin", Vector(-377.935, -536.472, 17.2828), 0.0, 0);
//Angle 0.0, Skin=0, Weapon  not specified

Also you can from npcscripts:
SendCommand("_npc_skin_request 0"); //if you need skin 0

Also from server, if player=npc, then
player.Skin=5; //medic

MEGAMIND

#143
hi @habi2 lets say

function OnPlayerText(playerid, message)
{
    if(message=="come")
    {
    print("Going to player: "+playerid+"\n");
    SendCommand("goto "+playerid);
    }
   
    if(message=="lookatme")
    {
        if(GetDistanceFromMeToPoint(GetPlayerPos(playerid))<100.0)
        {
            LookAtPlayer(playerid);
        }
    }
}

how am i going to call these from serverside? either onplayercommandor playerchat ?

or if theres a way to get the checkpoint id and do it from serverside?

if ( checkpoint.ID == 100)
{
onPlayerChat(player, "lookatme");
}
}

habi2

I am very much happy you asked this question.

From server you can call npcscript functions like LookAtPlayer:
RFC(1,"LookAtPlayer")(player.ID);
//Let 1 be ID of npc


RFC is available with npc04 plugin.
For this to work you have to load 'LibRPC' plugin of npc while connecting:
ConnectNPC("[npc]mike, "your_npc_script.nut", false, "", "rpclib");
//false = no console, hostname="" means 127.0.0.1
If you're using ConnectNPCEx instead of ConnectNPC then use following format:
Quote(name, Pos, angle, skinId, weaponId, classId, script="", enableconsoleinput=false, host="127.0.0.1", plugins="", ...)

If you want to use SendCommand it is same:
//From serverside only:
RFC(1, "SendCommand")("goto "+playerid);

MEGAMIND

#145
Quote from: habi2 on Nov 09, 2024, 11:20 AMI am very much happy you asked this question.

From server you can call npcscript functions like LookAtPlayer:
RFC(1,"LookAtPlayer")(player.ID);
//Let 1 be ID of npc


RFC is available with npc04 plugin.
For this to work you have to load 'LibRPC' plugin of npc while connecting:
ConnectNPC("[npc]mike, "your_npc_script.nut", false, "", "rpclib");
//false = no console, hostname="" means 127.0.0.1
If you're using ConnectNPCEx instead of ConnectNPC then use following format:
Quote(name, Pos, angle, skinId, weaponId, classId, script="", enableconsoleinput=false, host="127.0.0.1", plugins="", ...)

If you want to use SendCommand it is same:
//From serverside only:
RFC(1, "SendCommand")("goto "+playerid);

worked but crash, it  responded for 3 times but then crashed, what im doing is on npc side
function OnPlayerText(playerid, message)
{
if(message=="come")
{
print("Going to player: "+playerid+"\n");
SendCommand("goto "+playerid);
}

if(message=="lookatme")
{
if(GetDistanceFromMeToPoint(GetPlayerPos(playerid))<100.0)
{
LookAtPlayer(playerid);
}
}
}
and on serverside

if ( checkpoint.ID == 100)
{
local npc = FindPlayer(0);
RFC(0,"LookAtPlayer")(player.ID);
}
else
{
MessagePlayer("[#ffffff]Donot disturb npc",player);
}
}

though im using this ConnectNPCEx("[A.I]ChatGPT", Vector (-1735.81, -266.977, 14.8683),  -0.172573, 212, 24, 4,"npc.nut",true,"127.0.0.1","rpclib z-finder");
Edit: what i find out is that its fine until u give it a 2 or 3 sec break , if u enter checkpoint and leave and enter it crashes, like performing this move within a sec
 

MEGAMIND

#146
what i did that i tried even placing this rfc command at on playermove the server started and clsoed immedialtely @habi2

MEGAMIND

function OnNPCSpawn()
{


     SendChat("I have spawned");

SetTimerEx("SetMyPos",700, 1, npc_pos );
SetMyPos(npc_pos);



}

function OnPlayerDeath(playerid)
{
OnNPCSpawn();
}
npc is dead how he gonna spawn back?, bcz i see a msg that i have spawned but not actully spawned, even though i get npc it says player not spawned

habi2

Hi @MEGAMIND, i see your messages and will fix it one by one.
Quotenpc is dead how he gonna spawn back?, bcz i see a msg that i have spawned but not actully spawned, even though i get npc it says player not spawned
Use RequestSpawn to spawn the npc.when it is dead. It will spawn in the same class.
function OnPlayerDeath(playerid)
{
if(playerid==GetMyID())
              RequestSpawn();
}
About crashing of server (i hope it is server that is crashing), when you use RFC repetitiously there might be some bug which i will look now.

MEGAMIND

Quote from: habi2 on Nov 09, 2024, 04:11 PMHi @MEGAMIND, i see your messages and will fix it one by one.
Quotenpc is dead how he gonna spawn back?, bcz i see a msg that i have spawned but not actully spawned, even though i get npc it says player not spawned
Use RequestSpawn to spawn the npc.when it is dead. It will spawn in the same class.
function OnPlayerDeath(playerid)
{
if(playerid==GetMyID())
              RequestSpawn();
}
About crashing of server (i hope it is server that is crashing), when you use RFC repetitiously there might be some bug which i will look now.
why does it change skin? though i have a skin already in connect ConnectNPCEx("[A.I]ChatGPT", Vector (-1735.81, -266.977, 14.8683),  -0.172573, 212, 24, 4,"npc.nut",true,"wno-host.ddns.net","rpclib z-finder actionlib npcmodule");
its changing into lovefist skin