Halp [Random Amount]
#1

hi there!

I need some help, how do I make a pickup that gives you a random amount of money between 2000-5000. and how to write that "Random" amount in a SendClientMessage?
Reply
#2

https://sampwiki.blast.hk/wiki/Random

Take a look on the link above.
Reply
#3

-.-' It didn't help me
Reply
#4

pawn Код:
new pickup;

OnGameModeInit()
{
    //code
    pickup = CreatePickup(params..);
    return 1;
}

OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == pickup)
    {
        new cash = 2000 + random(3000);
        new str[128];
        GivePlayerMoney(playerid, cash);
        format(str, 128, "You have picked up $%i.", cash);
        SendClientMessage(playerid, -1, playerid);
        return 1;
    }
}
Quick example.
Reply
#5

Thanks man! it worked. but now i wonder if it's possible with score and weapons. I mean
Give a random amount of score and a random weapon, is it possible?
Reply
#6

Yes it's possible
pawn Код:
new money,score,wep;

OnGameModeInit()
{
    //code
    money = CreatePickup(params..);
    score = CreatePickup(params..);
    wep = CreatePickup(params..);
    return 1;
}

OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == money)
    {
        new cash = 2000 + random(3000);
        new str[128];
        GivePlayerMoney(playerid, cash);
        format(str, 128, "You have picked up $%i.", cash);
        SendClientMessage(playerid, -1, playerid);
        return 1;
    }
    else if(pickupid == score)
    {
        new sc = random(10);
        SetPlayerScore(playerid, GetPlayerScore(playerid) + sc);
        new str[60];
        format(str,60,"We added %i score to your's",sc);
        SendClientMessage(playerid,-1,str);
    }
    else if(pickupid==wep)
    {
        new w=0;
        for(;w==0 || (w>=19 && w<=21);) { w=random(44);}
        new ammo = random(1000);
        GivePlayerWeapon(playerid,w,ammo);
        new str[128],wname[20];
        GetWeaponName(w,wname,20);
        if(w == 18) format(wname,20,"Molotov Cocktail");
        format(str,128,"You received %s(%i).",wname,ammo);
        SendClientMessage(playerid,-1,str);
    }
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)