PDA

View Full Version : strins with numbers


penaut
18/04/2017, 08: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_SetTag(File2,"data");
INI_WriteInt(File2, "Number", PlayerInfo[playerid][pNumber]);
INI_Close(File2);

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

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

Nyitz
18/04/2017, 08: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).

penaut
19/04/2017, 02: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?

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

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

Marricio
19/04/2017, 07: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.