SA-MP Forums Archive
Problem NPC! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem NPC! (/showthread.php?tid=254305)



Problem NPC! - Ruto - 10.05.2011

Hi!!

I have a problem with my FS.
I will make a FS where the recording restart when I type /r
We can't use StopRecordingPlayback and StartRecordingPlayback in a FS (if you succeed this, thanks to say me how you do).
This is why, I'm require to Kick NPC and ConnectNPC for restart his recording.

This is a little part of my FS:

Код:
#include <a_samp>

public OnPlayerSpawn(playerid)
{
	if(IsPlayerNPC(playerid))
	{
    	          PutPlayerInVehicle(playerid, Veh, 0); //The NPC enter in his vehicle
	}
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
        if (strcmp("/r", cmdtext, true) == 0)
	{
			if(npc[playerid] != -1) Kick(npc[playerid]); //If the NPC already connected = Kick
   			new name[16], name2[20];
     		        GetPlayerName(playerid, name, sizeof(name));
      		        format(name2, sizeof(name2), "NPC_%s", name);
                        new id=0;
                        while(IsPlayerConected(id)) id++
       		        npc[playerid] = id; //This is the new NPC's id
        	        ConnectNPC(name2, "npc");
                        return 1;
	}
	return 0;
}
When I type /r, the npc won't connect to the server or will connect but won't enter in his vehicle.

Thank you in advance !!

Sorry for my bad english.


Re: Problem NPC! - itachi4x4 - 10.05.2011

pawn Код:
PutPlayerInVehicle(playerid, Veh, 0); //The NPC enter in his vehicle
This is what you did
If the guy who spawned is an npc, then put YOU (playerid) in "Veh"
Change it to this

pawn Код:
PutPlayerInVehicle(npc, Veh, 0); //The NPC enter in his vehicle



Re: Problem NPC! - Ruto - 10.05.2011

When the npc spawns, I put it in his vehicle!
This is why, playerid = npc's id in PutPlayerInVehicle(playerid, Veh, 0);
Maybe this is wrong :-S


Re: Problem NPC! - Biesmen - 10.05.2011

Try this:
pawn Код:
//Somewhere at the top of your script
    new NPCName[MAX_PLAYERS][30];
           //OnPlayerCommandText
    if (strcmp("/r", cmdtext, true) == 0)
    {
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        format(NPCName[playerid], 30, "NPC_%s", name);
        new id = 0;
        while(IsPlayerConnected(id))
        {
            id++;
        }
        npc[playerid] = id; //This is the new NPC's id
        ConnectNPC(NPCName, "npc");
        return 1;
    }
    // At OnplayerSpawn
  if(IsPlayerNPC(playerid))
  {
    new npcname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, npcname, sizeof(npcname));
    if(!strcmp(npcname, NPCName[playerid], true))
    {
      PutPlayerInVehicle(playerid, Veh, 0);
    }
  }



AW: Problem NPC! - Nero_3D - 10.05.2011

There was something similar some months ago, there it is

pawn Код:
stock RestartPlayback(const npc_playerid)
{ //By Nero_3D
    if(IsPlayerNPC(npc_playerid)) {
        new
            vehicleid = GetPlayerVehicleID(npc_playerid);
        if(vehicleid) {
            PutPlayerInVehicle(npc_playerid, vehicleid, 0);
        } else {
            SpawnPlayer(npc_playerid);
        }
        return true;
    }
    return false;
}



Re: Problem NPC! - Ruto - 11.05.2011

Thanks, I will try this!