Using an array in a function
#6

pawn Код:
new songURLS[][] =  // It is essential to use "[][]", one of them holds the number of urls and the other the string length.
{
    "http://mp3rehab.com/user_uploads_11313/Lana%20Del%20Rey%20-%20Summertime%20Sadness.mp3",
    "http://mp3rehab.com/user_uploads_11313/Eminem%20-%20Berzerk.mp3",
    "http://mp3rehab.com/user_uploads_11313/Avicii%20-%20Wake%20Me%20Up.mp3",
    "http://mp3rehab.com/user_uploads_11313/Ice%20Cube%20-%20Check%20Yo%20Self.mp3",
    "http://mp3rehab.com/user_uploads_11313/Ice%20Cube%20-%20We%20Be%20Clubbin.mp3",
    "http://mp3rehab.com/user_uploads_11313/Ice%20cube%28remix%29%20-%20Just%20bounce.mp3",
    "http://mp3rehab.com/user_uploads_11313/three%206%20mafia--3%206%20Mafia%20-%20Poppin%20My%20Collar.mp3",
    "http://mp3rehab.com/user_uploads_11313/Junior%20MAFIA%20-%20Get%20Money.mp3",
    "http://mp3rehab.com/user_uploads_11313/Fabolous%20-%20Gangsta.mp3",
    "http://mp3rehab.com/user_uploads_11313/04%20-%20AKON%20-%20Gangsta.mp3",
    "http://mp3rehab.com/user_uploads_11313/Snoop%20Dog%20Feat.%20David%20Guetta%20-%20Sweat%20%28Original%20Radio%20Edit%29.mp3",
    "http://mp3rehab.com/user_uploads_11313/metallica%20-%20the%20unforgiven.mp3",
    "http://mp3rehab.com/user_uploads_11313/Metallica%20-%20Enter%20Sandman.mp3",
    "http://mp3rehab.com/user_uploads_11313/B2K%20-%20Bada%20boom%28drop%20mix%29.mp3"
};

forward RadioSong(playerid, url[]); // Do not change this to songURLS[], or may get a warning/error.
public RadioSong(playerid, url[])  // Same as above.
{
    new Float:X, Float:Y, Float:Z, string[40], PName[MAX_PLAYER_NAME];
    GetPlayerPos(playerid, X, Y, Z);
    PRinfo[playerid][radioDeployed]=1;
    SendClientMessage(playerid, 0xFFE2E817, "You have deployed your radio at your current position.");
    PRinfo[playerid][locX]=X+2;
    PRinfo[playerid][locY]=Y;
    PRinfo[playerid][locZ]=Z;
    GetPlayerName(playerid, PName, sizeof(PName));
    format(string, sizeof(string), "%s's radio is here", PName);
    radioDeployedLabel[playerid] = Create3DTextLabel(string, 0xFFF900FF, PRinfo[playerid][locX], PRinfo[playerid][locY], PRinfo[playerid][locZ], 35.0, 0, 0);
    radioObject[playerid] = CreateObject(2103, PRinfo[playerid][locX], PRinfo[playerid][locY], PRinfo[playerid][locZ]-1, 0.0, 0.0, 0.0);
    PlayAudioStreamForPlayer(playerid, url, PRinfo[playerid][locX], PRinfo[playerid][locY], PRinfo[playerid][locZ], 20.0, 1);
    playerListeningRadio[playerid]=1;
    for (new i = 0;i<MAX_PLAYERS;i++) if(IsPlayerInRangeOfPoint(i, 10.0, PRinfo[playerid][locX], PRinfo[playerid][locY], PRinfo[playerid][locZ]) && i != playerid)
    {
        playerListeningRadio[i]=1;
        PlayAudioStreamForPlayer(i, url, PRinfo[playerid][locX], PRinfo[playerid][locY],PRinfo[playerid][locZ], 10.0, 1);
    }
    return 1;
}
Usage:
pawn Код:
RadioSong(playerid, songURLS[0]); // Any number lesser than the maximum amount of urls.
Reply


Messages In This Thread
Using an array in a function - by Tagathron - 10.11.2013, 08:33
Re: Using an array in a function - by newbie scripter - 10.11.2013, 08:39
Re: Using an array in a function - by Tagathron - 10.11.2013, 08:42
Re: Using an array in a function - by newbie scripter - 10.11.2013, 08:47
Re: Using an array in a function - by Tagathron - 10.11.2013, 08:49
Re: Using an array in a function - by Dragonsaurus - 10.11.2013, 08:58
Re: Using an array in a function - by fordawinzz - 10.11.2013, 08:59
Re: Using an array in a function - by Blacklite - 10.11.2013, 09:02

Forum Jump:


Users browsing this thread: 1 Guest(s)