| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787 |
- #define COLOR_RED (0xFF0000FF)
- #define COLOR_YELLOW (0xFFFF00FF)
- #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1 // Courtesy of DracoBlue
- #include <a_samp>
- #include <audio>
- public
- OnFilterScriptInit()
- {
- // Set the audio pack when the filterscript loads
- Audio_SetPack("default_pack", true);
- return 1;
- }
- /*
- Here are some testing commands.
- */
- public
- OnPlayerCommandText(playerid, cmdtext[])
- {
- dcmd(createsequence, 14, cmdtext);
- dcmd(destroysequence, 15, cmdtext);
- dcmd(addtosequence, 13, cmdtext);
- dcmd(removefromsequence, 18, cmdtext);
- dcmd(play, 4, cmdtext);
- dcmd(playsequence, 12, cmdtext);
- dcmd(playstreamed, 12, cmdtext);
- dcmd(pause, 5, cmdtext);
- dcmd(resume, 6, cmdtext);
- dcmd(stop, 4, cmdtext);
- dcmd(restart, 7, cmdtext);
- dcmd(seek, 4, cmdtext);
- dcmd(setvolume, 9, cmdtext);
- dcmd(set3dposition, 13, cmdtext);
- dcmd(set3doffsets, 12, cmdtext);
- dcmd(seteax, 6, cmdtext);
- dcmd(removeeax, 9, cmdtext);
- dcmd(setfx, 5, cmdtext);
- dcmd(removefx, 8, cmdtext);
- dcmd(connected, 9, cmdtext);
- dcmd(setpack, 7, cmdtext);
- return 0;
- }
- dcmd_createsequence(playerid, params[])
- {
- #pragma unused playerid, params
- new
- sequenceid,
- string[64];
- sequenceid = Audio_CreateSequence();
- if (sequenceid)
- {
- format(string, sizeof(string), "Sequence ID %d created", sequenceid);
- }
- else
- {
- format(string, sizeof(string), "Error creating sequence ID %d", sequenceid);
- }
- SendClientMessageToAll(COLOR_YELLOW, string);
- return 1;
- }
- dcmd_destroysequence(playerid, params[])
- {
- #pragma unused playerid
- new
- sequenceid = strval(params);
- if (!sequenceid)
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /destroysequence <sequenceid>");
- return 1;
- }
- new
- string[64];
- if (Audio_DestroySequence(sequenceid))
- {
- format(string, sizeof(string), "Sequence ID %d destroyed", sequenceid);
- }
- else
- {
- format(string, sizeof(string), "Error destroying sequence ID %d", sequenceid);
- }
- SendClientMessageToAll(COLOR_YELLOW, string);
- return 1;
- }
- dcmd_addtosequence(playerid, params[])
- {
- #pragma unused playerid
- new
- audioid,
- sequenceid;
- if (sscanf(params, "dd", sequenceid, audioid))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /addtosequence <sequenceid> <audioid>");
- return 1;
- }
- new
- string[64];
- if (Audio_AddToSequence(sequenceid, audioid))
- {
- format(string, sizeof(string), "Audio ID %d added to sequence ID %d", audioid, sequenceid);
- }
- else
- {
- format(string, sizeof(string), "Error adding audio ID %d to sequence ID %d", audioid, sequenceid);
- }
- SendClientMessageToAll(COLOR_YELLOW, string);
- return 1;
- }
- dcmd_removefromsequence(playerid, params[])
- {
- #pragma unused playerid
- new
- audioid,
- sequenceid;
- if (sscanf(params, "dd", sequenceid, audioid))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /removefromsequence <sequenceid> <audioid>");
- return 1;
- }
- new
- string[64];
- if (Audio_RemoveFromSequence(sequenceid, audioid))
- {
- format(string, sizeof(string), "Audio ID %d removed from sequence ID %d", audioid, sequenceid);
- }
- else
- {
- format(string, sizeof(string), "Error removing audio ID %d from sequence ID %d", audioid, sequenceid);
- }
- SendClientMessageToAll(COLOR_YELLOW, string);
- return 1;
- }
- dcmd_play(playerid, params[])
- {
- #pragma unused playerid
- new
- audioid,
- bool:downmix,
- bool:loop,
- bool:pause;
- if (sscanf(params, "dddd", audioid, pause, loop, downmix))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /play <audioid> <pause (0/1)> <loop (0/1)> <downmix (0/1)>");
- return 1;
- }
- Audio_Play(playerid, audioid, pause, loop, downmix);
- return 1;
- }
- dcmd_playsequence(playerid, params[])
- {
- #pragma unused playerid
- new
- audioid,
- bool:downmix,
- bool:loop,
- bool:pause;
- if (sscanf(params, "dddd", audioid, pause, loop, downmix))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /playsequence <sequenceid> <pause (0/1)> <loop (0/1)> <downmix (0/1)>");
- return 1;
- }
- Audio_PlaySequence(playerid, audioid, pause, loop, downmix);
- return 1;
- }
- dcmd_playstreamed(playerid, params[])
- {
- #pragma unused playerid
- new
- bool:downmix,
- bool:loop,
- bool:pause,
- url[256];
- if (sscanf(params, "sddd", url, pause, loop, downmix))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /playstreamed <url> <pause (0/1)> <loop (0/1)> <downmix (0/1)>");
- return 1;
- }
- Audio_PlayStreamed(playerid, url, pause, loop, downmix);
- return 1;
- }
- dcmd_pause(playerid, params[])
- {
- #pragma unused playerid
- new
- handleid = strval(params);
- if (!handleid)
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /pause <handleid>");
- return 1;
- }
- new
- string[64];
- format(string, sizeof(string), "Audio playback paused for handle ID %d", handleid);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- Audio_Pause(playerid, handleid);
- return 1;
- }
- dcmd_resume(playerid, params[])
- {
- #pragma unused playerid
- new
- handleid = strval(params);
- if (!handleid)
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /resume <handleid>");
- return 1;
- }
- new
- string[64];
- format(string, sizeof(string), "Audio playback resumed for handle ID %d", handleid);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- Audio_Resume(playerid, handleid);
- return 1;
- }
- dcmd_stop(playerid, params[])
- {
- #pragma unused playerid
- new
- handleid = strval(params);
- if (!handleid)
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /stop <handleid>");
- return 1;
- }
- Audio_Stop(playerid, handleid);
- return 1;
- }
- dcmd_restart(playerid, params[])
- {
- #pragma unused playerid
- new
- handleid = strval(params);
- if (!handleid)
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /restart <handleid>");
- return 1;
- }
- new
- string[64];
- format(string, sizeof(string), "Audio playback restarted for handle ID %d", handleid);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- Audio_Restart(playerid, handleid);
- return 1;
- }
- dcmd_seek(playerid, params[])
- {
- #pragma unused playerid
- new
- handleid,
- seconds;
- if (sscanf(params, "dd", handleid, seconds))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /seek <handleid> <seconds>");
- return 1;
- }
- new
- string[64];
- format(string, sizeof(string), "Audio seeked to %d seconds for handle ID %d", seconds, handleid);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- Audio_Seek(playerid, handleid, seconds);
- return 1;
- }
- dcmd_setvolume(playerid, params[])
- {
- #pragma unused playerid
- new
- handleid,
- volume;
- if (sscanf(params, "dd", handleid, volume))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /setvolume <handleid> <volume (0-100)>");
- return 1;
- }
- new
- string[64];
- format(string, sizeof(string), "Audio volume set to %d for handle ID %d", volume, handleid);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- Audio_SetVolume(playerid, handleid, volume);
- return 1;
- }
- dcmd_set3dposition(playerid, params[])
- {
- #pragma unused playerid
- new
- handleid,
- Float:distance,
- Float:x,
- Float:y,
- Float:z;
- if (sscanf(params, "dffff", handleid, x, y, z, distance))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /set3dposition <handleid> <x> <y> <z> <distance>");
- return 1;
- }
- new
- string[128];
- format(string, sizeof(string), "Audio 3D position set to %.01f, %.01f, %.01f (distance: %.01f) for handle ID %d", x, y, z, distance, handleid);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- Audio_Set3DPosition(playerid, handleid, x, y, z, distance);
- return 1;
- }
- dcmd_set3doffsets(playerid, params[])
- {
- #pragma unused playerid
- new
- handleid,
- Float:x,
- Float:y,
- Float:z;
- if (sscanf(params, "dfff", handleid, x, y, z))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /set3doffsets <handleid> <x> <y> <z>");
- return 1;
- }
- new
- string[128];
- format(string, sizeof(string), "Audio 3D offsets set to %.01f, %.01f, %.01f for handle ID %d", x, y, z, handleid);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- Audio_Set3DOffsets(playerid, handleid, x, y, z);
- return 1;
- }
- dcmd_seteax(playerid, params[])
- {
- #pragma unused playerid
- new
- environment;
- if (sscanf(params, "d", environment))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /seteax <environment (0-25)>");
- return 1;
- }
- new
- string[64];
- format(string, sizeof(string), "Audio EAX environment set to %d", environment);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- Audio_SetEAX(playerid, environment);
- return 1;
- }
- dcmd_removeeax(playerid, params[])
- {
- #pragma unused params, playerid
- new
- string[32];
- format(string, sizeof(string), "Audio EAX environment removed");
- SendClientMessage(playerid, COLOR_YELLOW, string);
- Audio_RemoveEAX(playerid);
- return 1;
- }
- dcmd_setfx(playerid, params[])
- {
- #pragma unused playerid
- new
- handleid,
- type;
- if (sscanf(params, "dd", handleid, type))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /setfx <handleid> <type (0-8)>");
- return 1;
- }
- new
- string[64];
- format(string, sizeof(string), "Audio FX type %d applied to handle ID %d", type, handleid);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- Audio_SetFX(playerid, handleid, type);
- return 1;
- }
- dcmd_removefx(playerid, params[])
- {
- #pragma unused playerid
- new
- handleid,
- type;
- if (sscanf(params, "dd", handleid, type))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /removefx <handleid> <type (0-8)>");
- return 1;
- }
- new
- string[64];
- format(string, sizeof(string), "Audio FX type %d removed from handle ID %d", type, handleid);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- Audio_RemoveFX(playerid, handleid, type);
- return 1;
- }
- dcmd_connected(playerid, params[])
- {
- new
- clientMsg[32];
- if (Audio_IsClientConnected(strval(params)))
- {
- format(clientMsg, sizeof(clientMsg), "Client ID %d is connected", strval(params));
- SendClientMessage(playerid, COLOR_YELLOW, clientMsg);
- }
- else
- {
- format(clientMsg, sizeof(clientMsg), "Client ID %d is not connected", strval(params));
- SendClientMessage(playerid, COLOR_YELLOW, clientMsg);
- }
- return 1;
- }
- dcmd_setpack(playerid, params[])
- {
- if (!IsPlayerAdmin(playerid))
- {
- SendClientMessage(playerid, COLOR_RED, "ERROR: You do not have permission to use this command.");
- return 1;
- }
- new
- audiopack[32],
- bool:transferable;
- if (sscanf(params, "sd", audiopack, transferable))
- {
- SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /setpack <audiopack> <transferable (0/1)>");
- return 1;
- }
- Audio_SetPack(audiopack, transferable);
- return 1;
- }
- public
- Audio_OnClientConnect(playerid)
- {
- new
- string[128];
- format(string, sizeof(string), "Audio client ID %d connected", playerid);
- SendClientMessageToAll(COLOR_YELLOW, string);
- // Transfer the audio pack when the player connects
- Audio_TransferPack(playerid);
- return 1;
- }
- public
- Audio_OnClientDisconnect(playerid)
- {
- new
- string[128];
- format(string, sizeof(string), "Audio client ID %d disconnected", playerid);
- SendClientMessageToAll(COLOR_YELLOW, string);
- return 1;
- }
- public
- Audio_OnPlay(playerid, handleid)
- {
- new
- string[64];
- format(string, sizeof(string), "Audio playback started for handle ID %d", handleid);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- return 1;
- }
- public
- Audio_OnStop(playerid, handleid)
- {
- new
- string[64];
- format(string, sizeof(string), "Audio playback stopped for handle ID %d", handleid);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- return 1;
- }
- public
- Audio_OnSetPack(audiopack[])
- {
- new
- string[64];
- format(string, sizeof(string), "Audio pack \"%s\" set", audiopack);
- for (new i = 0; i < MAX_PLAYERS; i++)
- {
- // Transfer the audio pack to all players when it is set
- Audio_TransferPack(i);
- }
- return 1;
- }
- public
- Audio_OnTransferFile(playerid, file[], current, total, result)
- {
- new
- string[128];
- switch (result)
- {
- case 0:
- {
- format(string, sizeof(string), "Audio file \"%s\" (%d of %d) finished local download", file, current, total);
- }
- case 1:
- {
- format(string, sizeof(string), "Audio file \"%s\" (%d of %d) finished remote download", file, current, total);
- }
- case 2:
- {
- format(string, sizeof(string), "Audio archive \"%s\" (%d of %d) finished extraction", file, current, total);
- }
- case 3:
- {
- format(string, sizeof(string), "Audio file/archive \"%s\" (%d of %d) passed check", file, current, total);
- }
- case 4:
- {
- format(string, sizeof(string), "Audio file/archive \"%s\" (%d of %d) could not be downloaded or extracted", file, current, total);
- }
- }
- SendClientMessage(playerid, COLOR_YELLOW, string);
- if (current == total)
- {
- SendClientMessage(playerid, COLOR_YELLOW, "All files have been processed");
- }
- return 1;
- }
- public
- Audio_OnTrackChange(playerid, handleid, track[])
- {
- new
- string[128];
- format(string, sizeof(string), "Now playing \"%s\" for handle ID %d", track, handleid);
- SendClientMessage(playerid, COLOR_YELLOW, string);
- }
- stock
- sscanf(string[], format[], {Float,_}:...)
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = string[stringPos];
- do
- {
- stringPos++;
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- setarg(paramPos, 0, _:floatstr(string[stringPos]));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
|