· 6 years ago · Jan 24, 2020, 05:12 PM
1//System tworzenia dynamicznych aktorów...
2
3#undef MAX_ACTORS
4#define MAX_ACTORS 25
5
6enum aInfo
7{
8 AktorID,
9 AktorUID,
10 AktorNazwa[10 + MAX_PLAYER_NAME],
11 AktorOpis[128],
12 AktorSkinID,
13 Float:AktorPos_X,
14 Float:AktorPos_Y,
15 Float:AktorPos_Z,
16 Float:AktorPos_A
17};
18new AktorInfo[MAX_ACTORS][aInfo];
19
20new Iterator:Actors<MAX_ACTORS>;
21
22CMD:stworzaktor(playerid, params[])
23{
24 new aNazwa[34], aOpis[128], aSkinID;
25
26 if(sscanf(params, "s[34]s[128]d", aNazwa, aOpis, aSkinID)) return SendClientMessage(playerid, -1, "UŻYJ: /stworzaktor [AktorNazwa] [AktorOpis] [AktorSkinID]");
27
28 new Float:aPosX, Float:aPosY, Float:aPosZ, Float:aPosA;
29
30 GetPlayerPos(playerid, aPosX, aPosY, aPosZ);
31 GetPlayerFacingAngle(playerid, aPosA);
32
33 StworzAktora(aNazwa, aOpis, aSkinID, aPosX+1.0, aPosY, aPosZ, aPosA);
34
35 return 1;
36}
37
38CMD:edytujaktor(playerid, params[])
39{
40 new aID;
41
42 if(sscanf(params, "d", aID)) return SendClientMessage(playerid, -1, "UŻYJ: /edytujaktor [AktorID]");
43
44 return 1;
45}
46
47CMD:usunaktor(playerid, params[])
48{
49 new aID;
50
51 if(sscanf(params, "d", aID)) return SendClientMessage(playerid, -1, "UŻYJ: /usunaktor [AktorID]");
52
53 UsunAktora(aID);
54
55 return 1;
56}
57
58stock StworzAktora(anazwa[34], aopis[128], askinid, Float:aposx, Float:aposy, Float:aposz, Float:aposa)
59{
60 new act = Iter_Free(Actors);
61
62 AktorInfo[act][AktorSkinID] = askinid;
63 AktorInfo[act][AktorPos_X] = aposx;
64 AktorInfo[act][AktorPos_Y] = aposy;
65 AktorInfo[act][AktorPos_Z] = aposz;
66 AktorInfo[act][AktorPos_A] = aposa;
67
68 format(AktorInfo[act][AktorNazwa], 34, anazwa);
69 format(AktorInfo[act][AktorOpis], 128, aopis);
70
71 AktorInfo[act][AktorID] = CreateActor(AktorInfo[act][AktorSkinID], AktorInfo[act][AktorPos_X], AktorInfo[act][AktorPos_Y], AktorInfo[act][AktorPos_Z], AktorInfo[act][AktorPos_A]);
72 Attach3DTextLabelToActor(AktorInfo[act][AktorID], AktorInfo[act][AktorNazwa], -1, 0.0, 0.0, 0.3, 40.0);
73 Attach3DTextLabelToActor(AktorInfo[act][AktorID], AktorInfo[act][AktorOpis], -1, 0.0, 0.0, -0.8, 40.0);
74
75 new query[256];
76
77 mysql_format(g_SQL, query, sizeof(query), "INSERT INTO `actors` (AktorNazwa, AktorOpis, AktorSkinID, AktorPosX, AktorPosY, AktorPosZ, AktorPosA) VALUES ('%s', '%s', %d, %f, %f, %f, %f)",
78 AktorInfo[act][AktorNazwa], AktorInfo[act][AktorOpis], AktorInfo[act][AktorSkinID], AktorInfo[act][AktorPos_X], AktorInfo[act][AktorPos_Y], AktorInfo[act][AktorPos_Z], AktorInfo[act][AktorPos_A]);
79 mysql_query(g_SQL, query);
80
81 AktorInfo[act][AktorID] = cache_insert_id();
82
83 Iter_Add(Actors, act);
84
85 return 1;
86}
87
88stock ZapiszAktora(act)
89{
90 new query[256];
91
92 mysql_format(g_SQL, query, sizeof(query), "UPDATE `actors` SET `AktorNazwa` = '%s', `AktorOpis` = '%s', `AktorSkinID` = %d, `AktorPosX` = %f, `AktorPosY` = %f, `AktorPosZ` = %f, `AktorPosA` = %f\
93 WHERE `AktorID` = %d", AktorInfo[act][AktorNazwa], AktorInfo[act][AktorOpis], AktorInfo[act][AktorSkinID], AktorInfo[act][AktorPos_X], AktorInfo[act][AktorPos_Y], AktorInfo[act][AktorPos_Z],
94 AktorInfo[act][AktorPos_A], AktorInfo[act][AktorID]);
95 mysql_query(g_SQL, query);
96
97 return 1;
98}
99
100stock WczytajAktora()
101{
102 mysql_query(g_SQL, "SELECT * FROM `actors`");
103
104 new rows = cache_num_rows(), acount;
105
106 printf("Liczba aktorów: %d", rows);
107
108 if(rows > 0)
109 {
110 for(new i = 0; i < rows; i++)
111 {
112 cache_get_value_int(i, "AktorID", AktorInfo[acount][AktorID]);
113 cache_get_value_name(i, "AktorNazwa", AktorInfo[acount][AktorNazwa], 40);
114 cache_get_value_name(i, "AktorOpis", AktorInfo[acount][AktorOpis], 128);
115 cache_get_value_name_int(i, "AktorSkinID", AktorInfo[acount][AktorSkinID]);
116 cache_get_value_name_float(i, "AktorPosX", AktorInfo[acount][AktorPos_X]);
117 cache_get_value_name_float(i, "AktorPosY", AktorInfo[acount][AktorPos_Y]);
118 cache_get_value_name_float(i, "AktorPosZ", AktorInfo[acount][AktorPos_Z]);
119 cache_get_value_name_float(i, "AktorPosA", AktorInfo[acount][AktorPos_A]);
120
121 AktorInfo[acount][AktorUID] = CreateActor(AktorInfo[acount][AktorSkinID], AktorInfo[acount][AktorPos_X], AktorInfo[acount][AktorPos_Y], AktorInfo[acount][AktorPos_Z], AktorInfo[acount][AktorPos_A]);
122 Attach3DTextLabelToActor(AktorInfo[acount][AktorUID], AktorInfo[acount][AktorNazwa], -1, 0.0, 0.0, 0.3, 40.0);
123 //Attach3DTextLabelToActor(AktorInfo[acount][AktorID], AktorInfo[acount][AktorOpis], -1, 0.0, 0.0, -0.8, 40.0);
124
125 new actstr[64];
126 new arrayid;
127
128 for(new zzz = 0; zzz < MAX_ACTORS; zzz++)
129 {
130 if(AktorInfo[zzz][AktorID] > 0)
131 {
132 arrayid = GetActorArrayID(AktorInfo[zzz][AktorUID]);
133 format(actstr, sizeof(actstr), "AktorID: %d", AktorInfo[arrayid][AktorID]);
134 }
135 }
136
137 Attach3DTextLabelToActor(AktorInfo[acount][AktorUID], actstr, -1, 0.0, 0.0, -0.8, 40.0);
138
139 Iter_Add(Actors, acount);
140
141 acount++;
142 }
143 }
144
145 return 1;
146}
147
148GetActorArrayID(db_slot)
149{
150 new slot;
151
152 foreach(new i : Actors)
153 {
154 if(AktorInfo[i][AktorID] == db_slot) return i;
155 }
156
157 return slot;
158}
159
160stock UsunAktora(aid)
161{
162 DestroyActor(aid);
163
164 new query[64];
165
166 mysql_format(g_SQL, query, sizeof(query), "DELETE FROM `actors` WHERE `AktorID` = %d", aid);
167 mysql_query(g_SQL, query);
168
169 return 1;
170}
171
172CMD:getpos(playerid)
173{
174 new Float:xx, Float:yy, Float:zz, Float:aa;
175 GetPlayerPos(playerid, xx, yy, zz);
176 GetPlayerFacingAngle(playerid, aa);
177 new str_f[128];
178 format(str_f, sizeof(str_f), "Pozycja X: %f | Pozycja Y: %f | Pozycja Z: %f | Pozycja A: %f", xx, yy, zz, aa);
179 SendClientMessage(playerid, -1, str_f);
180 return 1;
181}
182
183SetupActorTable()
184{
185 mysql_tquery(g_SQL, "CREATE TABLE IF NOT EXISTS `actors` (\
186 `AktorID` INT NOT NULL AUTO_INCREMENT,\
187 `AktorNazwa` VARCHAR(40) NOT NULL,\
188 `AktorOpis` VARCHAR(128) NOT NULL,\
189 `AktorSkinID` INT NOT NULL,\
190 `AktorPosX` FLOAT NOT NULL,\
191 `AktorPosY` FLOAT NOT NULL,\
192 `AktorPosZ` FLOAT NOT NULL,\
193 `AktorPosA` FLOAT NOT NULL,\
194 PRIMARY KEY (`AktorID`))");
195 return 1;
196}
197
198forward Text3D:Attach3DTextLabelToActor(actorid, text[], color, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:distance = 10.0, worldid = 0, testlos = 0);
199stock Text3D:Attach3DTextLabelToActor(actorid, text[], color, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:distance = 10.0, worldid = 0, testlos = 0)
200{
201 new Text3D:textid = Text3D:INVALID_3DTEXT_ID;
202
203 if(IsValidActor(actorid))
204 {
205 new Float:x, Float:y, Float:z;
206
207 GetActorPos(actorid, x, y, z);
208
209 textid = Create3DTextLabel(text, color, x + fOffsetX, y + fOffsetY, (z + 0.8) + fOffsetZ, distance, worldid, testlos);
210
211 if(textid != Text3D:INVALID_3DTEXT_ID)
212 {
213 s_3DTextActorID[_:textid] = actorid;
214 }
215 }
216 return textid;
217}
218
219//Koniec - tworzenia dynamicznych aktorów.