View Full Version : strins with numbers

18/04/2017, 09:08 PM
Hey! how can i insert numbers before random numbers? I was trying like this but it is not working
if(GetPlayerMoney(playerid) < 99) return SCM(playerid, COLOR_LIGHTRED, "You do not have enough money.");
if(PlayerInfo[playerid][pPhone] > 0) return SCM(playerid, COLOR_LIGHTRED, "You already have a cellphone.");
SCM(playerid, COLOR_WHITE, "You have bought a cellphone.");

new str[64];
new randphone = random(9999999) + 1000000; //minimum 150000 - max 500000 - defining the number
strins(randphone, "0670", 0, 4);
PlayerInfo[playerid][pNumber] = randphone; // Define pNumber as that number :)
format(str, sizeof(str), "Your new number is: %d.", randphone);
SendClientMessage(playerid, COLOR_WHITE, str);
PlayerInfo[playerid][pPhone] = 1;
GivePlayerMoney(playerid, -100);
new INI:File2 = INI_Open(UserPath(playerid));
INI_WriteInt(File2, "Number", PlayerInfo[playerid][pNumber]);

new id = GetPlayerVirtualWorld(playerid);
BusinessInfo[id][bMoney] += 50;

new file4[40];
format(file4, sizeof(file4), BPATH, id);
new INI:File = INI_Open(file4);
INI_WriteInt(File,"bMoney", BusinessInfo[id][bMoney]);

18/04/2017, 09:19 PM
strins won't work because it operates on strings. randphone is an integer. Try something like that:

new phonenumber[16];
format(phonenumber,sizeof(phonenumber),"%s-%d", "0670", randphone);

...and phonenumber should become what you want it to (0670-123456789 for example).

19/04/2017, 03:20 PM
Ralfie's method is working, the only problem is that it sets the strings first part to 670, not 0670. Is there any way to fix this?

19/04/2017, 03:22 PM
new phone[16];
format(phone, 16, "%d%d", 0670, randphone);
PlayerInfo[playerid][pNumber] = strval(phone);

19/04/2017, 08:01 PM
Still not working...

19/04/2017, 08:44 PM
Ah, yes. Basic math rules. Any zero to the left (in the beginning of the number) is insignificant.

Store it in a string.