Payphone system - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Payphone system (
/showthread.php?tid=638115)
Payphone system -
valelele - 27.07.2017
I just make a textdraw system payphone, on the textdrawstring it's setting numbers but when i press CALL i want to call the number is on the string
How can i do it?
I think i need to get the textdraw string probably, but how?
Re: Payphone system -
Dayrion - 27.07.2017
When a player press a number, add it to the string. If you need the number as an integer, use strval at the end
Re: Payphone system -
JaydenJason - 27.07.2017
Make the number that's being called a string.
Append a number to the end of the string (if you want numbers to start with 0, if not then theres no need for strings)
Check if phone number exists
Call?
Re: Payphone system -
FailerZ - 27.07.2017
You can use an array to store these numbers one by one in slots once they are pressed.
Example: (Detailed Tutorial). If you understand it you will be able to do it easily with the system you have.
PHP код:
#define MAX_NUMSLOTS 10 //Change this to the maximum number that can be dialed
new NumSlot[MAX_PLAYERS][MAX_NUMSLOTS]; //First we declare and array to hold the numbers in each slot and it is per player (MAX_PLAYERS).
CMD:del(playerid) //This is to clear all the slots and start fresh as the player want to use the payphone
{
for(new x; x < MAX_NUMSLOTS; x++) NumSlot[playerid][x] = -1; //Clear all the slots (sets them to unused number. Like -1 for example) //You should use that when the player gets the payphone textdraw
return 1;
}
CMD:slot(playerid, params[]) //This is command to assign a random number to the last unused slot for the tutorial sake (you should not do it random. You should make it to hold the number that the player pressed on the textdraw)
{
for(new i; i < MAX_NUMSLOTS; i++) //Looping through all the number slots
{
if(NumSlot[playerid][i] == -1) //Here we find the last unused slot
{
NumSlot[playerid][i] = random(9); //Instead of random number. This will hold the player numbers that he pressed in the textdraw
break; //We found a slot that is not in use. break the loop so it doesn't continue checking further
}
}
return 1;
}
CMD:dellast(playerid) //This will delete the last number entered
{
for(new i; i < MAX_NUMSLOTS; i++) //Looping through all the number slots
{
if(NumSlot[playerid][i] == -1) //Here we tell the loop if that slot is NOT in use (Has he value of -1) it should continue
{
NumSlot[playerid][i-1] = -1; //Notice the i-1 it is because we found an empty slot so we want to delete the slot behind it in which is definitely in use
break; //As always break so it doesn't continue further useless checks
}
}
return 1;
}
CMD:getnumber(playerid) //This is where you will get the last number (the result)
{
//Now we want to retrive them for further use
new snumbers[MAX_NUMSLOTS+1]; //This string we will pack all the numbers in. We set the size depends on the slots used and plus one for the null character
for(new i; i < MAX_NUMSLOTS; i++) //Starting from 0 slot to the size of slots which is 10 in our case.
{
if(NumSlot[playerid][i] != -1) //Here we tell the loop if that slot is in use (Not the value of -1) it should add it to the last string
{
new tmpstr[2]; //One cell for the integer (number we are holding) and the other for the null character
format(tmpstr, sizeof(tmpstr), "%i", NumSlot[playerid][i]); //format the temporary string to hold the number that we found in use
strcat(snumbers, tmpstr); //Strcat adds to the main string
}
else break; //Because it reached the last slot that is unused (has a value of -1) no need to continue the loop
}
if(isnull(snumbers)) return SendClientMessage(playerid, -1, "No numbers found");
new todial = strval(snumbers); //Here we get the value of the packed strings in the snumbers variable
printf("Numbers to dial %i", todial); //You can get the last numbers to dial both. as an integer (todial) or as a string (snumbers)
return 1;
}
Note: By the way this is ready to test tutorial that you can copy/paste and test it with those commands and see the results for further understanding. Just include <zcmd> don't forget
And I have put some effort in it for you to understand it. I hope you can understand it. Any question ask me here or in PM I can help further.