SHOW:
|
|
- or go back to the newest paste.
| 1 | //IN GAME DYNAMIC MAPS by ^_^ (SmileySmile) | |
| 2 | /*The MIT License (MIT) | |
| 3 | ||
| 4 | Copyright (c) 2014 Nicholas_West ^_^(SmileySmile), skype: nick_nr01 | |
| 5 | ||
| 6 | Permission is hereby granted, free of charge, to any person obtaining a copy | |
| 7 | of this software and associated documentation files (the "Software"), to deal | |
| 8 | in the Software without restriction, including without limitation the rights | |
| 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| 10 | copies of the Software, and to permit persons to whom the Software is | |
| 11 | furnished to do so, subject to the following conditions: | |
| 12 | ||
| 13 | The above copyright notice and this permission notice shall be included in all | |
| 14 | copies or substantial portions of the Software. | |
| 15 | ||
| 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
| 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
| 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
| 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
| 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
| 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
| 22 | SOFTWARE.*/ | |
| 23 | #if !defined STREAMER_TYPE_OBJECT | |
| 24 | #error DynamicMaps requires Streamer. | |
| 25 | #endif | |
| 26 | #if !defined MAX_MAPS | |
| 27 | #define MAX_MAPS (100) | |
| 28 | #endif | |
| 29 | #if !defined MAX_POINTS | |
| 30 | #define MAX_POINTS (MAX_MAPS*30) | |
| 31 | #endif | |
| 32 | #define INVALID_MAP_ID (DynamicMap:-1) | |
| 33 | #define INVALID_POINT_ID (Point:-1) | |
| 34 | enum | |
| 35 | {
| |
| 36 | POINT_WHITE = 19177, | |
| 37 | POINT_GREEN, | |
| 38 | POINT_RED, | |
| 39 | POINT_ORANGE, | |
| 40 | POINT_YELLOW | |
| 41 | } | |
| 42 | enum | |
| 43 | {
| |
| 44 | TINY_POINT=0, | |
| 45 | SMALL_POINT=0.005, | |
| 46 | MEDIUM_POINT=0.01, | |
| 47 | BIG_POINT=0.015, | |
| 48 | HUGE_POINT=0.02 | |
| 49 | } | |
| 50 | enum map_Data | |
| 51 | {
| |
| 52 | bool:_m_created, | |
| 53 | _m_objects_id, | |
| 54 | Float:_m_center_x, | |
| 55 | Float:_m_center_y, | |
| 56 | Float:_m_center_z, | |
| 57 | Float:_m_rotation_z, | |
| 58 | _m_vw, | |
| 59 | _m_i | |
| 60 | } | |
| 61 | enum point_Data | |
| 62 | {
| |
| 63 | _p_id, | |
| 64 | _p_mapid, | |
| 65 | Float:_p_size, | |
| 66 | Float:_p_current_mx, | |
| 67 | Float:_p_current_my, | |
| 68 | Float:_p_current_mz, | |
| 69 | Float:_p_current_ms, | |
| 70 | _p_vw, | |
| 71 | _p_i | |
| 72 | } | |
| 73 | static map_data[MAX_MAPS][map_Data]; | |
| 74 | static point_data[MAX_POINTS][point_Data]; | |
| 75 | stock DynamicMap:CreateDynamicMap(Float:_center_x, Float:_center_y, Float:_center_z, Float:_rotation_z, _vw = -1, _i = -1) | |
| 76 | {
| |
| 77 | new _tm_id; | |
| 78 | for _tm_id = 0; _tm_id < sizeof map_data; _tm_id++ do | |
| 79 | if !map_data[_tm_id][_m_created] *then break; | |
| 80 | if map_data[_tm_id][_m_created] || _tm_id == _:INVALID_MAP_ID *then return INVALID_MAP_ID; | |
| 81 | new Float:_tm_distancex = 1.5 * floatcos(_rotation_z/2, degrees) * floatsin(_rotation_z/2, degrees), Float:_tm_distancey = 1.5 * floatpower(floatsin(_rotation_z/2, degrees), 2); | |
| 82 | map_data[_tm_id][_m_objects_id] = CreateDynamicObject(19171, _center_x - _tm_distancex, _center_y+0.75000-_tm_distancey, _center_z-0.75000, 90.00000, 90.00000, _rotation_z); | |
| 83 | CreateDynamicObject(19169, _center_x - _tm_distancex, _center_y+0.75000-_tm_distancey, _center_z+0.75000, 90.00000, 90.00000, _rotation_z); | |
| 84 | CreateDynamicObject(19170, _center_x + _tm_distancex, _center_y-0.75000+_tm_distancey, _center_z-0.75000, 90.00000, 90.00000, _rotation_z); | |
| 85 | CreateDynamicObject(19168, _center_x + _tm_distancex, _center_y-0.75000+_tm_distancey, _center_z+0.75000, 90.00000, 90.00000, _rotation_z); | |
| 86 | map_data[_tm_id][_m_created] = true; | |
| 87 | map_data[_tm_id][_m_center_x] = _center_x; | |
| 88 | map_data[_tm_id][_m_center_y] = _center_y; | |
| 89 | map_data[_tm_id][_m_center_z] = _center_z; | |
| 90 | map_data[_tm_id][_m_rotation_z] = _rotation_z; | |
| 91 | map_data[_tm_id][_m_vw] = _vw; | |
| 92 | map_data[_tm_id][_m_i] = _i; | |
| 93 | return DynamicMap:_tm_id; | |
| 94 | } | |
| 95 | stock DestroyDynamicMap(DynamicMap:mapid) | |
| 96 | {
| |
| 97 | if !map_data[_:mapid][_m_created] || mapid == INVALID_MAP_ID *then return 0; | |
| 98 | DestroyDynamicObject(map_data[_:mapid][_m_objects_id]); | |
| 99 | DestroyDynamicObject(map_data[_:mapid][_m_objects_id]+1); | |
| 100 | DestroyDynamicObject(map_data[_:mapid][_m_objects_id]+2); | |
| 101 | DestroyDynamicObject(map_data[_:mapid][_m_objects_id]+3); | |
| 102 | map_data[_:mapid][_m_objects_id] = 0; | |
| 103 | for new _pt_sid; _pt_sid < sizeof point_data; _pt_sid++ do | |
| 104 | if point_data[_pt_sid][_p_mapid] == _:mapid && point_data[_pt_sid][_p_id] *then{
| |
| 105 | DestroyDynamicObject(point_data[_pt_sid][_p_id]); | |
| 106 | point_data[_pt_sid][_p_id] = 0; | |
| 107 | point_data[_pt_sid][_p_mapid] = 0; | |
| 108 | point_data[_pt_sid][_p_size] = 0.0; | |
| 109 | point_data[_pt_sid][_p_current_mx] = 0.0; | |
| 110 | point_data[_pt_sid][_p_current_my] = 0.0; | |
| 111 | point_data[_pt_sid][_p_current_mz] = 0.0; | |
| 112 | point_data[_pt_sid][_p_current_ms] = 0.0; | |
| 113 | point_data[_pt_sid][_p_vw] = 0; | |
| 114 | point_data[_pt_sid][_p_i] = 0; | |
| 115 | } | |
| 116 | map_data[_:mapid][_m_created] = false; | |
| 117 | map_data[_:mapid][_m_center_x] = 0.0; | |
| 118 | map_data[_:mapid][_m_center_y] = 0.0; | |
| 119 | map_data[_:mapid][_m_center_z] = 0.0; | |
| 120 | map_data[_:mapid][_m_rotation_z] = 0.0; | |
| 121 | map_data[_:mapid][_m_vw] = 0; | |
| 122 | map_data[_:mapid][_m_i] = 0; | |
| 123 | return 1; | |
| 124 | } | |
| 125 | stock Point:CreatePointForDynamicMap(DynamicMap:mapid, point_object, Float:_point_size=0.0, Float:p_realC_x = 0.0, Float:p_realC_y = 0.0, _vw = -1, _i = -1) | |
| 126 | {
| |
| 127 | if mapid == INVALID_MAP_ID || !map_data[_:mapid][_m_created] *then return INVALID_POINT_ID; | |
| 128 | new _pt_sid; | |
| 129 | for _pt_sid = 0; _pt_sid < sizeof point_data; _pt_sid++ do | |
| 130 | if !point_data[_pt_sid][_p_id] *then break; | |
| 131 | if point_data[_pt_sid][_p_id] || _pt_sid == _:INVALID_POINT_ID *then return INVALID_POINT_ID; | |
| 132 | new Float:_pt_x, Float:_pt_y, Float:_pt_z; | |
| 133 | GetDynamicMapCoords(p_realC_x, p_realC_y, mapid, _pt_x, _pt_y, _pt_z, _point_size); | |
| 134 | if map_data[_:mapid][_m_vw] != -1 && map_data[_:mapid][_m_vw] != _vw *then _vw = map_data[_:mapid][_m_vw]; | |
| 135 | if map_data[_:mapid][_m_i] != -1 && map_data[_:mapid][_m_i] != _i *then _i = map_data[_:mapid][_m_i]; | |
| 136 | new _pt_id = CreateDynamicObject(point_object, _pt_x, _pt_y, _pt_z, 90.00000, 90.00000, map_data[_:mapid][_m_rotation_z], _vw, _i); | |
| 137 | point_data[_pt_sid][_p_id] = _pt_id; | |
| 138 | point_data[_pt_sid][_p_mapid] = _:mapid; | |
| 139 | point_data[_pt_sid][_p_size] = _point_size; | |
| 140 | point_data[_pt_sid][_p_vw] = _vw; | |
| 141 | point_data[_pt_sid][_p_i] = _i; | |
| 142 | return Point:_pt_sid; | |
| 143 | } | |
| 144 | stock DestroyPoint(Point:_pointid) | |
| 145 | {
| |
| 146 | if _pointid == INVALID_POINT_ID || !point_data[_:_pointid][_p_id] *then return 0; | |
| 147 | DestroyDynamicObject(point_data[_:_pointid][_p_id]); | |
| 148 | point_data[_:_pointid][_p_id] = 0; | |
| 149 | point_data[_:_pointid][_p_mapid] = 0; | |
| 150 | point_data[_:_pointid][_p_size] = 0.0; | |
| 151 | point_data[_:_pointid][_p_current_mx] = 0.0; | |
| 152 | point_data[_:_pointid][_p_current_my] = 0.0; | |
| 153 | point_data[_:_pointid][_p_current_mz] = 0.0; | |
| 154 | point_data[_:_pointid][_p_current_ms] = 0.0; | |
| 155 | point_data[_:_pointid][_p_vw] = 0; | |
| 156 | point_data[_:_pointid][_p_i] = 0; | |
| 157 | return 1; | |
| 158 | } | |
| 159 | stock SetPointSize(Point:_pointid, Float:_pt_size) | |
| 160 | {
| |
| 161 | if _pointid == INVALID_POINT_ID || !point_data[_:_pointid][_p_id] *then return 0; | |
| 162 | if _pt_size == point_data[_:_pointid][_p_size] *then return -1; | |
| 163 | new Float:_tp_curx, Float:_tp_cury, Float:_tp_curz; | |
| 164 | GetDynamicObjectPos(point_data[_:_pointid][_p_id], _tp_curx, _tp_cury, _tp_curz); | |
| 165 | new Float:_m_rotation = map_data[point_data[_:_pointid][_p_mapid]][_m_rotation_z] - 180.0; | |
| 166 | SetDynamicObjectPos(point_data[_:_pointid][_p_id], _tp_curx + floatcos(_m_rotation, degrees)*(point_data[_:_pointid][_p_size] - _pt_size), | |
| 167 | _tp_cury + floatsin(_m_rotation, degrees)*(point_data[_:_pointid][_p_size] - _pt_size), _tp_curz); | |
| 168 | point_data[_:_pointid][_p_size] = _pt_size; | |
| 169 | if IsDynamicObjectMoving(point_data[_:_pointid][_p_id]) *then{
| |
| 170 | MoveDynamicObject(point_data[_:_pointid][_p_id], point_data[_:_pointid][_p_current_mx], point_data[_:_pointid][_p_current_my], point_data[_:_pointid][_p_current_mz], | |
| 171 | point_data[_:_pointid][_p_current_ms]); | |
| 172 | return 2; | |
| 173 | } | |
| 174 | return 1; | |
| 175 | } | |
| 176 | stock SetPointObject(Point:_pointid, pointobject) | |
| 177 | {
| |
| 178 | if _pointid == INVALID_POINT_ID || !point_data[_:_pointid][_p_id] *then return 0; | |
| 179 | new Float:_tp_curx, Float:_tp_cury, Float:_tp_curz; | |
| 180 | GetDynamicObjectPos(point_data[_:_pointid][_p_id], _tp_curx, _tp_cury, _tp_curz); | |
| 181 | DestroyDynamicObject(point_data[_:_pointid][_p_id]); | |
| 182 | point_data[_:_pointid][_p_id] = CreateDynamicObject(pointobject, _tp_curx, _tp_cury, _tp_curz, 90.00000, 90.00000, map_data[point_data[_:_pointid][_p_mapid]][_m_rotation_z], point_data[_:_pointid][_p_vw], point_data[_:_pointid][_p_i]); | |
| 183 | return 1; | |
| 184 | } | |
| 185 | stock AssignPointToPos(Point:_pointid, Float:real_x, Float:real_y) | |
| 186 | {
| |
| 187 | if _pointid == INVALID_POINT_ID || !point_data[_:_pointid][_p_id] *then return 0; | |
| 188 | new Float:_pt_x, Float:_pt_y, Float:_pt_z; | |
| 189 | GetDynamicMapCoords(real_x, real_y, DynamicMap:point_data[_:_pointid][_p_mapid], _pt_x, _pt_y, _pt_z, point_data[_:_pointid][_p_size]); | |
| 190 | SetDynamicObjectPos(point_data[_:_pointid][_p_id], _pt_x, _pt_y, _pt_z); | |
| 191 | point_data[_:_pointid][_p_current_mx] = 0.0; | |
| 192 | point_data[_:_pointid][_p_current_my] = 0.0; | |
| 193 | point_data[_:_pointid][_p_current_mz] = 0.0; | |
| 194 | return 1; | |
| 195 | } | |
| 196 | stock MovePointForPos(Point:_pointid, Float:real_mx, Float:real_my, Float:movespeed = 0.1) | |
| 197 | {
| |
| 198 | if _pointid == INVALID_POINT_ID || !point_data[_:_pointid][_p_id] *then return 0; | |
| 199 | new Float:_t_mx, Float:_t_my, Float:_t_mz; | |
| 200 | GetDynamicMapCoords(real_mx, real_my, DynamicMap:point_data[_:_pointid][_p_mapid], _t_mx, _t_my, _t_mz, point_data[_:_pointid][_p_size]); | |
| 201 | MoveDynamicObject(point_data[_:_pointid][_p_id], _t_mx, _t_my, _t_mz, movespeed); | |
| 202 | point_data[_:_pointid][_p_current_mx] = _t_mx; | |
| 203 | point_data[_:_pointid][_p_current_my] = _t_my; | |
| 204 | point_data[_:_pointid][_p_current_mz] = _t_mz; | |
| 205 | return 1; | |
| 206 | } | |
| 207 | stock GetDynamicMapCoords(Float:x,Float:y, DynamicMap:mapid, &Float:on_map_x,&Float:on_map_y,&Float:on_map_z, Float:_point_size) | |
| 208 | {
| |
| 209 | on_map_x = x/2000 + map_data[_:mapid][_m_center_x]; | |
| 210 | on_map_z = y/2000 + map_data[_:mapid][_m_center_z]; | |
| 211 | on_map_y = map_data[_:mapid][_m_center_y]; | |
| 212 | _point_size += 0.015; | |
| 213 | new Float:pointdistance = map_data[_:mapid][_m_center_x] - on_map_x, Float:map_rotation = 270 - map_data[_:mapid][_m_rotation_z]; | |
| 214 | on_map_y += 2*floatcos(map_rotation/2, degrees) * floatsin(map_rotation/2, degrees) * pointdistance - _point_size*floatsin(90-map_rotation, degrees); | |
| 215 | on_map_x += 2*floatpower(floatsin(map_rotation/2, degrees), 2) * pointdistance - _point_size*floatcos(90-map_rotation, degrees); | |
| 216 | } | |
| 217 | stock GetDynamicMapPointRealCoords(DynamicMap:_mapid, Float:on_map_x, Float:on_map_y, Float:on_map_z, &Float:real_x, &Float:real_y) | |
| 218 | {
| |
| 219 | real_x = ((map_data[_:_mapid][_m_center_x] - on_map_x) > 0 ? -1 : 1) * (floatsin(map_data[_:_mapid][_m_rotation_z] - 180.0) >= 0 ? -1 : 1) * floatsqroot(floatpower(map_data[_:_mapid][_m_center_x] - on_map_x, 2) + floatpower(map_data[_:_mapid][_m_center_y] - on_map_y, 2)) * 2000; | |
| 220 | real_y = (on_map_z - map_data[_:_mapid][_m_center_z]) * 2000; | |
| 221 | } |