SA-MP Forums Archive
[Include] Insanity Random Lists(generate a random number from your list) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Filterscripts (https://sampforum.blast.hk/forumdisplay.php?fid=17)
+---- Forum: Includes (https://sampforum.blast.hk/forumdisplay.php?fid=83)
+---- Thread: [Include] Insanity Random Lists(generate a random number from your list) (/showthread.php?tid=269457)



Insanity Random Lists(generate a random number from your list) - CyNiC - 16.07.2011

• Insanity Random Lists •
- Description


It allows you to create lists of numbers to generate a random number later
from theses lists.

- Author

Allan Jader (CyNiC)

- Note

You can change how much you want the include, leaving the credit to creator.

- Functions
pawn Code:
CreateRandomList(...);//Creates a random list and returns the id
DestroyRandomList(RandomList:ListID);//Destroys a random list
AddItemsToRandomList(RandomList:ListID, ...);//Add items to a existent random list
RemoveItemsFromRandomList(RandomList:ListID, ...);///Remove items from a existent random list
ClearRandomList(RandomList:ListID)//Remove all items from a existent random list
- Definitions and returns

pawn Code:
# MAX_RANDOM_LISTS      30 //Define as you like
# MAX_RANDOM_ITEMS      25 //Define as you like
# INVALID_LIST_ID       (RandomList:65535)
# INVALID_SLOT          65535
# INVALID_RANDOM_NUMBER 65535 //Number thats return if you try to generate a random numer of a inexistent list
- Simple script examples
pawn Code:
// *  Example 1  *
#include <a_samp>
#include <IRL>

new RandomList:MyRandomList;

public OnFilterScriptInit()
{
    MyRandomList = CreateRandomList(99,88,77,66,55,44,33,22,11);
    AddItemsToRandomList(MyRandomList, 900, 800, 700);
    RemoveItemsFromRandomList(MyRandomList, 99, 88, 77);
    printf("My Random Number: %d", RandomNumberFromList(MyRandomList));
    ClearRandomList(MyRandomList);
    printf("My Random Number: %d", RandomNumberFromList(MyRandomList));//will be printed: 65535(INVALID RANDOM NUMBER)
    return 1;
}
//* Example 2 *
new RandomList:PlayersRandomList;
new Hit[MAX_PLAYERS];

public OnGameModeInit()
{
    PlayersRandomList = CreateRandomList();
    return 1;
}

public OnPlayerConnect(playerid)
{
    AddItemsToRandomList(PlayersRandomList, playerid);
    return 1;
}

public OnPlayerDisconnect(playerid)
{
    RemoveItemsFromRandomList(PlayersRandomList, playerid);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    new msg[128], randomhitforplayer = RandomNumberFromList(PlayersRandomList);
    if(randomlistforplayer != INVALID_RANDOM_NUMBER)
    {
                GetPlayerName(randomhitforplayer, msg, MAX_PLAYER_NAME);
        format(msg, sizeof msg, "You have a new hit! Kill {FF4040}%s{FFFFFF}!", msg);
        SendClientMessage(playerid, -1, msg);
        Hit[playerid] = randomhitforplayer;    
    }
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(IsPlayerConnected(killerid))
    {
        if(Hit[killerid] == playerid)
        {
            new msg[128], randomhitforplayer = RandomNumberFromList(PlayersRandomList);
            Hit[killerid] = randomhitforplayer;
            GetPlayerName(playerid, msg, MAX_PLAYER_NAME);
            format(msg, sizeof msg, "You killed %s and earned 500$", msg);
            SendClientMessage(killerid, -1, msg);
            format(msg, sizeof msg, "You have a new hit to do! Kill {FF4040}%s{FFFFFF}!", msg);
            SendClientMessage(killerid, -1, msg);
        }
    }
}
- Download

Download here

Tags: include generate personal random numbers list


Re: Insanity Random Lists(generate a random number from your list) - FireCat - 16.07.2011

Oh nice idea, never though of this


Re: Insanity Random Lists(generate a random number from your list) - Rapgangsta - 16.07.2011

stock randoMix(...) return getarg(random(numargs()));



AW: Insanity Random Lists(generate a random number from your list) - asdfgh98 - 16.07.2011

Very useful, it were nice when you could add a function "RemoveAllRandomListItems(RandomList:ListID);" , to "clear" the list.


Re: AW: Insanity Random Lists(generate a random number from your list) - FireCat - 16.07.2011

Quote:
Originally Posted by asdfgh98
View Post
Very useful, it were nice when you could add a function "RemoveAllRandomListItems(RandomList:ListID);" , to "clear" the list.
You could just do DestroyRandomList(RandomList:ListID);
8 char


Re: Insanity Random Lists(generate a random number from your list) - wups - 16.07.2011

Quote:
Originally Posted by Rapgangsta
View Post
stock randoMix(...) return getarg(random(numargs()));
Yup, and you can do this with strings, floats etc.


AW: Re: AW: Insanity Random Lists(generate a random number from your list) - asdfgh98 - 17.07.2011

Quote:
Originally Posted by FireCat
View Post
You could just do DestroyRandomList(RandomList:ListID);
8 char
Does this function exist?


AW: Insanity Random Lists(generate a random number from your list) - asdfgh98 - 23.07.2011

I need a Function to Remove all Data from a list, please :d


Re: Insanity Random Lists(generate a random number from your list) - CyNiC - 23.07.2011

Updated with this function.


Re: AW: Insanity Random Lists(generate a random number from your list) - FireCat - 23.07.2011

Quote:
Originally Posted by asdfgh98
View Post
I need a Function to Remove all Data from a list, please :d
DestroyRandomList(RandomList:ListID);