· 9 years ago · Feb 04, 2017, 11:02 PM
1
2// How to load maps from the mysql server
3
4enum MapsEnum {
5
6 objectid,
7 Float:posX,
8 Float:posY,
9 Float:posZ,
10 Float:rotX,
11 Float:rotY,
12 Float:rotZ
13};
14
15new MapsInfo[MAX_OBJECTS][MapsEnum];
16
17forward onMapsInit();
18
19public OnGameModeInit()
20{
21 mysql_query(mysqlhandle, "CREATE TABLE IF NOT EXISTS `maps` ( `objectid` INT(4), `floatX` FLOAT(16), `floatY` FLOAT(16), `floatZ` FLOAT(16), `rotationX` FLOAT(16), `rotationY` FLOAT(16), `rotationZ` FLOAT(16))");
22 mysql_tquery(mysqlhandle, "SELECT * FROM `maps`", "onMapsInit", "");
23}
24
25public onMapsInit()
26{
27 for(new i = 0; i < MAX_OBJECTS; i++) {
28 new rows;
29 if(rows) {
30
31 cache_get_name_int(0, "objectid", MapsInfo[i][objectid]);
32 cache_get_name_float(0, "floatX", MapsInfo[i][posX]);
33 cache_get_name_float(0, "floatY", MapsInfo[i][posY]);
34 cache_get_name_float(0, "floatZ", MapsInfo[i][posZ]);
35 cache_get_name_float(0, "rotationX", MapsInfo[i][rotX]);
36 cache_get_name_float(0, "rotationY", MapsInfo[i][rotY]);
37 cache_get_name_float(0, "rotationZ", MapsInfo[i][rotZ]);
38
39 Createobject(MapsInfo[i][objectid], MapsInfo[i][posX], MapsInfo[i][posY], MapsInfo[i][posZ], MapsInfo[i][rotX], MapsInfo[i][rotY], MapsInfo[i][rotZ]);
40 }
41 }
42}
43
44// How to upload to it
45
46/**** How to create maps.txt ****/
47
48/*
49
50 First :
51 Get all Createobjects on it
52
53 Second:
54
55 convert it to arguments
56 ex:
57 CreateObject(2587, 2001.195679, 1547.113892, 14.283400, 0.0, 0.0, 96.0, 300.0);
58 change it to
59
60 2587, 2001.195679, 1547.113892, 14.283400, 0.0, 0.0, 96.0
61
62 and put it in the file
63
64 you don't need to add a draw distance Please be sure the file located at scriptfiles/maps.txt
65
66 Have fun !
67*/
68
69CMD:uploadmaps(playerid, params[])
70{
71 SendClientMessageToAll(-1, "[SERVER]: We are upload maps to mysql server this might create some lags for a few seconds");
72 new Argument[9][70];
73 new objects;
74 new File: mapsfile = fopen("maps.txt", io_read);
75 if (mapsfile)
76 {
77 for(new i = 0; i < MAX_OBJECTS; i++)
78 {
79 MapsInfo[i][objectid] = strval(Argument[0]);
80 MapsInfo[i][posX] = floatstr(Argument[1]);
81 MapsInfo[i][posY] = floatstr(Argument[2]);
82 MapsInfo[i][posZ] = floatstr(Argument[3]);
83 MapsInfo[i][rotX] = floatstr(Argument[4]);
84 MapsInfo[i][rotY] = floatstr(Argument[5]);
85 MapsInfo[i][rotZ] = floatstr(Argument[6]);
86 objects++;
87
88 mysql_query(mysqlhandle, "INSERT INTO `maps` (`objectid`, `floatX`, `floatY`, `floatZ`, `rotationX`, `rotationY`, `rotationZ`) VALUES (%d, %f, %f, %f, %f, %f, %f)",
89 MapsInfo[i][objectid], MapsInfo[i][posX], MapsInfo[i][posY], MapsInfo[i][posZ], MapsInfo[i][rotX], MapsInfo[i][rotY], MapsInfo[i][rotZ]);
90 }
91 printf("=====================================================");
92 printf("|| %d objects has been uploaded to mysql server ||", objects);
93 printf("=====================================================");
94 }
95 return 1;
96}