View difference between Paste ID: vtYdu5KF and bA0KEHUA
SHOW: | | - or go back to the newest paste.
1
#include <a_samp>
2
#include <YSI\y_commands>
3
#include <SII>
4
#include <sscanf2>
5
6
7
#define GREEN 				0x21DD00FF
8
#define RED 				0xE60000FF
9
#define ADMIN_RED 			0xFB0000FF
10
#define WHITE 				0xFFFFFFFF
11
#define ORANGE 				0xF97804FF
12
#define LIGHTRED 			0xFF8080FF
13
#define LIGHTBLUE 			0x00C2ECFF
14
#define PURPLE 				0xB360FDFF
15
#define BLUE 				0x1229FAFF
16
#define LIGHTGREEN 			0x38FF06FF
17
#define DARKPINK			0xE100E1FF
18
#define DARKGREEN 			0x008040FF
19
#define AQUAGREEN			0x00CACAFB
20
#define NICESKY 			0x99FFFFAA
21
#define GREY 				0xCECECEFF
22
#define ORANGERED 			0xFF4500FF
23
#define PINK 				0xFFC0CBFF
24-
#define SLOT_DIALOG         14
24+
25-
#define SAVE_POS_DIALOG     15
25+
#define SAVE_POS_DIALOG		15
26-
#define LOAD_POS_DIALOG     16
26+
#define LOAD_POS_DIALOG		16
27
28-
#define SAVE_POS_SLOT1      17
28+
#define SAVE_POS_SLOT1		17
29-
#define SAVE_POS_SLOT2      18
29+
#define SAVE_POS_SLOT2		18
30-
#define SAVE_POS_SLOT3      19
30+
#define SAVE_POS_SLOT3		19
31
32
new Float:SPosXS1,
33
	Float:SPosYS1,
34
	Float:SPosZS1;
35
36
// I think i dont even need those two, but puted them just in case
37
//
38
new Float:SPosXS2,
39
	Float:SPosYS2,
40
	Float:SPosZS2;
41
	
42
new Float:SPosXS3,
43
	Float:SPosYS3,
44
	Float:SPosZS3;
