NPC problem
#1

Why won't this very simple NPC code work? (0.3d R2)

pawn Код:
#include <a_npc>

main () {
   
}

public OnNPCConnect(myplayerid) {
    new buf[64];
   
    GetPlayerName(myplayerid, buf, sizeof(buf));
   
    format(buf, sizeof(buf), "I am %s (%d).", buf, myplayerid);
   
    SendChat(buf);

    // Output: Output: "I am  (0)."
}
Edit: It seems that GetPlayerName doesn't work until OnNPCSpawn.
Reply
#2

I looked on the wiki and I didn't find that callback. I assume you've included a_samp already and have SendChat defined. Use y_hooks to hook ConnectNPC and add that.
Reply
#3

It's an NPC mode, and it does exist.
Reply
#4

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
I looked on the wiki and I didn't find that callback. I assume you've included a_samp already and have SendChat defined. Use y_hooks to hook ConnectNPC and add that.
You're really blind then: OnNPCConnect, SendChat

EDIT: Well I've tried your Little Script, a little modified by me but... :
pawn Код:
#include <a_samp>
#include <a_npc>

main ()
{
    ConnectNPC( "LOL", " " );
}

public OnGameModeInit( ) return 1;
public OnGameModeExit( ) return 1;

public OnNPCConnect( myplayerid )
{
    new buf[ 64 ];
   
    format( buf, sizeof buf, "I am %s (%d).", pName( myplayerid ), myplayerid );
    SendChat(buf);
   
    return 1;
}

pName( playerid )
{
    new s_p_N[ MAX_PLAYER_NAME ];
   
    GetPlayerName( playerid, s_p_N, sizeof s_p_N );
    return( s_p_N );
}
Errors:
Код:
NPC.pwn(12) : warning 235: public function lacks forward declaration (symbol "OnNPCConnect")
NPC.pwn(17) : error 017: undefined symbol "SendChat"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase
EDIT2: I've checked and the two natives / callbacks are in the .inc... :
pawn Код:
native SendChat(msg[]);
forward OnNPCConnect(myplayerid);
Reply
#5

I as far as I know, I think aRoach mate the ConnectNPC function must be used in the Gamemode or Filterscript Init

like this ?

pawn Код:
public OnFilterScriptInit()
{
    ConnectNPC("name","script");
    return 1;
}
https://sampwiki.blast.hk/wiki/NPC:ConnectNPC

-FalconX
Reply
#6

aRoach, you can't use a_samp in an NPC mode.

I'm not having any problems connecting the NPC, the problem is it prints out "I am (0).";
Reply
#7

Quote:
Originally Posted by ue_falconx
Посмотреть сообщение
I as far as I know, I think aRoach mate the ConnectNPC function must be used in the Gamemode or Filterscript Init

like this ?

pawn Код:
public OnFilterScriptInit()
{
    ConnectNPC("name","script");
    return 1;
}
https://sampwiki.blast.hk/wiki/NPC:ConnectNPC

-FalconX
I think you can use it everywhere, like a command and so on...

@Slice: I noticed that thing..
Reply
#8

Quote:
Originally Posted by aRoach
Посмотреть сообщение
I think you can use it everywhere, like a command and so on...

@Slice: I noticed that thing..
Hmm, there is no need of an include <a_npc> to make the npc connect, I've made a filterscript without including it with my fs.

And Slide mate if that SendChat function not works then there is always an alternative way isn't it, just an idea we can format his name and the text then put the string for SendClientMessageToAll

like this maybe?

pawn Код:
//in OnPlayerConnect?

  if(IsPlayerNPC(playerid)) //Checks if the player that is an NPC.
  {
    new string[128], npcname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, npcname, sizeof(npcname)); //Getting the NPC's name.
    format(string, sizeof(string), "%s(%d): yourmessage",npcname, playerid);
    SendClientMessageToAll(-1, string);
   }
   else
    {
     // other connect code
    }


-FalconX
Reply
#9

I'm talking about an NPC MODE not a gamemode/filterscript...
Reply
#10

Are you sure that you have maxnpc not in 0?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)