strins with numbers
#1

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);
Reply
#2

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).
Reply
#3

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?
Reply
#4

Код:
new phone[16];
format(phone, 16, "%d%d", 0670, randphone);
PlayerInfo[playerid][pNumber] = strval(phone);
Reply
#5

Still not working...
Reply
#6

Ah, yes. Basic math rules. Any zero to the left (in the beginning of the number) is insignificant.

Store it in a string.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)