NPC problem -
niels44 - 15.10.2012
hey everyone,
im trying to create a bot and puts it in a vehicle when someone does /test, but instead of putting the bot in the car, it puts me or another player in the car...
anyways this is my code:
pawn Code:
public OnGameModeInit()
{
SetGameModeText("StreetRodzRacers");
AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
FirstRaceBotVehicle = CreateVehicle(517,2656.8381,-2005.3379,13.0751,0,0,0,-1);
FirstRaceBot = ConnectNPC( "FirstRaceBot", "npcdriver" );
return 1;
}
pawn Code:
CMD:test(playerid, params[])
{
SetPlayerRaceCheckpoint(playerid, 0, -1714.984741, 1027.797485, 45.036315, -1725.589111, 926.632080, 24.717582, 10.0);
CheckPointID++;
SendClientMessage(playerid, 0xFF0000FF, "test started");
PutPlayerInVehicle(FirstRaceBot, FirstRaceBotVehicle, 0);
WaitForBot(FirstRaceBot, FIRSTRACE, "startfirstrace");
return 1;
}
pawn Code:
WaitForBot( playerid, menu, action[] )
{
PlayerInfo[playerid][botready] = false;
SendClientMessage(FirstRaceBot, COLOR_GREEN, action );
PlayerInfo[playerid][waitingforbot] = SetTimerEx("WaitForBotTimer",250,true,"dd",playerid,menu );
return 1;
}
public WaitForBotTimer( playerid, menu )
{
if( PlayerInfo[playerid][botready] ) // This is handled inside npcdriver.pwn
{
KillTimer(PlayerInfo[playerid][waitingforbot]);
switch(menu)
{
case FIRSTRACE:
{
}
}
}
return 1;
}
does anyone sees wuts wrong in this code?
greets niels
Re: NPC problem -
clavador - 16.10.2012
Your problem is here:
Code:
FirstRaceBot = ConnectNPC( "FirstRaceBot", "npcdriver" );
ConnectNPC doesnt return anything, so your variable FirstRaceBot is something else.
If you want to link an npc to an id, you can make a check inside OnPlayerConnect and check the name of the bot, if the bot's name is the the name you're looking for, then assing a variable that identifies that bot to it's player id, like:
Code:
OnPlayerConnect(playerid)
{
if( IsPlayerNPC(playerid) ){
new name[24];
GetPlayerName(playerid, name, sizeof(name));
if( name == "FirstRaceBot" ){
//Is the bot we are looking for, so we assing a variable to it.
FirstRaceBot = playerid;
}
}
}
If you want to link a bot to a player id, it's a little more complicated, but you should be able to figure it out with this piece of code.
Re: NPC problem -
niels44 - 16.10.2012
Thnx

, i thought it was something wuth this in begin, butvdidnt jnew how i should it in other way so i searched for sonething else
Anyways thnx again

DD