16.07.2011, 15:42
(
Last edited by CyNiC; 23/07/2011 at 01:34 PM.
)
• Insanity Random Lists •
- DescriptionIt 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
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
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 here
Tags: include generate personal random numbers list