SHOW:
|
|
- or go back to the newest paste.
| 1 | #include <a_samp> | |
| 2 | #include <a_locs> | |
| 3 | ||
| 4 | forward public ChangeStage(); | |
| 5 | ||
| 6 | #define ALLOW_COMMANDS ( true ) | |
| 7 | ||
| 8 | #define PICKUP_MODEL_ID ( 1550 ) | |
| 9 | ||
| 10 | #define STAGE_SPAWNED ( 0 ) | |
| 11 | #define STAGE_REVEAL_LOC ( 1 ) | |
| 12 | #define STAGE_REVEAL_CLP ( 2 ) | |
| 13 | #define STAGE_REVEAL_DIS ( 3 ) | |
| 14 | #define STAGE_INVALID ( -1 ) | |
| 15 | ||
| 16 | #define TIMER_UPDATE_MINS ( 1 ) | |
| 17 | ||
| 18 | #define NEW_MONEYBAG_DELAY ( 5 ) | |
| 19 | ||
| 20 | #define PRIZE_LOWER_LIMIT ( 22500 ) | |
| 21 | #define PRIZE_UPPER_LIMIT ( 43000 ) | |
| 22 | ||
| 23 | #define IsPlayerAllowed(%0) ( IsPlayerAdmin(%0) ) | |
| 24 | ||
| 25 | #if ALLOW_COMMANDS == true | |
| 26 | ||
| 27 | #include <zcmd> | |
| 28 | ||
| 29 | #endif | |
| 30 | ||
| 31 | #include <moneybag_locations> | |
| 32 | ||
| 33 | static gMoneyBag = INVALID_OBJECT_ID, | |
| 34 | gCurrStage = STAGE_INVALID, | |
| 35 | Float: g_fCurrPos[3] = { 0.0, 0.0, 0.0 },
| |
| 36 | gTimer = -1, | |
| 37 | gCurrPrize = 0; | |
| 38 | ||
| 39 | public OnFilterScriptInit() | |
| 40 | {
| |
| 41 | ChangeStage(); | |
| 42 | gTimer = SetTimer("ChangeStage", ( TIMER_UPDATE_MINS * 60 * 1000 ), 1);
| |
| 43 | return 1; | |
| 44 | } | |
| 45 | ||
| 46 | public ChangeStage() | |
| 47 | {
| |
| 48 | switch( gCurrStage ) | |
| 49 | {
| |
| 50 | case STAGE_INVALID: | |
| 51 | {
| |
| 52 | new _rand = random(sizeof(g_MoneyBagSpawns)), _string[128]; | |
| 53 | ||
| 54 | gMoneyBag = CreatePickup(PICKUP_MODEL_ID, 2, g_MoneyBagSpawns[_rand][0], g_MoneyBagSpawns[_rand][1], g_MoneyBagSpawns[_rand][2], 0); | |
| 55 | ||
| 56 | gCurrPrize = ( random( (PRIZE_UPPER_LIMIT - PRIZE_LOWER_LIMIT) ) + PRIZE_LOWER_LIMIT ); | |
| 57 | ||
| 58 | for(new i = 0; i < 3; i++) | |
| 59 | {
| |
| 60 | g_fCurrPos[i] = g_MoneyBagSpawns[_rand][i]; | |
| 61 | } | |
| 62 | ||
| 63 | format(_string, sizeof(_string), "{4AE8E8}INFO: {FFFFFF}A moneybag (worth $%s) has been spawned!", AddCharComma(gCurrPrize));
| |
| 64 | SendClientMessageToAll(-1, _string); | |
| 65 | ||
| 66 | gCurrStage = STAGE_SPAWNED ; | |
| 67 | } | |
| 68 | case STAGE_SPAWNED: | |
| 69 | {
| |
| 70 | new _string[128], _loc[30]; | |
| 71 | Get2DZone(g_fCurrPos[0], g_fCurrPos[1], _loc, sizeof(_loc)); | |
| 72 | format(_string, sizeof(_string), "{4AE8E8}INFO: {FFFFFF}The money bag is in '%s'.", _loc);
| |
| 73 | ||
| 74 | SendClientMessageToAll(-1, _string); | |
| 75 | ||
| 76 | gCurrStage = STAGE_REVEAL_LOC ; | |
| 77 | } | |
| 78 | case STAGE_REVEAL_LOC: | |
| 79 | {
| |
| 80 | new cPlayer = GetClosestTo(g_fCurrPos[0], g_fCurrPos[1], g_fCurrPos[2]), | |
| 81 | _string[128]; | |
| 82 | ||
| 83 | if( cPlayer != INVALID_PLAYER_ID ) | |
| 84 | {
| |
| 85 | new _name[ MAX_PLAYER_NAME ]; | |
| 86 | GetPlayerName(cPlayer, _name, MAX_PLAYER_NAME); | |
| 87 | format(_string, sizeof(_string), "{4AE8E8}INFO: {4AE8E8}%s (%d){FFFFFF} is closest to the money bag!", _name, cPlayer);
| |
| 88 | } | |
| 89 | else format(_string, sizeof(_string), "{4AE8E8}INFO: {FFFFFF}There is no one close to the money bag, yet.");
| |
| 90 | ||
| 91 | SendClientMessageToAll(-1, _string); | |
| 92 | ||
| 93 | gCurrStage = STAGE_REVEAL_CLP; | |
| 94 | } | |
| 95 | case STAGE_REVEAL_CLP: | |
| 96 | {
| |
| 97 | new clPlayer = GetClosestTo(g_fCurrPos[0], g_fCurrPos[1], g_fCurrPos[2]), | |
| 98 | Float: fDist, | |
| 99 | _string[128]; | |
| 100 | if( clPlayer != INVALID_PLAYER_ID) | |
| 101 | {
| |
| 102 | new _name[MAX_PLAYER_NAME]; | |
| 103 | fDist = GetPlayerDistanceFromPoint(clPlayer, g_fCurrPos[0], g_fCurrPos[1], g_fCurrPos[2]); | |
| 104 | GetPlayerName(clPlayer, _name, MAX_PLAYER_NAME); | |
| 105 | format(_string, sizeof(_string), "{4AE8E8}INFO: {FFFFFF}The distance of the closest player - {4AE8E8}%s (%d) - {FFFFFF}from the money bag is %d metres.", _name, clPlayer, floatround(fDist));
| |
| 106 | } | |
| 107 | else | |
| 108 | format(_string, sizeof(_string), "{4AE8E8}INFO: {FFFFFF}There is no one yet close the the money bag!");
| |
| 109 | ||
| 110 | SendClientMessageToAll(-1, _string); | |
| 111 | ||
| 112 | gCurrStage = STAGE_REVEAL_DIS; | |
| 113 | } | |
| 114 | case STAGE_REVEAL_DIS: | |
| 115 | {
| |
| 116 | SendClientMessageToAll(-1, "{4AE8E8}INFO: {FFFFFF}No one could find the money bag, and it has been reset!");
| |
| 117 | ||
| 118 | DestroyPickup(gMoneyBag); | |
| 119 | ||
| 120 | gMoneyBag = -1; | |
| 121 | ||
| 122 | KillTimer(gTimer); | |
| 123 | SetTimer("ChangeStage", (NEW_MONEYBAG_DELAY * 60 * 1000), 1);
| |
| 124 | ||
| 125 | gCurrStage = STAGE_INVALID; | |
| 126 | } | |
| 127 | } | |
| 128 | ||
| 129 | return 1; | |
| 130 | } | |
| 131 | ||
| 132 | GetClosestTo( Float: x, Float: y, Float: z ) | |
| 133 | {
| |
| 134 | new Float: _temp_closest = ((6000 * 1.41)), Float: _dist = 0.0, | |
| 135 | _temp_player = -1; | |
| 136 | ||
| 137 | for(new i = 0; i < MAX_PLAYERS; i++) | |
| 138 | {
| |
| 139 | if(IsPlayerConnected(i)) | |
| 140 | {
| |
| 141 | _dist = GetPlayerDistanceFromPoint(i, x, y, z); | |
| 142 | if( _dist < _temp_closest ) | |
| 143 | {
| |
| 144 | _temp_closest = _dist; | |
| 145 | _temp_player = i ; | |
| 146 | } | |
| 147 | } | |
| 148 | } | |
| 149 | return ( ( _temp_player == -1 ) ? ( INVALID_PLAYER_ID ) : _temp_player ); | |
| 150 | } | |
| 151 | ||
| 152 | AddCharComma(number) | |
| 153 | {
| |
| 154 | new _temp[24], _counter = -1; | |
| 155 | ||
| 156 | valstr(_temp, number); | |
| 157 | ||
| 158 | for(new i = strlen(_temp) ;i > 0; i--) | |
| 159 | {
| |
| 160 | _counter++; | |
| 161 | if(_counter == 3) | |
| 162 | {
| |
| 163 | strins( _temp, ",", i ); | |
| 164 | _counter = 0; | |
| 165 | } | |
| 166 | } | |
| 167 | return _temp; | |
| 168 | } | |
| 169 | ||
| 170 | ||
| 171 | public OnPlayerPickUpPickup(playerid, pickupid) | |
| 172 | {
| |
| 173 | if(pickupid == gMoneyBag) | |
| 174 | {
| |
| 175 | gCurrStage = STAGE_INVALID; | |
| 176 | ||
| 177 | DestroyPickup(gMoneyBag); | |
| 178 | ||
| 179 | gMoneyBag = INVALID_OBJECT_ID; | |
| 180 | ||
| 181 | new _name[MAX_PLAYER_NAME], _string[128] ; | |
| 182 | GetPlayerName(playerid, _name, MAX_PLAYER_NAME); | |
| 183 | ||
| 184 | format(_string, sizeof(_string), "{4AE8E8}INFO: {FFFFFF}%s (%d) has found the money bag, and won $%s!", _name, playerid, AddCharComma(gCurrPrize) );
| |
| 185 | SendClientMessageToAll(-1, _string); | |
| 186 | ||
| 187 | GivePlayerMoney(playerid, gCurrPrize); | |
| 188 | ||
| 189 | SendClientMessageToAll(-1, "{4AE8E8}INFO: {FFFFFF}The money bag will be started in a few minutes!");
| |
| 190 | ||
| 191 | KillTimer(gTimer); | |
| 192 | SetTimer("ChangeStage", (NEW_MONEYBAG_DELAY * 60 * 1000), 1);
| |
| 193 | ||
| 194 | gCurrStage = STAGE_INVALID; | |
| 195 | } | |
| 196 | return 1; | |
| 197 | } | |
| 198 | ||
| 199 | #if ALLOW_COMMANDS == true | |
| 200 | ||
| 201 | COMMAND:startmoneybag(playerid) | |
| 202 | {
| |
| 203 | if(IsPlayerAllowed(playerid)) | |
| 204 | {
| |
| 205 | gCurrStage = STAGE_INVALID; | |
| 206 | ||
| 207 | ChangeStage(); | |
| 208 | gTimer = SetTimer("ChangeStage", ( TIMER_UPDATE_MINS * 60 * 1000 ), 1);
| |
| 209 | ||
| 210 | return SendClientMessage(playerid, -1, "{4AE8E8}INFO: {FFFFFF}Started money bag successfully!");
| |
| 211 | } | |
| 212 | return 0; | |
| 213 | } | |
| 214 | ||
| 215 | COMMAND:startmb(playerid) | |
| 216 | {
| |
| 217 | return cmd_startmoneybag(playerid); | |
| 218 | } | |
| 219 | ||
| 220 | COMMAND:gotomoneybag(playerid) | |
| 221 | {
| |
| 222 | if(IsPlayerAllowed(playerid)) | |
| 223 | {
| |
| 224 | new Float: x, Float: y, Float: angle; | |
| 225 | GetPlayerFacingAngle(playerid, angle); | |
| 226 | ||
| 227 | x = g_fCurrPos[0]; | |
| 228 | y = g_fCurrPos[1]; | |
| 229 | ||
| 230 | x -= ( 4 * floatcos( (angle), degrees ) ); | |
| 231 | y -= ( 4 * floatsin( (angle), degrees ) ); | |
| 232 | ||
| 233 | SetPlayerPos(playerid, x, y, g_fCurrPos[2]); | |
| 234 | ||
| 235 | return SendClientMessage(playerid, -1, "{4AE8E8}INFO: {FFFFFF}Teleported to the moneybag successfully!");
| |
| 236 | } | |
| 237 | return 0; | |
| 238 | } | |
| 239 | ||
| 240 | COMMAND:gotomb(playerid) | |
| 241 | {
| |
| 242 | return cmd_gotomoneybag(playerid); | |
| 243 | } | |
| 244 | ||
| 245 | COMMAND:resetmoneybag(playerid) | |
| 246 | {
| |
| 247 | if(IsPlayerAllowed(playerid)) | |
| 248 | {
| |
| 249 | SendClientMessageToAll(-1, "{4AE8E8}INFO:{FFFFFF} The money bag has been reset.");
| |
| 250 | ||
| 251 | DestroyPickup(gMoneyBag); | |
| 252 | ||
| 253 | gMoneyBag = -1; | |
| 254 | ||
| 255 | KillTimer(gTimer); | |
| 256 | SetTimer("ChangeStage", (NEW_MONEYBAG_DELAY * 60 * 1000), 1);
| |
| 257 | ||
| 258 | gCurrStage = STAGE_INVALID; | |
| 259 | ||
| 260 | return SendClientMessage(playerid, -1, "{4AE8E8}INFO: {FFFFFF}You have reset the money bag!");
| |
| 261 | } | |
| 262 | return 0; | |
| 263 | } | |
| 264 | ||
| 265 | COMMAND:resetmb(playerid) | |
| 266 | {
| |
| 267 | return cmd_resetmoneybag(playerid); | |
| 268 | } | |
| 269 | ||
| 270 | COMMAND:stopmoneybag(playerid) | |
| 271 | {
| |
| 272 | if(IsPlayerAllowed(playerid)) | |
| 273 | {
| |
| 274 | SendClientMessageToAll(-1, "{4AE8E8}INFO: {FFFFFF}The money bag has been stopped.");
| |
| 275 | ||
| 276 | DestroyPickup(gMoneyBag); | |
| 277 | ||
| 278 | gMoneyBag = -1; | |
| 279 | ||
| 280 | KillTimer(gTimer); | |
| 281 | ||
| 282 | gCurrStage = STAGE_INVALID; | |
| 283 | ||
| 284 | return SendClientMessage(playerid, -1, "{4AE8E8}INFO: {FFFFFF}You have stopped the money bag!");
| |
| 285 | } | |
| 286 | return 0; | |
| 287 | } | |
| 288 | ||
| 289 | COMMAND:stopmb(playerid) | |
| 290 | {
| |
| 291 | return cmd_stopmoneybag(playerid); | |
| 292 | } | |
| 293 | ||
| 294 | #endif |