[Tutorial] Making a CB Radio System.
#9

Quote:
Originally Posted by fatspeeddog
View Post
pawn Code:
#include <a_samp>

new pChannel[MAX_PLAYERS];

#define COLOR_RED 0xFF0000FF
#define COLOR_YELLOW 0xFFFF00FF
#define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1

//publics

public OnPlayerDisconnect(playerid, reason)
{
    #pragma unused reason
    pChannel[playerid] = 0;
    return 1;
}

public OnPlayerSpawn(playerid)
{
    pChannel[playerid] = 1;
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    dcmd(cbch, 4, cmdtext);
    dcmd(cb, 2, cmdtext);
    return 0;
}

public OnPlayerConnect(playerid)
{
    SendClientMessage(playerid, COLOR_RED, "CB-Radio-System. Use /cbch [1-40] to select a CH.");
    SendClientMessage(playerid, COLOR_YELLOW, "Use /cb [message] to speak with players into the same channel.");
    SendClientMessage(playerid, COLOR_RED, "have FUN with your new CB-Radio.");
    return 1;
}

//commands

dcmd_cbch(playerid, params[])
{
    if(!strlen(params)) /*&& !IsNumeric(params)*/ return SendClientMessage(playerid, COLOR_RED, "No parameters (Usage: /cbch [1-40]");
    //If the length of params is 0 (non existent) - it returns an error message
    //I have commeneted our "IsNumeric" because I am not supplying it with the tutorial (because I can't find it!)
    if(strval(params) < 1 || strval(params) > 40) return SendClientMessage(playerid, COLOR_RED, "Only channels 1 upto 40 exist");
    //If the integer value of the parameters string is lower than 1 or bigger than 40 then it returns another error message
    pChannel[playerid] = strval(params);
    //Set the players channel
        //You may also want to add a "Your channel is now %i" message.
    return 1;
    //Return 1 (command complete)
}

dcmd_cb(playerid, params[])
{
    if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "No parameters (Usage: /cb [message]");
    //Error message if the player did not specify any parameters
    static str[128];
    //Why static? It stops it being created more than once (in fact if you decompiled an AMX script you would find the "static" variable has become GLOBAL)
    format(str, sizeof(str), "[CB]%s: %s", ReturnName(playerid), params);
    //Format the output message (str)
    //ReturnName, is a function to return a players name - I will include it toward the end of this post
    //You could use colour embedding here!
    for(new i; i < GetMaxPlayers(); i++)
    {
        //Start the loop (GetMaxPlayers will return the MAXIMUM player slots on your server - you could use Foreach here instead)
        if(!IsPlayerConnected(i)) continue;
        //If the player is not connected, skip to the next one
        if(pChannel[i] == pChannel[playerid])
        {
            //If the player channel matches the other players channel
            SendClientMessage(i, COLOR_YELLOW, str);
        }
    }
    return 1;
    //End the command (return 1)
}

stock ReturnName(playerid)
{
    static name[24];
    GetPlayerName(playerid, name, 24);
    return name;
}
What done I wrong
You have done nothing wrong.
Also, I replied to your post on the Filterscript thread.
Reply


Messages In This Thread
Making a CB Radio System. - by Ash. - 07.07.2011, 10:28
Re : Making a CB Radio System. - by Ligeti Ferenc - 07.07.2011, 10:44
Re: Making a CB Radio System. - by Rock_Ro - 07.07.2011, 10:48
Re : Making a CB Radio System. - by Ligeti Ferenc - 07.07.2011, 10:50
Re: Making a CB Radio System. - by Ash. - 07.07.2011, 10:59
Re: Making a CB Radio System. - by Mark_Weston - 07.07.2011, 10:59
Re: Making a CB Radio System. - by [HUN]Poldzsiii - 21.07.2011, 08:16
AW: Making a CB Radio System. - by fatspeeddog - 31.07.2011, 08:15
Re: AW: Making a CB Radio System. - by Ash. - 03.08.2011, 10:26
Re: Making a CB Radio System. - by dickyodie - 23.09.2011, 12:43

Forum Jump:


Users browsing this thread: 2 Guest(s)