NPC/Bots implementation in VCMP 0.4 Servers

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

Previous topic - Next topic

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

#151
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

#153
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

#154
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

MEGAMIND

#158
Quote from: habi2 on Nov 09, 2024, 04:11 PMAbout 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.
yes serverside.exe gets closed

Suggestion lookatplayer should be as syncd as whn npc is targetting and shooting player, add the same mechanics to lookatplayer too @habi2

habi2

#159
Hi Megamind i was not well for two days and now recovering fast.
The mechanism of creating npc with skin was created when npc didn't die. Now it dies and gets skin of the class which in your case maybe lovefist. I will fix it in next update. But you can
SendCommand("_npc_skin_request 65");
to set npc skin anytime. The above code set it to 65, as we discussed before. OnNPCSpawn might be the right place.

About server crashing issue, it is the 64-bit version of windows (and perhaps linux too) that has bug when using RFC. I will correct it.

MEGAMIND

Quote from: habi2 on Nov 12, 2024, 08:10 AMHi Megamind i was not well for two days and now recovering fast.
The mechanism of creating npc with skin was created when npc didn't die. Now it dies and gets skin of the class which in your case maybe lovefist. I will fix it in next update. But you can
SendCommand("_npc_skin_request 65");
to set npc skin anytime. The above code set it to 65, as we discussed before. OnNPCSpawn might be the right place.

About server crashing issue, it is the 64-bit version of windows (and perhaps linux too) that has bug when using RFC. I will correct it.
thanks habi i also found a work around from serverside for facing the npc towards me but it will be alot better if just single line of code can do the work easily instead of doing a full math, also get well soon

habi2

Hi Megamind,

Here is 64-bit version of plugin with RFC function fixed:
npc04rel64-windows.zip (170.53 KB)

I was writing 8 bytes in allocated memory of 4 bytes for integer. Now casted the 8 byte integer to 4 byte and write in the 4 bytes memory.

MEGAMIND

Quote from: habi2 on Nov 14, 2024, 02:59 PMHi Megamind,

Here is 64-bit version of plugin with RFC function fixed:
npc04rel64-windows.zip (170.53 KB)

I was writing 8 bytes in allocated memory of 4 bytes for integer. Now casted the 8 byte integer to 4 byte and write in the 4 bytes memory.
thats graet habi i had stoped working on npc kindof paused but ill checkit out and resume my work, thanks for your time, ill get back to u with results/bugs

MEGAMIND

#163
@habi2 Hi just tested it and i have did some crazy amount of testing on it and now its perfectly fine..! Thanks again

MEGAMIND

hey @habi2 sup man, ok so i was trying to give it a more like gta vc npc feeling but i saw in the plugin that only SendCommand("_npc_skin_request 211");
    SendCommand("_npc_weapon_request 24");
were available from npcscripts but what about if we want like anims or alot more can be asked like to send commands from npc side to server..

+ u know what people do at my server?

spawn me a car, fight me walk with me so i think i could comeup with those codes but can we have some more of these

SendCommand("_npc_anim_request someanim"); also access serverside commands from npcside, ik theres RFC but tahts from server side what im trying is to give npc a new feel also it would easily work with my chatgpt integration with it te npc will become more life like being..