View difference between Paste ID: bdPqhte3 and CdSbuE8m
SHOW: | | - or go back to the newest paste.
1
/*
2
// ---------------------------------------
3
Incorporated Gaming Release.
4
	DO NOT REMOVE THE ABOVE OR ANY CREDITS.
5
		I_Checkpoint.
6
		    By Snowman12.
7
// ---------------------------------------
8
*/
9
10
#if defined I_Checkpoint included
11
	#endinput
12
#endif
13
#define I_Checkpoint included
14
15-
#include <YSI\y_hooks>
15+
#include                        <streamer>
16
#include                        <YSI\y_hooks>
17
#include                        <YSI\y_ini>
18
#include                        <a_samp>
19
20
#if !defined _streamer_included
21
#error You will be needing to download streamer.inc.
22
#endif
23
24
#define INCLUDE_REVISION        (2)
25
26
#define MAX_CHECKPOINTS			(300)
27
28
#define INVALID_CHECKPOINT_ID 	(0xFFFF)
29
30
#define CHECKPOINT_LOCATION     "Checkpoints/check%d.ini"
31
32-
	Version: v0.1 Released.
32+
33-
	Remember to add any suggestions you have.
33+
34
#endif
35
36
/* CHANGE LOG */
37
38
/*
39
	R1 - Release.
40
	R2 -
41
	    Saving/Loading System Y_INI.
42
	    DestroyDynamicCheckpoint added.
43
	    Fixed some bugs.
44
 */
45
	    
46
/*
47
native CreateDynamicCheckpoint(CheckpointName[28], Float: X, Float: Y, Float: Z, Float: Size, Float: EX, Float: EY, Float: EZ, Interior = -1,  EInterior = -1);
48
native DestroyDynamicCheckpoint(ID);
49
*/
50
51
forward loadCheckpoints_data(ID, name[], value[]);
52
53
enum E_CHECKPOINT_INFO
54
{
55
	E_CHECKPOINT_NAME[30],
56
	Text3D: E_LABEL,
57
	E_CHECKPOINT,
58
	bool: E_CREATED,
59
	Float: E_LOCX,
60
	Float: E_LOCY,
61
	Float: E_LOCZ,
62
	Float: E_SIZE,
63
	Float: E_ENTER_X,
64
	Float: E_ENTER_Y,
65-
	printf("| VERSION: %d                     |",INCLUDE_REVISION);
65+
66
	E_INTERIOR,
67
	E_ENTER_INTERIOR,
68
};
69
70
new CheckpointInfo[MAX_CHECKPOINTS][E_CHECKPOINT_INFO];
71
72
hook OnGameModeInit()
73
{
74
	print("====================================");
75
	print("| CHECKPOINT CREATOR LOADED        |");
76
	print("| MAX CHECKPOINTS: %d              |");
77
	print("| (c) Incorporated Gaming 2011     |");
78
	printf("| VERSION: R%d                    |",INCLUDE_REVISION);
79
	print("====================================");
80
	return 1;
81
}
82
83
CreateDynamicCheckpoint(CheckpointName[28], Float: X, Float: Y, Float: Z, Float: Size, Float: EX, Float: EY, Float: EZ, Interior = -1,  EInterior = -1)
84
{
85
	new ID = GetFreeCheckpointSlot();
86
	new szString[50];
87
	
88
	if(ID != INVALID_CHECKPOINT_ID)
89
	{
90
	    format(szString,sizeof(szString),""COL_YELLOW"Checkpoint:{FFFFFF}\n%s",CheckpointName);
91
	    format(CheckpointInfo[ID][E_CHECKPOINT_NAME], 30, "%s", CheckpointName);
92
	    CheckpointInfo[ID][E_CHECKPOINT] = CreateDynamicCP(X, Y, Z, Size, VirtualWorld, Interior);
93
	    CheckpointInfo[ID][E_LABEL] = Create3DTextLabel(szString,0xFFFFFFFF, X, Y, Z, 15.0, 0);
94
		CheckpointInfo[ID][E_LOCX] = X, CheckpointInfo[ID][E_LOCY] = Y, CheckpointInfo[ID][E_LOCZ] = Z;
95
		CheckpointInfo[ID][E_CREATED] = true;
96
	    CheckpointInfo[ID][E_SIZE] = Size;
97
   		CheckpointInfo[ID][E_ENTER_X] = EX, CheckpointInfo[ID][E_ENTER_Y], CheckpointInfo[ID][E_ENTER_Z];
98
		CheckpointInfo[ID][E_INTERIOR] = Interior;
99
		CheckpointInfo[ID][E_ENTER_INTERIOR] = EInterior;
100
		format(szString, sizeof(szString), CHECKPOINT_LOCATION, ID);
101
		new INI:File;
102
		iFile = INI_Open(szString);
103
		INI_SetTag(iFile, "Checkpoint Information");
104
		INI_WriteString(iFile, "CheckpointName",CheckpointName);
105
		INI_WriteFloat(iFile, "X", X);
106
		INI_WriteFloat(iFile, "Y", Y);
107
		INI_WriteFloat(iFile, "Z", Z);
108
		INI_WriteFloat(iFile, "Size", Size);
109
		INI_WriteFloat(iFile, "EX", EX);
110
		INI_WriteFloat(iFile, "EY", EY);
111
		INI_WriteFloat(iFile, "EZ", EZ);
112
		INI_WriteInt(iFile, "Interior", Interior);
113
		INI_WriteInt(iFile, "EnterInterior", EInterior);
114
		INI_Close(iFile);
115
		return ID;
116
	}
117
	return INVALID_CHECKPOINT_ID;
118
}
119
120
DestroyDynamicCheckpoint(ID)
121
{
122
	if(!CheckpointInfo[ID][E_CREATED])
123
	    return 0;
124
125
	static szString[30];
126
	format(szString,28,CHECKPOINT_LOCATION,ID);
127
	fremove(szString);
128
	DestroyDynamicCP(CheckpointInfo[ID][E_CHECKPOINT]);
129
	Delete3DTextLabel(CheckpointInfo[ID][E_LABEL]);
130
	CheckpointInfo[ID][E_CREATED] = false;
131
	return 1;
132
}
133
134
hook OnPlayerEnterDynamicCP(playerid, checkpointid)
135
{
136
	for(new i; i < MAX_CHECKPOINTS; i++)
137
	{
138
		if(CheckpointInfo[i][E_CHECKPOINT] == checkpointid)
139
		{
140
			if(CheckpointInfo[i][E_ENTER_INTERIOR] >= 1)
141
			{
142
			    SetPlayerInterior(playerid, CheckpointInfo[i][E_ENTER_INTERIOR]);
143
			}
144
			SetPlayerPos(playerid, CheckpointInfo[i][E_ENTER_X], CheckpointInfo[i][E_ENTER_Y], CheckpointInfo[i][E_ENTER_Z]);
145
		}
146
	}
147
	return 1;
148
}
149
150
151
152
stock strmatch(const str1[], const str2[])
153
{
154
    if ((strcmp(str1, str2, true, strlen(str2)) == 0) && (strlen(str2) == strlen(str1))) return true;
155
    return false;
156
}
157
158
stock GetFreeCheckpointSlot()
159
{
160
	for(new i; i < MAX_CHECKPOINTS; i++)
161
	{
162
	    if(!CheckpointInfo[i][E_CREATED])
163
			return i;
164
	}
165
	return INVALID_CHECKPOINT_ID;
166
}
167
		
