26.08.2016, 13:53
I have decided to create a random message system, But this isn't one of these regular random message where in they are placed in an array. Instead, they will be created dynamically, Loaded/Saved/Inserted in the database. So far I am not having any problems on loading, saving or inserting the data on the database; However I am having a hard time on coding the part where the HintMessage() generates the next random message. Is it possible to randomized the next message just like in the regular random message system? Like for example; I have 3 random messages in the database;
1. This is my first test.
2. This is the second one.
3. This is the last one.
HintMessage() will then randomized these (just like random()), The current code I had returns null (I know, I have coded it wrong so my bad) - Help will be appreciated on this one ~ And sorry about my grammar, Just like always xD
1. This is my first test.
2. This is the second one.
3. This is the last one.
HintMessage() will then randomized these (just like random()), The current code I had returns null (I know, I have coded it wrong so my bad) - Help will be appreciated on this one ~ And sorry about my grammar, Just like always xD
PHP код:
public HintMessage()
{
new id = random(sizeof(randomMessages));
SendFormatMessage(INVALID_PLAYER_ID, COLOR_RED, "* "cyan"%s", randomMessages[id][randomMessage]);
return 1;
}
stock LoadRandomMessage(id) // This one is looped through i < MAX_RANDOM_MESSAGES
{
new query[128], field[130];
new DBResult: resultdb;
format(query, sizeof(query), "SELECT * FROM `randommsg` WHERE `id` = %d", id);
resultdb = db_query(database, query);
if(db_num_rows(resultdb))
{
db_get_field_assoc(resultdb, "message", field, sizeof(field)); format(randomMessages[id][randomMessage], 128, field);
randomMessages[id][randomMessageExist] = true;
}
db_free_result(resultdb);
return 1;
}