45
//
46
47
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
48
{
49
	if(dialogid == SAVE_POS_DIALOG)
50
	{
51-
	    if(response == 1)
51+
		if(response == 1)
52-
	    {
52+
53-
	        switch(listitem)
53+
			switch(listitem)
54-
	        {
54+
55-
	            case 0: ShowPlayerDialog(playerid, SAVE_POS_SLOT1, DIALOG_STYLE_INPUT,"{FFFFFF}Type Your Save Location {00FF00}Name", "", "Save","Cancel");
55+
				case 0: ShowPlayerDialog(playerid, SAVE_POS_SLOT1, DIALOG_STYLE_INPUT,"{FFFFFF}Type Your Save Location {00FF00}Name", " ", "Save","Cancel");
56-
	            case 1: ShowPlayerDialog(playerid, SAVE_POS_SLOT2, DIALOG_STYLE_INPUT,"{FFFFFF}Type Your Save Location {00FF00}Name", "", "Save","Cancel");
56+
				case 1: ShowPlayerDialog(playerid, SAVE_POS_SLOT2, DIALOG_STYLE_INPUT,"{FFFFFF}Type Your Save Location {00FF00}Name", " ", "Save","Cancel");
57-
	            case 2: ShowPlayerDialog(playerid, SAVE_POS_SLOT3, DIALOG_STYLE_INPUT,"{FFFFFF}Type Your Save Location {00FF00}Name", "", "Save","Cancel");
57+
				case 2: ShowPlayerDialog(playerid, SAVE_POS_SLOT3, DIALOG_STYLE_INPUT,"{FFFFFF}Type Your Save Location {00FF00}Name", " ", "Save","Cancel");
58
			}
59
		}
60
	}
61-
 	if(dialogid == SAVE_POS_SLOT1)
61+
	if(dialogid == SAVE_POS_SLOT1)
62
	{
63-
	    if(response == 1)
63+
		if(response == 1)
64
		{
65
			GetPlayerPos(playerid, SPosXS1, SPosYS1, SPosZS1);
66-
				GetPlayerPos(playerid, SPosXS1, SPosYS1, SPosZS1);
66+
			if(INI_Open(getINI(playerid)))
67-
    			if(INI_Open(getINI(playerid)))
67+
68
				INI_WriteString("SpawnPosSlot1Name", inputtext);
69-
				    INI_WriteString("SpawnPosSlot1Name", inputtext);
69+
				INI_WriteFloat("SpawnPosXSlot1",SPosXS1);
70-
					INI_WriteFloat("SpawnPosXSlot1",SPosXS1);
70+
				INI_WriteFloat("SpawnPosYSlot1",SPosYS1);
71-
			 		INI_WriteFloat("SpawnPosYSlot1",SPosYS1);
71+
				INI_WriteFloat("SpawnPosZSlot1",SPosZS1);
72-
			  		INI_WriteFloat("SpawnPosZSlot1",SPosZS1);
72+
				INI_Save();
73-
			  		INI_Save();
73+
				INI_Close();
74-
					INI_Close();
74+
75-
	            }
75+
76-
	        }
76+
77
	if(dialogid == SAVE_POS_SLOT2)
78
	{
79
		if(response == 1)
80
		{
81-
	    if(response == 1)
81+
			GetPlayerPos(playerid, SPosXS2, SPosYS2, SPosZS2);
82
			if(INI_Open(getINI(playerid)))
83
			{
84-
				GetPlayerPos(playerid, SPosXS2, SPosYS2, SPosZS2);
84+
				INI_WriteString("SpawnPosSlot2Name", inputtext);
85-
    			if(INI_Open(getINI(playerid)))
85+
				INI_WriteFloat("SpawnPosXSlot2",SPosXS2);
86
				INI_WriteFloat("SpawnPosYSlot2",SPosYS2);
87-
				    INI_WriteString("SpawnPosSlot2Name", inputtext);
87+
				INI_WriteFloat("SpawnPosZSlot2",SPosZS2);
88-
					INI_WriteFloat("SpawnPosXSlot2",SPosXS2);
88+
				INI_Save();
89-
			 		INI_WriteFloat("SpawnPosYSlot2",SPosYS2);
89+
				INI_Close();
90-
			  		INI_WriteFloat("SpawnPosZSlot2",SPosZS2);
90+
91-
			  		INI_Save();
91+
92-
					INI_Close();
92+
93-
	            }
93+
94-
	        }
94+
95
		if(response == 1)
96
		{
97
			GetPlayerPos(playerid, SPosXS3, SPosYS3, SPosZS3);
98
			if(INI_Open(getINI(playerid)))
99-
	    if(response == 1)
99+
100
				INI_WriteString("SpawnPosSlot3Name", inputtext);
101
				INI_WriteFloat("SpawnPosXSlot3",SPosXS3);
102-
				GetPlayerPos(playerid, SPosXS3, SPosYS3, SPosZS3);
102+
				INI_WriteFloat("SpawnPosYSlot3",SPosYS3);
103-
    			if(INI_Open(getINI(playerid)))
103+
				INI_WriteFloat("SpawnPosZSlot3",SPosZS3);
104
				INI_Save();
105-
				    INI_WriteString("SpawnPosSlot3Name", inputtext);
105+
				INI_Close();
106-
					INI_WriteFloat("SpawnPosXSlot3",SPosXS3);
106+
107-
			 		INI_WriteFloat("SpawnPosYSlot3",SPosYS3);
107+
108-
			  		INI_WriteFloat("SpawnPosZSlot3",SPosZS3);
108+
109-
			  		INI_Save();
109+
110-
					INI_Close();
110+
	// The loading slot dialog:
111-
	            }
111+
	if(dialogid == LOAD_POS_DIALOG)
112-
	        }
112+
113
		// Run this code if the user pressed 'load'
114
		if(response)
115
		{
116
			
117
			// Open the file again
118
			if(INI_Open(getINI(playerid)))
119
			{
120
				// Declare some variables to store the coordinates in.
121
				new
122
					Float:x,
123
					Float:y,
124
					Float:z;
125
126
				// Run a different code block depending on the listitem:
127
				switch(listitem)
128
				{
129
					case 0:
130
					{
131
						x = INI_ReadFloat("SpawnPosXSlot1");
132-
	// This is the problem here!
132+
						y = INI_ReadFloat("SpawnPosYSlot1");
133-
	// So i basicly need, if a slot is empty is says ex. Slot 1 but if its taken is says the text of the inputtext shown above
133+
						z = INI_ReadFloat("SpawnPosZSlot1");
134-
	ShowPlayerDialog(playerid, SLOT_DIALOG, DIALOG_STYLE_LIST, "{FFFFFF}Choose {00FF00}Save Slot","Slot 1\nSlot 2\nSlot 3","Save","Cancel");
134+
					}
135
136
					case 1:
137
					{
138
						x = INI_ReadFloat("SpawnPosXSlot2");
139
						y = INI_ReadFloat("SpawnPosYSlot2");
140-
  	new account[64], pName[MAX_PLAYER_NAME];
140+
						z = INI_ReadFloat("SpawnPosZSlot2");
141-
  	GetPlayerName(playerid, pName, sizeof(pName));
141+
					}
142-
  	format(account,30,"Users/%s.ini", pName);
142+
143-
  	return account;
143+
					case 2:
144
					{
145
						x = INI_ReadFloat("SpawnPosXSlot3");
146
						y = INI_ReadFloat("SpawnPosYSlot3");
147
						z = INI_ReadFloat("SpawnPosZSlot3");
148
					}
149
				}
150
151
				// Perform this check to see if the loaded coordinates are valid.
152
				// If all the coordinates are 0.0, the slot probably doesn't exist.
153
				// So let the player choose a different slot.
154
				if(x == 0.0 && y == 0.0 && z == 0.0)
155
				{
156
					// Show the menu again so the player can choose a new slot.
157
					ShowPlayerSlotList(playerid);
158
				}
159
				else
160
				{
161
					// Set the player position to the stored coordinates.
162
					SetPlayerPos(playerid, x, y, z);
163
				}
164
165
				// Close the file to clear memory and allow another file to be opened in the future.
166
				INI_Close();
167
			}
168
			else
169
			{
170
				// INI_Open returned 0 meaning the file didn't open, warn the player or something.
171
			}
172
		}
173
	}
