Random Skins + Timer
#1

Im making an /undercover command which is copied exactly off /copduty but changed "CopOnDuty" to "Undercover".
Only problem is that it sets your skin to a police skin, How could i make it pick random skins?
Would it go like this?

pawn Код:
new Random;
enum random
{
     {"skinid"},
     {"skinid"},
     {"skinid"},
     {"skinid"}
etc
};
Then in the /undercover command change
pawn Код:
SetPlayerSkin(random);
?..

Also, how could i set up ProxDetector + a 5 minute timer on this command (5 minute timer = /rob [id] "ohh look at that i got some money, lets try again" /rob [id] "Error: You cannot rob for another 5 minutes")

pawn Код:
dcmd_rob(playerid, params[])
{
    new string[128],
        PlayerName[MAX_PLAYER_NAME],
        OtherName[MAX_PLAYER_NAME],
        id,
        robamount;
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, 0xFF0000AA, "[Error]: Usage: /rob [Playerid]");
    {
    if(ProxDetectorS(8.0, playerid))
    {
    else
    {
        robamount = GetPlayerMoney(id) / 1000;
        GetPlayerName(playerid, PlayerName, sizeof(PlayerName));
        GetPlayerName(id, OtherName, sizeof(OtherName));
        format(string, sizeof(string), "[Succes]: You have robbed $%d from %s!", robamount, OtherName);
        SendClientMessage(playerid, 0xFF0000AA, string);
        format(string, sizeof(string), "[Rob]: You have been robbed by %s! He stole $%d from you!", PlayerName, robamount);
        SendClientMessage(id, 0xFF0000AA, string);
        GivePlayerMoney(playerid, robamount);
        GivePlayerMoney(id, -robamount);
    }
    }
    }
    return 1;
}
Sorry for the stupid questions lately, I've spent too much time learning about error fixes and strcmp commands and not enough with any real stuff like DCMD, ZCMD, SSCANF or anything useful
Reply
#2

There's no need for enum there, just an array with values inserted
pawn Код:
new Skins[4] = {
    skin1,
    skin2,
    skin3
};
Then you would select a random cell in the Skins array and use the integer stored there for the skin ID.

pawn Код:
SetPlayerSkin(playerid, Skins[random(sizeof(Skins)]);
Reply
#3

pawn Код:
new randomskins[skinsintotal(lines)][how many kommasdoyouhave]
So it owuld look like this.

pawn Код:
new randomskins[4][1] = {
   skin 1,
   skin 2,
   skin 3,
   skin 4
};
So at the comand you need to make a randoom.
pawn Код:
new rand = random(sizeof(randomskins));
SetPlayerSkin(playerid, rand);
Reply
#4

Quote:
Originally Posted by GaGlets®
Посмотреть сообщение
pawn Код:
new randomskins[skinsintotal(lines)][how many kommasdoyouhave]
So it owuld look like this.

pawn Код:
new randomskins[4][1] = {
   skin 1,
   skin 2,
   skin 3,
   skin 4
};
So at the comand you need to make a randoom.
pawn Код:
new rand = random(sizeof(randomskins));
SetPlayerSkin(playerid, rand);
I done it this way but the only skins it picks is CJ and that english guy with the fishing hat.. The skins i put down were a guy in a hoody (ID 29) and two mexican guys (47 and 4 so its like this

pawn Код:
new randomskins[4][1] = {
   29,
   47,
   48,
   285
};
pawn Код:
GivePlayerWeapon(playerid, 24, 99999);
                            GivePlayerWeapon(playerid, 3, 0);
                            GivePlayerWeapon(playerid, 41, 99999);
                            GivePlayerWeapon(playerid, 31, 99999);
                            CopOnDuty[playerid] = 1;
                            SetPlayerSkin(playerid, randa);
                            format(string, sizeof(string), "[LSPD:] %s is now an on duty police officer.",GetPlayerNameEx(playerid));
                            SendFactionTypeMessage(1, COLOR_LSPD, string);
                            return 1;
Changed from "rand" to "randa" due to a warning i got
Reply
#5

Two reasons most likely, first of all this

pawn Код:
new randomskins[4] = { // Not sure why you added an extra cell, it's only storing an integer
   29,
   47,
   48,
   285
};
And this

pawn Код:
GivePlayerWeapon(playerid, 24, 99999);
                            GivePlayerWeapon(playerid, 3, 0);
                            GivePlayerWeapon(playerid, 41, 99999);
                            GivePlayerWeapon(playerid, 31, 99999);
                            CopOnDuty[playerid] = 1;
                            SetPlayerSkin(playerid, randa);
                            format(string, sizeof(string), "[LSPD:] %s is now an on duty police officer.",GetPlayerNameEx(playerid));
                            SendFactionTypeMessage(1, COLOR_LSPD, string);
                            return 1;
Is missing the random code, unless you just left it out of the snippet.

There should be a

pawn Код:
randa = random(sizeof(randomskins));
In there.
Reply
#6

A better answer with example is up here ^^

This should work
pawn Код:
new randomskins[] = { 29, 47, 48, 285 };

new rand = random(sizeof(randomskins));
SetPlayerSkin(playerid, rand);
Reply
#7

Still the same problem

pawn Код:
GivePlayerWeapon(playerid, 24, 99999);
                            GivePlayerWeapon(playerid, 3, 0);
                            GivePlayerWeapon(playerid, 41, 99999);
                            GivePlayerWeapon(playerid, 31, 99999);
                            CopOnDuty[playerid] = 1;
                            randa = random(sizeof(randomskins));
                            SetPlayerSkin(playerid, randa);
                            format(string, sizeof(string), "[LSPD:] %s is now an on duty police officer.",GetPlayerNameEx(playerid));
                            SendFactionTypeMessage(1, COLOR_LSPD, string);
                            return 1;
pawn Код:
new randomskins[] = { 29, 47, 48, 285 };
And i also added "new rand = random" at the top of OnPlayercommandtext with the "new string" and "new tmp"
Reply
#8

Quote:
Originally Posted by Ritchie999
Посмотреть сообщение
Still the same problem

pawn Код:
GivePlayerWeapon(playerid, 24, 99999);
                            GivePlayerWeapon(playerid, 3, 0);
                            GivePlayerWeapon(playerid, 41, 99999);
                            GivePlayerWeapon(playerid, 31, 99999);
                            CopOnDuty[playerid] = 1;
                            randa = random(sizeof(randomskins));
                            SetPlayerSkin(playerid, randa);
                            format(string, sizeof(string), "[LSPD:] %s is now an on duty police officer.",GetPlayerNameEx(playerid));
                            SendFactionTypeMessage(1, COLOR_LSPD, string);
                            return 1;
pawn Код:
new randomskins[] = { 29, 47, 48, 285 };
And i also added "new rand = random" at the top of OnPlayercommandtext with the "new string" and "new tmp"
That's because you're setting the player skin to the random number, which is between 0 and 4 in this case. You want to use the random number to extract a value from the array, so simply replace your SetPlayerSkin with this:

pawn Код:
SetPlayerSkin(playerid, randomskins[randa]);
Reply
#9

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
That's because you're setting the player skin to the random number, which is between 1 and 4 in this case. You want to use the random number to extract a value from the array, so simply replace your SetPlayerSkin with this:

pawn Код:
SetPlayerSkin(playerid, randomskins[randa]);
Aha.. Im learning
Thanks man
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)