168
stock LoadCheckpointsFromFile()
169
{
170
	new
171
	    iFile[50]
172
	;
173
	for(new i; i < MAX_CHECKPOINTS; i++)
174
	{
175
		format(iFile, 28, CHECKPOINT_LOCATION, i);
176
		if(fexist(iFile))
177
		{
178
		    INI_ParseFile(iFile, "loadCheckpoints_%s", .bExtra = true, .extra = i);
179
		    CheckpointInfo[i][E_CHECKPOINT] = CreateDynamicCP(CheckpointInfo[i][E_LOCX],CheckpointInfo[i][E_LOCY],CheckpointInfo[i][E_LOCZ],CheckpointInfo[i][E_SIZE], -1, CheckpointInfo[i][E_INTERIOR]);
180
		    format(iFile, sizeof(iFile), ""COL_YELLOW"Checkpoint:{FFFFFF}\n%s",CheckpointInfo[i][E_CHECKPOINT_NAME]);
181
		    CheckpointInfo[i][E_LABEL] = Create3DTextLabel(iFile, 0xFFFFFFFF, CheckpointInfo[i][E_LOCX], CheckpointInfo[i][E_LOCY], CheckpointInfo[i][E_LOCZ], 15.0, 0);
182
		    CheckpointInfo[i][E_CREATED] = true;
183
		}
184
	}
185
	return 1;
186
}
187
188
public loadCheckpoints_data(ID, name[], value[])
189
{
190
	if(strmatch(name, "CheckpointName")) format(CheckpointInfo[ID][E_CHECKPOINT_NAME], 28, "%s", value);
191
	if(strmatch(name, "X")) CheckpointInfo[ID][E_LOCX] = floatstr(value);
192
	if(strmatch(name, "Y")) CheckpointInfo[ID][E_LOCY] = floatstr(value);
193
	if(strmatch(name, "Z")) CheckpointInfo[ID][E_LOCZ] = floatstr(value);
194
	if(strmatch(name, "Size")) CheckpointInfo[ID][E_SIZE] = floatstr(value);
195
	if(strmatch(name, "EX")) CheckpointInfo[ID][E_ENTER_X] = floatstr(value);
196
	if(strmatch(name, "EY")) CheckpointInfo[ID][E_ENTER_Y] = floatstr(value);
197
	if(strmatch(name, "EZ")) CheckpointInfo[ID][E_ENTER_Z] = floatstr(value);
198
	if(strmatch(name, "Interior")) CheckpointInfo[ID][E_INTERIOR] = strval(value);
199
	if(strmatch(name, "EnterInterior")) CheckpointInfo[ID][E_ENTER_INTERIOR] = strval(value);
200
}