All got same nick as id 0
#1

Hi, I have problem with my script. When i'm converting from pwn to amx everything is ok but on server all have got same nick as id 0. Player with id 0 see normal nicks but other players see only id 0 nick.


Code:
#include <a_samp>

#define MAX_MESSAGES 100

#define TIMER 60000

#define COLOR_BOT 0x0099EEFF

new BotName[24] = "Leszczu";
new RANDOMMSG = 1;
new MAXMESSAGE;
new BOTMESSAGE[MAX_PLAYERS][128];

forward Random(playerid);

new RandomMsg[][] =
{
	"Niech kurwy siadają nie będą przecież stały",
	"Nie pękaj bracie bo pękają gacie",
	"Raz dwa trzy wypierdalamy drzwi ",
	"Kurwy tańczą jak im zagram "
};

public OnFilterScriptInit()
{
	if(RANDOMMSG == 1)
	{
		SetTimer("SendRandomMessage",TIMER,1);
	}

	AddRandomMessage("Niech kurwy siadają nie będą przecież stały");
	AddRandomMessage("Nie pękaj bracie bo pękają gacie");
	AddRandomMessage("Raz dwa trzy wypierdalamy drzwi");
	AddRandomMessage("Kurwy tańczą jak im zagram");
	AddRandomMessage("Jest melina i posypana kokaina");
	AddRandomMessage("Dziwki właśnie przyjechały i opierdalają gały");
	AddRandomMessage("Lecimy na bogato pierdolona szmato");


	print("Shadow's Chatbot Loaded");
	return 1;
}

public OnPlayerConnect(playerid)
{
	SendBotMessage("Yoł skurwiele jest balanga u leszcza");
	return 1;
}

forward SendRandomMessage();
public SendRandomMessage()
{
	for(new playerid=0;playerid<MAX_PLAYERS;playerid++)
	{
	 * *if(IsPlayerConnected(playerid)==1 && GetPlayerColor(playerid) != 0)
	 * *{
			new pName[18];
			format(pName,sizeof(pName),"%s",PlayerName(playerid));
			new ColorSave = GetPlayerColor(playerid);
			SetPlayerColor(playerid,COLOR_BOT);
			SetPlayerName(playerid,BotName);
			SendPlayerMessageToAll(playerid,BOTMESSAGE[random(MAXMESSAGE)]);
			SetPlayerColor(playerid,ColorSave);
			SetPlayerName(playerid,pName);
			return 1;
		}
	}
	return 1;
}

forward SendBotMessage(msg[]);
public SendBotMessage(msg[])
{
	for(new playerid=0;playerid<MAX_PLAYERS;playerid++)
	{
	 * *if(IsPlayerConnected(playerid)==1 && GetPlayerColor(playerid) != 0)
	 * *{
			new pName[18];
			format(pName,sizeof(pName),"%s",PlayerName(playerid));
			new ColorSave = GetPlayerColor(playerid);
			SetPlayerColor(playerid,COLOR_BOT);
			SetPlayerName(playerid,BotName);
			SendPlayerMessageToAll(playerid,msg);
			SetPlayerColor(playerid,ColorSave);
			SetPlayerName(playerid,pName);
			return 1;
		}
	}
	return 1;
}

stock AddRandomMessage(msg[])
{
	format(BOTMESSAGE[MAXMESSAGE],128,"%s",msg);
	MAXMESSAGE++;
	return 1;
}

stock PlayerName(playerid)
{
	new pName2[MAX_PLAYER_NAME];
	GetPlayerName(playerid, pName2, MAX_PLAYER_NAME);
	return pName2;
}

public OnPlayerText(playerid, text[])
{
 * *if(!strcmp(text, "siema", true) || !strcmp(text, "elo", true) || !strcmp(text, "czesc", true) || !strcmp(text, "witam", true))
	{
 * *	SendPlayerMessageToAll(playerid, text);
		SendBotMessage("Siema. Tu Leszczu zaraz rozpalamy grila");
		return 0;
	}
	
	if(!strcmp(text, "Hi", true) || !strcmp(text, "Sup", true) || !strcmp(text, "Sophie", true) || !strcmp(text, "Hiya", true))
	{
		SendPlayerMessageToAll(playerid, text);
		Random(playerid);
		return 0;
	}

	return 1;
}

public Random(playerid)
{
		new str[128];
		new randMSG = random(sizeof(RandomMsg));
		format(str, sizeof(str), "%s %s", RandomMsg[randMSG], PlayerName(playerid));
 * *	SendBotMessage(str);
 * * * *return 1;
}
My friend said me to paste it:

Code:
forward SendBotMessage(msg[]); 
public SendBotMessage(msg[]) 
{ 
for(new playerid=0;playerid<MAX_PLAYERS;playerid++) 
{ 
if(IsPlayerConnected(playerid)==1 && GetPlayerColor(playerid) != 0) 
{ 
new pName[18]; 
format(pName,sizeof(pName),"%s",PlayerName(playerid)); 
new ColorSave = GetPlayerColor(playerid); 
SetPlayerColor(playerid,COLOR_BOT); 
SendPlayerMessageToAll(playerid,msg); 
return 1; 
} 
} 
return 1;
But later i have errors like this:


Code:
 C:\Users\Real Madrid\Desktop\nowyleszcz.pwn(94) : error 021: symbol already defined: "SendBotMessage" 
C:\Users\Real Madrid\Desktop\as.txt(101) : warning 204: symbol is assigned a value that is never used: "ColorSave" 
C:\Users\Real Madrid\Desktop\as.txt(101 -- 107) : warning 217: loose indentation
I found on this forum solution but idk how to use it ;/


Code:
Code:
if(IsPlayerConnected(playerid)==1 && GetPlayerColor(playerid) != 0)
As explained by SA-MP, if a player doesn't have his colour changed by the script (SetPlayerColor), the players colour will be 0.

Just use a integer, when the player connects check if it's a bot (strcmp it's name), then set the integer (im_a_bot)to the playerid.
Code:
new im_a_bot = -1;
Code:
public OnPlayerConnect(playerid)
{
 * *if(strcmp("Rac3r(Bot)", PlayerName(playerid), true)==0)im_a_bot = playerid;
 * *return 1; // end of code, obviously
}
Then, instead of a MAX_PLAYERS loop, just use:
Code:
public SendBotMessage(msg[])
{ * *
 * *if(im_a_bot != -1)
 * *{
 * * * * new pName[18]; * * * * * *
 * * * * format(pName,sizeof(pName),"%s",PlayerName(im_a_bot));
 * * * * .....// and so on;
Use your head, make a check OnPlayerDisconnect, if the chatting bot disconnects, set im_a_bot to -1.

Can someone do it ?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)