[Include] Insanity Random Lists(generate a random number from your list)
#1

• 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
Reply
#2

Oh nice idea, never though of this
Reply
#3

stock randoMix(...) return getarg(random(numargs()));
Reply
#4

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

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
Reply
#6

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

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

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

Updated with this function.
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)