Help with teamchat threw frequencies -
AIped - 31.05.2014
Hello,
Im trying to make a radio/walkie talkie system. If you want to setup a teamchat you only have to set eachothers
radio frequencie to the same level.
the getfrequentie i made here returns the correct frequencie a player has set.
pawn Код:
new TotalFreqientie[MAX_PLAYERS];
stock GetPlayerFrequentie(playerid)
{
new frq[20];
format(frq, sizeof(frq), "%d.%d", FreqCount1[playerid],FreqCount2[playerid]);
printf(frq);
new TotalFreqientie[playerid] = GetPVarInt(playerid,frq);
return 1;
}
I just cant get the chat itself to work. (in some tryouts the text showed for all and some not at all)
pawn Код:
public OnPlayerText(playerid, text[])
{
if(text[0] == '!')
{
new string[100];
new sendername[MAX_PLAYER_NAME];
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string),":Radio: %s: %s", sendername,text[1]);
for(new i = 0; i < MAX_PLAYERS; i++)//foreach(Player,i)
{
// new frequentie = GetPlayerFrequentie(i);
if(GetPVarInt(i,TotalFreqientie[i]))
{
SendClientMessage(i,COLOR_YELLOW,string);
}
}
return 0;
}
return 1;
}
What should i do on onplayertext to make it work ?
Re: Help with teamchat threw frequencies -
Threshold - 31.05.2014
Where do you SET the player's frequency. I can make a much better alternative to this to make it work easier.
Re: Help with teamchat threw frequencies -
SyntaxQ - 31.05.2014
pawn Код:
if(GetPVarInt(i, "TotalFreqientie")) == GetPVarInt(playerid, "TotalFreqientie"))
{
SendClientMessage(i,COLOR_YELLOW,string);
}
Player radio frequency should be equal to the frequency of 'i' to chat? Do you want it like this?
Also, you don't set any value to the variable?
pawn Код:
stock GetPlayerFrequentie(playerid)
{
new frq[20];
format(frq, sizeof(frq), "%d.%d", FreqCount1[playerid],FreqCount2[playerid]);
printf(frq);
SetPVarInt(playerid, "TotalFrequientie", frq);
return 1;
}
EDIT: I think, you can simply do
return frq; without setting any variable in the stock and use it.
EDIT2: And you don't need to use the [playerid] tags with the variable when you are using PVars because they are already player variables.
Re: Help with teamchat threw frequencies -
AIped - 31.05.2014
sorry here;
pawn Код:
stock SetPlayerFrequentie(playerid)
{
new Sfrq[20];
format(Sfrq, sizeof(Sfrq), "%d.%d", FreqCount1[playerid],FreqCount2[playerid]);
printf(Sfrq);
SetPVarInt(playerid,Sfrq,1);
SendClientMessage(playerid,COLOR_WHITE,Sfrq);
return 1;
}
Syntaxq said: Player radio frequency should be equal to the frequency of 'i' to chat? Do you want it like this?
Answer : yes i do. ill try it your way
however;
@BenzoAMG : yes id like to see the alternative so i can actually learn something.
Re: Help with teamchat threw frequencies -
Zues - 31.05.2014
if(GetPVarInt(i, "TotalFreqientie")) == GetPVarInt(playerid, "TotalFreqientie"))
should be
if(GetPVarInt(i, "TotalFreqientie") == GetPVarInt(playerid, "TotalFreqientie"))
Re: Help with teamchat threw frequencies -
AIped - 31.05.2014
Yea i fixed that but still all players get to see the chat when frequency is different
AW: Help with teamchat threw frequencies -
Nero_3D - 31.05.2014
Well just store the values in the array and compare only the array in OnPlayerText
pawn Код:
static const
pFreqFrac = 100
;
static stock
pFrequency[MAX_PLAYERS]
;
stock SetPlayerFrequency(playerid, freq1, freq2) {
pFrequency[playerid] = freq1 * pFreqFrac + freq2 % pFreqFrac;
}
stock GetPlayerFrequency(playerid, & freq1, & freq2) {
freq1 = pFrequency[playerid] / pFreqFrac;
freq2 = pFrequency[playerid] % pFreqFrac;
}
stock GetPlayerFrequencyV(playerid) {
return pFrequency[playerid];
}
pawn Код:
// OnPlayerText
if(text[0] == '!') {
new
string[144],
freq = GetPlayerFrequencyV(playerid)
;
GetPlayerName(playerid, string, MAX_PLAYER_NAME);
format(string, sizeof string, ":Radio: %s: %s", string, text[1]);
for(new i; i < MAX_PLAYERS; i++) {
if(GetPlayerFrequencyV(i) == freq) {
SendClientMessage(i, COLOR_YELLOW, string);
}
}
return 0;
}
Re: Help with teamchat threw frequencies -
LowRyder - 31.05.2014
It's still not working, now we are't even able to normal chat;
We'll just try to go from scratch, it's better; Meanwhile, any ideas are way more then appreciated
Re: Help with teamchat threw frequencies -
AIped - 31.05.2014
Quote:
Originally Posted by LowRyder
It's still not working, now we are't even able to normal chat;
We'll just try to go from scratch, it's better; Meanwhile, any ideas are way more then appreciated
|
lol return 0 for the radio chat and return 1 for normal chat otherwise you get that problem
Re: Help with teamchat threw frequencies -
Threshold - 01.06.2014
Personally, I would just use a float value for the radio frequency.
pawn Код:
stock SetPlayerFrequentie(playerid)
{
new str[20];
Frequency[playerid] = (random(1000) / 100);
format(str, sizeof(str), "Frequency: %0.2f", Frequency[playerid]);
SendClientMessage(playerid, COLOR_WHITE, str);
return 1;
}
Then at the top of your script, or in your enum:
pawn Код:
//New var
new Float:Frequency[MAX_PLAYERS];
//Enum
Float:Frequency[MAX_PLAYERS];