20.12.2011, 13:05
Hi.
How can I move that code from fs to gamemode?
I tried to just move it's part to correct callbacks but it doesn't work.
How can I move that code from fs to gamemode?
Код:
/* CB Radio System; By Ash (funky1234) Do what you want with it, I don't really care. */ #include <a_samp> new pChannel[MAX_PLAYERS]; #define COLOUR_RED 0xFF0000FF #define COLOUR_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 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(cbchannel, 9, cmdtext); dcmd(cb, 2, cmdtext); return 0; } dcmd_cbchannel(playerid, params[]) { if(!strlen(params) /*&& !IsNumeric(params)*/) return SendClientMessage(playerid, 0x00FFCCFF, "Usage: \"/cbchannel <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, 0x00FFCCFF, "Please select 1-40 channel."); //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. static zmiana[128]; format(zmiana, sizeof(zmiana), "[CB] You changed CB channel to %i.", pChannel[playerid]); SendClientMessage(playerid, 0x00FFCCFF, zmiana); return 1; //Return 1 (command complete) } dcmd_cb(playerid, params[]) { if(!strlen(params)) return SendClientMessage(playerid, 0x00FFCCFF, "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 %i] %s: %s", pChannel[playerid], 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, 0x00FFCCFF, str); } } return 1; //End the command (return 1) } stock ReturnName(playerid) { static name[24]; GetPlayerName(playerid, name, 24); return name; }