Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <string>
- #include <assert.h>
- #include <process.h>
- #include <ctime>
- #include "SAMPFUNCS_API.h"
- #include "game_api\game_api.h"
- SAMPFUNCS *SF = new SAMPFUNCS();
- stFontInfo* pFont;
- unsigned int simplex_seed = 0xCAA938DB;
- long long int nrandom(long long int max)
- {
- int min = 0;
- unsigned int INITIAL_SEED = 0xCAA938DB;
- long long int IL_RMULT = (1103515245);
- if (min > max)
- min ^= max, max ^= min, min ^= max;
- if (simplex_seed == INITIAL_SEED)
- {
- simplex_seed = time(0);
- }
- long long int lo, hi, ll, lh, hh, hl;
- long long int result;
- lo = simplex_seed & 0xffff;
- hi = simplex_seed >> 16;
- ll = lo * (IL_RMULT & 0xffff);
- lh = lo * (IL_RMULT >> 16);
- hl = hi * (IL_RMULT & 0xffff);
- hh = hi * (IL_RMULT >> 16);
- result = ((ll + 12345) >> 16) + lh + hl + (hh << 16);
- result &= ~(-2147483647);
- if (max != 0)
- result %= (max - min);
- return result + min;
- }
- void srandom(unsigned int seed)
- {
- simplex_seed = seed;
- }
- int core_random(long long int max, int min = 0)
- {
- int result = nrandom(max);
- simplex_seed = simplex_seed * 1103515245 + 12345;
- return result;
- }
- void CALLBACK cmd_rnd(std::string param)
- {
- char buf[128];
- sprintf(buf, "script random: %d", core_random(10) + 2);
- SF->getSAMP()->getChat()->AddChatMessage(-1, buf);
- };
- void CALLBACK mainloop()
- {
- static bool init = false;
- if (!init)
- {
- if (GAME == nullptr)
- return;
- if (GAME->GetSystemState() != eSystemState::GS_PLAYING_GAME)
- return;
- if (!SF->getSAMP()->IsInitialized())
- return;
- SF->getSAMP()->getChat()->AddChatMessage( D3DCOLOR_XRGB( 0, 0xAA, 0 ), "mac test" );
- SF->getSAMP()->registerChatCommand("random1", cmd_rnd);
- init = true;
- }
- }
- BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReasonForCall, LPVOID lpReserved)
- {
- switch (dwReasonForCall)
- {
- case DLL_PROCESS_ATTACH:
- SF->initPlugin(mainloop, hModule);
- break;
- case DLL_THREAD_ATTACH:
- case DLL_THREAD_DETACH:
- case DLL_PROCESS_DETACH:
- break;
- }
- return TRUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement