Randomizing death messages
#1

Here is my code for my death messages, but I was wondering if it was possible to randomize messages, As you can see one line of code says
pawn Код:
format(string, sizeof(string), "{FF6600}*** %s has fucked up %s, with a %s", killer, playername, deathreason);
Is it possible to randomise the message so that it doesnt allways say "has fucked up" and can maybe change to... "has re-arranged the face of %s" ?
Is this possible?


pawn Код:
new string[256];
    new deathreason[20];
    GetPlayerName(playerid, playername, sizeof(playername));
    GetWeaponName(reason, deathreason, 20);
    if (killerid == INVALID_PLAYER_ID) {
        switch (reason) {
            case WEAPON_DROWN:
            {
                format(string, sizeof(string), "{FF6600}*** %s has drowned.)", playername);
            }
            default:
            {
                if (strlen(deathreason) > 0) {
                    format(string, sizeof(string), "{FF6600}*** %s has died. (%s)", playername, deathreason);
                } else {
                    format(string, sizeof(string), "{FF6600}*** %s has died.", playername);
                }
            }
        }
    }
    else {
    new killer[MAX_PLAYER_NAME];
    GetPlayerName(killerid, killer, sizeof(killer));
    if (strlen(deathreason) > 0) {
        format(string, sizeof(string), "{FF6600}*** %s has fucked up %s, with a %s", killer, playername, deathreason);
        } else {
                format(string, sizeof(string), "{FF6600}*** %s has fucked up %s.", killer, playername);
            }
        }
    SendClientMessageToAll(COLOR_YELLOW, string);

    return 1;
}
Reply
#2

It is possible, just do something like this:

At the top of the Script
Код:
new Death[][3] =
{
    {1},
    {2}
};
At the top of your command:
Код:
new Random = random(sizeof(Death));
I would save it to dini or something, because if not then i don't know how to check it without playerid...

So if you wanna save it to dini, so put this below Random:

Код:
dini_IntSet("File destination", "Death", Death[Random][0]);
Then somewhere in your command put this if you did with Dini:

Код:
        if(dini_Int("file destination", "Death") == 1)
	{
           format(string, sizeof(string), "{FF6600}*** %s has fucked up %s.", killer, playername);
        }
        else if(dini_Int("file destination", "Death") == 2)
        {
             Write here something else
        }
Done

If without dini do something like this:
Код:
if(death[playerid] == 1) // i dont know how to do it without playerid, so you have to figure it out :(
	{
           format(string, sizeof(string), "{FF6600}*** %s has fucked up %s.", killer, playername);
        }
        else if(death[playerid] == 2)
        {
             Write here something else
        }
Reply
#3

damn thats one inefficient way to do it.

add as said the array on top of your script OR:

add a switch(random(5)) with 5 cases to the onplayerdeath
and there do a format
Reply
#4

I tried both of these methods and they did not work.. Any other suggestions from readers??
Reply
#5

bump
Reply
#6

pawn Код:
new
    deathmsgs[][] = {
    {"%s has fucked up %s with a %s"},
    {"%s has killed %s with a %s"}
};

// OnPlayerDeath
new
    rand = random(sizeof(deathmsgs)),
    msg[128];

format(msg, sizeof(msg), deathmsgs[rand], killerid, playerid, reason);
Something like that.
Reply
#7

That worked, sorry for the late reply, forgot. Thanks alot man
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)