I can't see my NPC
#1

Hi guys!

This problem, haunts me hours ago.

I add my NPC normally (as I will explain later), but it seems that I was in another virtualworld when I spotted it.

I tried to assign a virtualworld with "SetPlayerVirtualWorld" but it does not work.

Here's my code:

npcmodes/test.pwn
Code:
#define RECORDING "Police_Man" //I have this file in the folder npcmodes/records.
#define RECORDING_TYPE 1 //1 for in vehicle and 2 for on foot. (in this case, my NPC going in car)

#include <a_npc>
main(){}
public OnRecordingPlaybackEnd() StartRecordingPlayback(RECORDING_TYPE, RECORDING);

#if RECORDING_TYPE == 1
  public OnNPCEnterVehicle(vehicleid, seatid) StartRecordingPlayback(RECORDING_TYPE, RECORDING);
  public OnNPCExitVehicle() StopRecordingPlayback();
#else
  public OnNPCSpawn() StartRecordingPlayback(RECORDING_TYPE, RECORDING);
#endif
gamemodes/mygm.pwn

Code:
public OnGameModeInit()
{
        ConnectNPC("Police_Man", "test"); 
	NPC_Veh = CreateVehicle(602, 0.0, 0.0, 0.0, 0.0, -1, -1, 5000);  // This variable is declared higher in my code (new NPC_Veh;)
}
Code:
public OnPlayerSpawn(playerid) {
    if(IsPlayerNPC(playerid)) 
	{
	    new npcname[MAX_PLAYER_NAME];
	    GetPlayerName(playerid, npcname, MAX_PLAYER_NAME);
	    if(!strcmp(npcname, "Police_Man", true)) 
	    {
	      SetVehicleVirtualWorld(GetPlayerVehicleID(playerid), 0);
	      SetPlayerVirtualWorld(playerid, 0);
	      SetPlayerTeam(playerid, 1);
	      PutPlayerInVehicle(playerid, NPC_Veh, 0); 
	      
	    }
	    return 1;
	}

   // more code..
}
Code:
public OnPlayerConnect(playerid){
      if(IsPlayerNPC(playerid)) return 1;

// more code..
}
Code:
public OnPlayerRequestClass(playerid, classid)
{
        if(IsPlayerNPC(playerid)) return 1;

// more code..
}
server.cfg:

maxnpc 2 Enough since it is a single NPC.

The NPC connects to the server, but as I explained it looks like it's in another virtualworld.
Reply
#2

From what I can see, you have not written any code to tell the NPC to spawn (so you won't see it).

I've used the following code which works fine for my NPC..

PHP Code:
public OnNPCConnect(myplayerid)
{
    
//Send Console Message
    
new myname[MAX_PLAYER_NAME];
    
GetPlayerName(myplayeridmynameMAX_PLAYER_NAME);
    
printf("** NPC %s (ID:%i) connected to the server!"mynamemyplayerid);
    
    
//Spawn The NPC
    
SpawnPlayer(myplayerid);
    
    return 
1;

Remember you have to forward to OnNPCConnect callback, write this outside any callbacks..

PHP Code:
forward OnNPCConnect(myplayerid); 
P.s. Virtual worlds definitely won't be an issue since all players/NPCs spawn in virtual world 0 by default, unless you've specifically written code to set their world to another ID.
Reply
#3

Hi nate4, thanks for your response!

I paste this code un my GameMode outside any callbacks. But never runs the "pintf()", Then the code is not reading the callback. Do you have any idea what it will be?

Code:
forward OnNPCConnect(myplayerid);
public OnNPCConnect(myplayerid) 
{ 
    //Send Console Message 
    new myname[MAX_PLAYER_NAME]; 
    GetPlayerName(myplayerid, myname, MAX_PLAYER_NAME); 
    printf("** NPC %s (ID:%i) connected to the server!", myname, myplayerid); 
    PutPlayerInVehicle(myplayerid, NPC_Veh, 0);
     
    //Spawn The NPC 
    SpawnPlayer(myplayerid); 
     
    return 1; 
}
Reply
#4

I just realized, that the NPC now if it is in the "world" that my mappings are, but it appears static does not perform what I recorded in the .rec file
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)