Need Help With NPC
#1

Hello, i've created NPCs 3 in Cityhalls (LS, LV, SF) according to player's virtual world.

LS Interior Virtual World = 186
LV Interior Virtual World = 185
SF Interior Virtual World = 187

when i press MMB near bot it only work for 1 bot [BOT]Jack Spawned in LS CityHall Interior.
even i press MMB in LV Cityhall it shows me [BOT]Jack work.

please help me...

my code.

OnGameModeInt
pawn Код:
ConnectNPC("[BOT]Jack","npcidle");
        ConnectNPC("[BOT]Aaron","npcidle");
        ConnectNPC("[BOT]Joshua","npcidle");
Under OnPlayerSpawn
pawn Код:
if (IsPlayerNPC(playerid))
    {

               if (!strcmp(PlayerInfo[playerid][pName],"[BOT]Jack",true))
        {
            SetPlayerPosEx(playerid,359.713867, 173.678939, 1008.389343, 269.782714, 3, 187);
            SetPlayerColor(playerid,COLOR_WANTED_LEVEL_0);

            format(string, sizeof(string), "City Hall In Temple");
            strmid(PlayerInfo[playerid][pLocation], string, 0, strlen(string), 256);

            new Text3D:Jack = Create3DTextLabel("[BOT]Jack", 0xFFFFFFFF, 30.0, 40.0, 50.0, 40.0, 0);
            Attach3DTextLabelToPlayer(Jack, playerid, 0.0, 0.0, 0.0);
        }

        if (!strcmp(PlayerInfo[playerid][pName],"[BOT]Aaron",true))
        {
            SetPlayerPosEx(playerid,359.713867, 173.678939, 1008.389343, 269.782714, 3, 185);
            SetPlayerColor(playerid,COLOR_WANTED_LEVEL_0);

            format(string, sizeof(string), "City Hall In South East Las Venturas");
            strmid(PlayerInfo[playerid][pLocation], string, 0, strlen(string), 256);

            new Text3D:Aaron = Create3DTextLabel("[BOT]Aaron", 0xFFFFFFFF, 30.0, 40.0, 50.0, 40.0, 0);
            Attach3DTextLabelToPlayer(Aaron, playerid, 0.0, 0.0, 0.0);
        }

        if (!strcmp(PlayerInfo[playerid][pName],"[BOT]Joshua",true))
        {
            SetPlayerPosEx(playerid,359.713867, 173.678939, 1008.389343, 269.782714, 3, 186);
            SetPlayerColor(playerid,COLOR_WANTED_LEVEL_0);

            format(string, sizeof(string), "City Hall In San Fierro");
            strmid(PlayerInfo[playerid][pLocation], string, 0, strlen(string), 256);

            new Text3D:Joshua = Create3DTextLabel("[BOT]Joshua", 0xFFFFFFFF, 30.0, 40.0, 50.0, 40.0, 0);
            Attach3DTextLabelToPlayer(Joshua, playerid, 0.0, 0.0, 0.0);
        }
    }
OnPlayerKeyState

pawn Код:
if (newkeys & KEY_LOOK_BEHIND || newkeys & KEY_SUBMISSION)
            {
                new npcid = -1, PlayerCount;

                for (new i = 0; i < GetMaxPlayers(); i++)
                {
                    if (IsPlayerConnected(i) && i != playerid && PlayerInfo[playerid][pDead] == 0 && GetDistanceBetweenPlayers(playerid,i) < 10)
                    {
                        if (IsPlayerNPC(i))
                        {
                            PlayerCount ++;

                            if (PlayerCount > 0) npcid = i; break;
                        }
                    }
                }

                if (npcid > -1)
                {
                    if (!strcmp(PlayerInfo[npcid][pName],"[BOT]Jack",true) || !strcmp(PlayerInfo[npcid][pName],"[BOT]Aaron",true) || !strcmp(PlayerInfo[npcid][pName],"[BOT]Joshua",true))
                    {
                        new string[256];
                        format(string, sizeof(string), "Hello, IM %s",PlayerInfo[npcid][pName]);
                        SendClientMessage(playerid, -1, string);
                    }
                }
             }
setplayerposex
pawn Код:
stock SetPlayerPosEx(playerid,Float:x,Float:y,Float:z,Float:angle,interior,world)
{
    SetPlayerPos(playerid,x,y,z);
    SetPlayerFacingAngle(playerid,angle);
    SetCameraBehindPlayer(playerid);
    SetPlayerInterior(playerid,interior);
    SetPlayerVirtualWorld(playerid,world);
    return 1;
}
Reply
#2

So, did you just decide to completely ignore the virtual world check on purpose, or...?

pawn Код:
if(newkeys & KEY_LOOK_BEHIND || newkeys & KEY_SUBMISSION)
            {
                new npcid = INVALID_PLAYER_ID, pvw = GetPlayerVirtualWorld(playerid);
                for(new i = 0; i < GetMaxPlayers(); i++)
                {
                    if(!IsPlayerConnected(i) || i == playerid) continue;
                    if(!IsPlayerNPC(i) || PlayerInfo[i][pDead] || GetDistanceBetweenPlayers(playerid, i) > 10.0) continue;
                    if(GetPlayerVirtualWorld(i) == pvw)
                    {
                        npcid = i;
                        break;
                    }
                }
                if(npcid != INVALID_PLAYER_ID)
                {
                    if(!strcmp(PlayerInfo[npcid][pName], "[BOT]Jack", true) || !strcmp(PlayerInfo[npcid][pName], "[BOT]Aaron", true) || !strcmp(PlayerInfo[npcid][pName], "[BOT]Joshua", true))
                    {
                        new string[40];
                        format(string, sizeof(string), "Hello, I'm %s", PlayerInfo[npcid][pName]);
                        SendClientMessage(playerid, -1, string);
                    }
                }
            }
Reply
#3

thanks man! +rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)