Problem NPC!
#1

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.
Reply
#2

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
Reply
#3

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
Reply
#4

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);
    }
  }
Reply
#5

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;
}
Reply
#6

Thanks, I will try this!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)