[Question] About random..again..
#1

Hello,

Im trying to make a random value but it keeps giving me tag mismatch error or its just not working at all
heres how i made the random, and weed crack and canabis are the values that need to be true:
pawn Код:
//the enum...
enum DrugInfo
{
    Crack,
    Marijuana,
    Weed,
    Cocaine,
    Canabis,
    Ganja,
    Heroin,
}
new DrugType[MAX_PLAYERS][DrugInfo];

//and the random that is in a callback
new randomvalue[3]={Weed,Crack,Canabis};
DrugType[playerid][randomvalue[random(sizeof randomvalue)] =1;
here are my warnings;
pawn Код:
C:\Games\Rockstar Games\GTA San Andreas\sampserver\filterscripts\DontDoDrugsMan.pwn(368) : warning 213: tag mismatch
C:\Games\Rockstar Games\GTA San Andreas\sampserver\filterscripts\DontDoDrugsMan.pwn(368) : warning 213: tag mismatch
C:\Games\Rockstar Games\GTA San Andreas\sampserver\filterscripts\DontDoDrugsMan.pwn(369) : warning 213: tag mismatch
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase

3 Warnings.
I dont think it works like this anyway because the stuff i put in random already excists in the enum.

please give me your suggestion.
Reply
#2

Lines?
Reply
#3

pawn Код:
new randomvalue[3]={Weed,Crack,Canabis};
has to be
pawn Код:
new randomvalue[3]={DrugType[playerid][Weed], DrugType[playerid][Crack], DrugType[playerid][Canabis]};
Reply
#4

Thanks alright now i have this;

pawn Код:
new randomvalue[3]={DrugType[playerid][Weed], DrugType[playerid][Crack], DrugType[playerid][Canabis]};
DrugType[playerid][randomvalue[random(sizeof randomvalue)]] =1;
and these errors;

pawn Код:
C:\Games\Rockstar Games\GTA San Andreas\sampserver\filterscripts\DontDoDrugsMan.pwn(370) : error 008: must be a constant expression; assumed zero
C:\Games\Rockstar Games\GTA San Andreas\sampserver\filterscripts\DontDoDrugsMan.pwn(371) : warning 213: tag mismatch
Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


1 Error.
Edit: the lines are at the 2 lines im showing above new randomvalue...and DrugType..(370 and 371)
Reply
#5

Quote:
Originally Posted by Lenny the Cup
Посмотреть сообщение
pawn Код:
new randomvalue[3]={Weed,Crack,Canabis};
has to be
pawn Код:
new randomvalue[3]={DrugType[playerid][Weed], DrugType[playerid][Crack], DrugType[playerid][Canabis]};
When initialising variables you must use constant expressions, other vars will not work.
Reply
#6

Quote:
Originally Posted by iggy1
Посмотреть сообщение
Whe initialising variables you must use constant expressions, other vars will not work.
Yea i was afraid of that :S How should i do it then ?
Reply
#7

I'm not sure what it is you want to do. Explain and I can probably help.
Reply
#8

Well i made some kind of drugsystem when a player picks up a drug package somewhere the player will
have a variablelike...canabis..weed...bla bla bla like this;

DrugType[playerid][Canabis] = 1;
DrugType[playerid][Weed] = 1;

it works fine if i use just one DrugType[playerid][Crack] == 1) under onplayerpickup

but i want the pickup gives the player not only crack but also weed as a value so i thought maybe i can make it random each time a player picks up the same pickup
Thats where it all started

EDIT: yes the player should be able to have many drugtypes at once..hmm alright maybe i should explain the whole thing XD
Reply
#9

Thanks for the big explaining ****** . I tried your last example wich gave me this error

(371) : error 023: array assignment must be simple assignment

coming from this line;

pawn Код:
DrugType[playerid] |= randomvalue[random(sizeof randomvalue)];
Reply
#10

This function might help you.

pawn Код:
enum DrugInfo
{
    Crack,
    Marijuana,
    Weed,
    Cocaine,
    Canabis,
    Ganja,
    Heroin,
}
new DrugType[MAX_PLAYERS][DrugInfo];

GivePlayerRandomDrug(playerid)
{
    new
        iRand = random(7);
    switch(iRand)
    {
        case Crack:
        {
            DrugType[playerid][Crack]++;
            SendClientMessage(playerid, 0x00FF00AA, "You have found a package of crack.");
        }
        case Marijuana:
        {
            DrugType[playerid][Marijuana]++;
            SendClientMessage(playerid, 0x00FF00AA, "You have found a package of marijuana.");
        }
        case Weed:
        {
            DrugType[playerid][Weed]++;
            SendClientMessage(playerid, 0x00FF00AA, "You have found a package of weed.");
        }
        case Cocaine:
        {
            DrugType[playerid][Cocaine]++;
            SendClientMessage(playerid, 0x00FF00AA, "You have found a package of cocain.");
        }
        case Canabis:
        {
            DrugType[playerid][Canabis]++;
            SendClientMessage(playerid, 0x00FF00AA, "You have found a package of cannabis.");
        }
        case Ganja:
        {
            DrugType[playerid][Ganja]++;
            SendClientMessage(playerid, 0x00FF00AA, "You have found a package of ganja.");
        }
        case Heroin:
        {
            DrugType[playerid][Heroin]++;
            SendClientMessage(playerid, 0x00FF00AA, "You have found a package of heroin.");
        }
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)