· 6 years ago · Jul 10, 2019, 03:02 PM
1//=======CUSTOM SETTINGS=======//
2#undef MAX_OBJECTS
3#define MAX_OBJECTS 5
4#define MINX 0.25
5#define MINY 0.25
6#define MINZ 0.25
7#define MAXX 3.00
8#define MAXY 3.00
9#define MAXZ 3.00
10new objectlist = mS_INVALID_LISTID;
11enum oData
12{
13 bool:used1,
14 index1,
15 modelid1,
16 bone1,
17 Float:fOffsetX1,
18 Float:fOffsetY1,
19 Float:fOffsetZ1,
20 Float:fRotX1,
21 Float:fRotY1,
22 Float:fRotZ1,
23 Float:fScaleX1,
24 Float:fScaleY1,
25 Float:fScaleZ1
26}
27new oInfo[MAX_PLAYERS][MAX_OBJECTS][oData];
28new inindex[MAX_PLAYERS], inmodel[MAX_PLAYERS];
29OnGameModeInit()
30{
31 objectlist = LoadModelSelectionMenu("objects.txt");
32 mysql_tquery(g_SQL, "CREATE TABLE IF NOT EXISTS `objects` (`ID` int(5) NOT NULL,`Index` int(2) NOT NULL,`Model` int(7) NOT NULL,`Bone` int(2) NOT NULL,`OffsetX` float NOT NULL,`OffsetY` float NOT NULL,`OffsetZ` float NOT NULL,`RotX` float NOT NULL,`RotY` float NOT NULL,`RotZ` float NOT NULL,`ScaleX` float NOT NULL,`ScaleY` float NOT NULL,`ScaleZ` float NOT NULL)");
33}
34OnPlayerConnect(playerid)
35{
36for(new i, j=MAX_OBJECTS; i<j; i++)
37 {
38 oInfo[playerid][i][used1] = false;
39 }
40 CheckDataTimer[playerid] = SetTimerEx("Checkiraj", 1000, false, "d", playerid);
41
42}
43OnPlayerSpawn(playerid)
44{
45for(new i,j=MAX_OBJECTS; i<j; i++)
46 {
47 if(oInfo[playerid][i][used1] == true) SetPlayerAttachedObject(playerid, oInfo[playerid][i][index1], oInfo[playerid][i][modelid1], oInfo[playerid][i][bone1], oInfo[playerid][i][fOffsetX1], oInfo[playerid][i][fOffsetY1], oInfo[playerid][i][fOffsetZ1], oInfo[playerid][i][fRotX1], oInfo[playerid][i][fRotY1], oInfo[playerid][i][fRotZ1], oInfo[playerid][i][fScaleX1], oInfo[playerid][i][fScaleY1], oInfo[playerid][i][fScaleZ1]);
48 }
49}
50COMMAND:attach(playerid,params[])
51{
52 new string[300], s[40];
53 format(string, sizeof(string), "{84B4C4}Slot 1\t%s\n", oInfo[playerid][0][used1] == true ? ("{E62E2E}Used") : ("{0DFF00}Empty"));
54 for(new i=1,j=MAX_OBJECTS; i<j; i++) {
55 format(s, sizeof(s), "{84B4C4}Slot %d\t%s\n", i+1, oInfo[playerid][i][used1] == true ? ("{E62E2E}Used") : ("{0DFF00}Empty"));
56 strcat(string, s); }
57 ShowPlayerDialog(playerid, DIALOG_ATTACH1, DIALOG_STYLE_TABLIST, "{33FF00}Objects", string, "Select", "Cancel");
58 return 1;
59}
60public OnPlayerEditAttachedObject(playerid, response, index, modelid, boneid, Float:fOffsetX, Float:fOffsetY, Float:fOffsetZ, Float:fRotX, Float:fRotY, Float:fRotZ, Float:fScaleX, Float:fScaleY, Float:fScaleZ)
61{
62 if(response) {
63 fScaleX = (fScaleX < MINX) ? (MINX) : ((fScaleX > MAXX) ? (MAXX) : (fScaleX));
64 fScaleY = (fScaleY < MINY) ? (MINY) : ((fScaleY > MAXY) ? (MAXY) : (fScaleY));
65 fScaleZ = (fScaleZ < MINZ) ? (MINZ) : ((fScaleZ > MAXZ) ? (MAXZ) : (fScaleZ));
66 oInfo[playerid][index][fOffsetX1] = fOffsetX;
67 oInfo[playerid][index][fOffsetY1] = fOffsetY;
68 oInfo[playerid][index][fOffsetZ1] = fOffsetZ;
69 oInfo[playerid][index][fRotX1] = fRotX;
70 oInfo[playerid][index][fRotY1] = fRotY;
71 oInfo[playerid][index][fRotZ1] = fRotZ;
72 oInfo[playerid][index][fScaleX1] = fScaleX;
73 oInfo[playerid][index][fScaleY1] = fScaleY;
74 oInfo[playerid][index][fScaleZ1] = fScaleZ; }
75 new query[60];
76 SendClientMessage(playerid, -1, "Object {0DFF00}Saved!");
77 SetPlayerAttachedObject(playerid, index, modelid, boneid, oInfo[playerid][index][fOffsetX1], oInfo[playerid][index][fOffsetY1], oInfo[playerid][index][fOffsetZ1], oInfo[playerid][index][fRotX1], oInfo[playerid][index][fRotY1], oInfo[playerid][index][fRotZ1], oInfo[playerid][index][fScaleX1], oInfo[playerid][index][fScaleY1], oInfo[playerid][index][fScaleZ1]);
78 mysql_format(g_SQL, query, sizeof(query), "SELECT * FROM `Objects` WHERE `Index` = %d AND `ID` = %d", index, PlayerInfo[playerid][sqlID]);
79 mysql_tquery(g_SQL, query, "OnObjectSave", "iiii", playerid, index, modelid, boneid);
80 return 1;
81}
82Onplayermodelselection()
83{
84 if(listid == objectlist)
85 {
86 if(response)
87 {
88 inmodel[playerid] = modelid;
89 ShowPlayerDialog(playerid, DIALOG_ATTACH3, DIALOG_STYLE_LIST, "{0DFF00}Bone", "Spine\nHead\nLeft Upper Arm\nRight Upper Arm\nLeft Hand\nRight Hand\nLeft Tight\nRight Tight\nLeft Foot\nRight Foot\nRight Calf\nLeft Calf\nLeft Forearm\nRight Forearm\nLeft Shoulder\nRight Shoulder\nNeck\nJaw", "Select", "Cancel");
90 }
91 return 1;
92 }
93}
94OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
95{
96 if(dialogid == DIALOG_ATTACH1)
97 {
98 if(!response) return 0;
99 new string1[10], string2[75]; inindex[playerid] = listitem;
100 if(oInfo[playerid][listitem][used1] == false) return ShowModelSelectionMenu(playerid, objectlist, "Select An Object");
101 format(string1, sizeof(string1), "Slot %d", listitem+1);
102 format(string2, sizeof(string2), "{33FF00}You have {33FF00}Selected slot %d\nDo you wanna remove or edit it?", listitem+1);
103 ShowPlayerDialog(playerid, DIALOG_ATTACH2, DIALOG_STYLE_MSGBOX, string1, string2, "Edit", "Remove");
104 }
105 else if(dialogid == DIALOG_ATTACH2)
106 {
107 if(response) return EditAttachedObject(playerid, inindex[playerid]);
108 RemovePlayerAttachedObject(playerid, inindex[playerid]);
109 oInfo[playerid][inindex[playerid]][used1] = false;
110 new string[80], query[100];
111 format(string, sizeof(string), "You have {FF0000}removed {FFFFFF}this object. Slot %d is now {0DFF00}free!", inindex[playerid]+1);
112 SendClientMessage(playerid, -1, string);
113 mysql_format(g_SQL, query, sizeof(query), "DELETE FROM `Objects` WHERE `ID` = %d AND `Index` = %d", PlayerInfo[playerid][sqlID], inindex[playerid]);
114 mysql_tquery(g_SQL, query);
115 }
116 else if(dialogid == DIALOG_ATTACH3)
117 {
118 if(response) {
119 SetPlayerAttachedObject(playerid, inindex[playerid], inmodel[playerid], listitem+1);
120 oInfo[playerid][inindex[playerid]][index1] = inindex[playerid];
121 oInfo[playerid][inindex[playerid]][modelid1] = inmodel[playerid];
122 oInfo[playerid][inindex[playerid]][bone1] = listitem+1;
123 oInfo[playerid][inindex[playerid]][used1] = true;
124 EditAttachedObject(playerid, inindex[playerid]); }
125 }
126}
127forward OnObjectLoad(playerid);
128public OnObjectLoad(playerid)
129{
130 for(new i, j=cache_num_rows(); i<j; i++) {
131 cache_get_value_int(i, "Model",oInfo[playerid][i][modelid1]);
132 cache_get_value_int(i, "Bone",oInfo[playerid][i][bone1]);
133 cache_get_value_name_float(i, "OffsetX",oInfo[playerid][i][fOffsetX1]);
134 cache_get_value_name_float(i, "OffsetY",oInfo[playerid][i][fOffsetY1]);
135 cache_get_value_name_float(i, "OffsetZ",oInfo[playerid][i][fOffsetZ1]);
136 cache_get_value_name_float(i, "RotX",oInfo[playerid][i][fRotX1]);
137 cache_get_value_name_float(i, "RotY",oInfo[playerid][i][fRotY1]);
138 cache_get_value_name_float(i, "RotZ",oInfo[playerid][i][fRotZ1]);
139 cache_get_value_name_float(i, "ScaleX",oInfo[playerid][i][fScaleX1]);
140 cache_get_value_name_float(i, "ScaleY",oInfo[playerid][i][fScaleY1]);
141 cache_get_value_name_float(i, "ScaleZ",oInfo[playerid][i][fScaleZ1]);
142 oInfo[playerid][i][used1] = true;
143 }
144}
145forward OnObjectSave(playerid, index, modelid, boneid);
146public OnObjectSave(playerid, index, modelid, boneid)
147{
148 new query[250];
149 if(!cache_num_rows())
150 {
151 mysql_format(g_SQL, query, sizeof(query), "INSERT INTO `Objects` (`ID`,`Index`,`Model`,`Bone`,`OffsetX`,`OffsetY`,`OffsetZ`) VALUES (%d,%d,%d,%d,%f,%f,%f)",PlayerInfo[playerid][sqlID], index, modelid, boneid, oInfo[playerid][index][fOffsetX1], oInfo[playerid][index][fOffsetY1], oInfo[playerid][index][fOffsetZ1]);
152 mysql_tquery(g_SQL, query);
153 mysql_format(g_SQL, query, sizeof(query), "UPDATE `Objects` SET `RotX` = %f, `RotY` = %f, `RotZ` = %f, `ScaleX` = %f, `ScaleY` = %f, `ScaleZ` = %f WHERE `ID` = %d AND `Index` = %d",oInfo[playerid][index][fRotX1], oInfo[playerid][index][fRotY1], oInfo[playerid][index][fRotZ1], oInfo[playerid][index][fScaleX1], oInfo[playerid][index][fScaleY1], oInfo[playerid][index][fScaleZ1], PlayerInfo[playerid][sqlID], oInfo[playerid][index][index1]);
154 mysql_tquery(g_SQL, query);
155 }
156 mysql_format(g_SQL, query, sizeof(query), "UPDATE `Objects` SET `Model` = %d,`Bone` = %d,`OffsetX` = %f,`OffsetY` = %f,`OffsetZ` = %f WHERE `ID` = %d AND `Index` = %d",modelid, boneid, oInfo[playerid][index][fOffsetX1], oInfo[playerid][index][fOffsetY1], oInfo[playerid][index][fOffsetZ1], PlayerInfo[playerid][sqlID], oInfo[playerid][index][index1]);
157 mysql_tquery(g_SQL, query);
158 mysql_format(g_SQL, query, sizeof(query), "UPDATE `Objects` SET `RotX` = %f, `RotY` = %f, `RotZ` = %f, `ScaleX` = %f, `ScaleY` = %f, `ScaleZ` = %f WHERE `ID` = %d AND `Index` = %d",oInfo[playerid][index][fRotX1], oInfo[playerid][index][fRotY1], oInfo[playerid][index][fRotZ1], oInfo[playerid][index][fScaleX1], oInfo[playerid][index][fScaleY1], oInfo[playerid][index][fScaleZ1], PlayerInfo[playerid][sqlID], oInfo[playerid][index][index1]);
159 mysql_tquery(g_SQL, query);
160}
161I kad se igrac uloguje
162new query[100];
163mysql_format(g_SQL, query, sizeof(query), "SELECT * FROM `objects` WHERE `ID` = %d", PlayerInfo[playerid][sqlID]);
164mysql_tquery(g_SQL, query, "OnObjectLoad", "i", playerid);