CyberMor/sampvoice

Plugin samp voice frequency

Opened this issue · 0 comments

hiwyn commented

I tried but fail to put radio frequencies on samp voice...

2 problems:

1- you can hear and talk to everyone in any frequency, i mean you are in 3000, you can talk to people on 5000
2- server crashes a while after people use this

What i'm doing wrong?

global

#define MAX_RADIOS 9999
forward ConnectRadioVoice(playerid);
forward DisconnectRadioVoice(playerid);
new SV_GSTREAM:StreamFreq[MAX_RADIOS] = SV_NULL;
new players_in_radiofrequency[MAX_RADIOS];

OnPlayerActivationKeyPress

// radio voice
if(radio_frequency[playerid] == 0) {
    SvAttachSpeakerToStream(StreamFreq[radio_frequency[playerid]], playerid);
}
// voice local
else {
    SvAttachSpeakerToStream(lstream[playerid], playerid);
}

OnPlayerActivationKeyRelease

    // Detach the player from the local stream if the 'B' key is released
    if (keyid == 0x42 && lstream[playerid]) {
        SvDetachSpeakerFromStream(lstream[playerid], playerid);
    }
    // Detach the player from the local stream if the 'B' key is released
    if (keyid == 0x42 && StreamFreq[radio_frequency[playerid]]) {
        SvDetachSpeakerFromStream(StreamFreq[radio_frequency[playerid]], playerid);
    }

functions from command

public ConnectRadioVoice(playerid) {
    new rfid = radio_frequency[playerid];
    if(StreamFreq[rfid] == SV_NULL)
    {
        new string[128];
        format(string, sizeof(string), "Radio %i", rfid);
        StreamFreq[rfid] = SvCreateGStream(0xFF00FFFF, string);
        SvAttachListenerToStream(StreamFreq[rfid], playerid);
    }
    else
    {
        SvAttachListenerToStream(StreamFreq[rfid], playerid);
    }
    players_in_radiofrequency[rfid] += 1;
    return 1;
}
public DisconnectRadioVoice(playerid) {
    new rfid = radio_frequency[playerid];
    players_in_radiofrequency[rfid] -= 1;
    if(players_in_radiofrequency[rfid] <= 0) {
      StreamFreq[rfid] = SV_NULL;
    }
    return 1;
}

command

CMD:radio(playerid, params[]) {
    new frequency_id;
    if(sscanf(params,"i", frequency_id)) return SendClientMessage(playerid, -1, "Use: /testid [id]");
    if(frequency_id > MAX_RADIOS || frequency_id < 1) return SendClientMessage(playerid, -1, "O numero deve ser entre 1 e MAX_RADIOS");
    radio_frequency[playerid] = frequency_id;
    if(frequency_id == 0) DisconnectRadioVoice(playerid);
    else ConnectRadioVoice(playerid);
    return 1;
}