174
175
	return 0;
176
}
177
178
YCMD:spos(playerid,params[], help)
179
{
180
	#pragma unused params
181
	#pragma unused help
182
183
	ShowPlayerDialog(playerid, SAVE_POS_DIALOG, DIALOG_STYLE_LIST, "{FFFFFF}Choose {00FF00}Save Slot","Slot 1\nSlot 2\nSlot 3","Save","Cancel");
184
	return 1;
185
}
186
187
YCMD:lpos(playerid,params[], help)
188
{
189
	#pragma unused params
190
	#pragma unused help
191
192
	// Use a function to display the menu
193
	// This way, you can display the menu from anywhere without needing to write all the code again.
194
	ShowPlayerSlotList(playerid);
195
196
	return 1;
197
}
198
199
ShowPlayerSlotList(playerid)
200
{
201
	new
202
		list[(128 + 1) * 3], // 128 is the max-length of the slot name, 1 is the \n character, multiply by 3 for 3 lines.
203
		tmp[128 + 1]; // Used to store the slot name loaded from the file.
204
205
	if(INI_Open(getINI(playerid)))
206
	{
207
		// Only run this code if INI_Open returned 1, aka the file opened successfully.
208
209
		// Read the slot name, store it to 'tmp'.
210
		if(INI_ReadString(tmp, "SpawnPosSlot1Name"))
211
		{
212
			// If INI_ReadString returned 1, the string was loaded.
213
			// Set the last character to a '\n' for the menu newline.
214
			tmp[strlen(tmp)] = '\n';
215
			// Stick it onto the end of 'list' with 'strcat'.
216
			strcat(list, tmp);
217
		}
218
		else
219
		{
220
			// If INI_ReadString returned 0, insert the slot number instead.
221
			strcat(list, "Slot 1\n");
222
		}
223
224
		// Same as above for the other slots:
225
		if(INI_ReadString(tmp, "SpawnPosSlot2Name"))
226
		{
227
			tmp[strlen(tmp)] = '\n';
228
			strcat(list, tmp);
229
		}
230
		else
231
		{
232
			strcat(list, "Slot 2\n");
233
		}
234
235
		if(INI_ReadString(tmp, "SpawnPosSlot3Name"))
236
		{
237
			tmp[strlen(tmp)] = '\n';
238
			strcat(list, tmp);
239
		}
240
		else
241
		{
242
			strcat(list, "Slot 3\n");
243
		}
244
245
		// The dialog is also under the INI_Open block so it only shows if the file opened properly.
246
		ShowPlayerDialog(playerid, LOAD_POS_DIALOG, DIALOG_STYLE_LIST, "{FFFFFF}Choose {00FF00}Save Slot",list,"Load","Cancel");
247
248
		// Close the file to clear memory and allow another file to be opened in the future.
249
		INI_Close();
250
	}
251
	else
252
	{
253
		// INI_Open returned 0 meaning the file didn't open, warn the player or something.
254
	}
255
}
256
257
stock getINI(playerid)
258
{
259
	new account[64], pName[MAX_PLAYER_NAME];
260
	GetPlayerName(playerid, pName, sizeof(pName));
261
	format(account,30,"Users/%s.ini", pName);
262
	return account;
263
}