Guest User

s

a guest
Apr 28th, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Credits to Y_Less, Dracoblue and Kush.
  2.  
  3. #include <a_samp>
  4. #include <YSI\y_ini>
  5. #include <sscanf2>
  6. #include <pvehicle>
  7.  
  8. #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  9.  
  10. #define DIALOG_REGISTER 1
  11. #define DIALOG_LOGIN 2
  12. #define DIALOG_SUCCESS_1 3
  13. #define DIALOG_SUCCESS_2 4
  14. #define DIALOG_ADVEHICLES 5
  15.  
  16. #define PATH "/Users/%s.ini"
  17.  
  18. #define COL_WHITE "{FFFFFF}"
  19. #define COL_RED "{F81414}"
  20. #define COL_GREEN "{00FF22}"
  21. #define COL_LIGHTBLUE "{00CED1}"
  22.  
  23. enum pInfo
  24. {
  25.     pPass,
  26.     pCash,
  27.     pAdmin,
  28.     pKills,
  29.     pDeaths
  30. }
  31. new PlayerInfo[MAX_PLAYERS][pInfo];
  32.  
  33. forward LoadUser_data(playerid,name[],value[]);
  34. public LoadUser_data(playerid,name[],value[])
  35. {
  36.     INI_Int("Password",PlayerInfo[playerid][pPass]);
  37.     INI_Int("Cash",PlayerInfo[playerid][pCash]);
  38.     INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
  39.     INI_Int("Kills",PlayerInfo[playerid][pKills]);
  40.     INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
  41.     return 1;
  42. }
  43.  
  44. stock UserPath(playerid)
  45. {
  46.     new string[128],playername[MAX_PLAYER_NAME];
  47.     GetPlayerName(playerid,playername,sizeof(playername));
  48.     format(string,sizeof(string),PATH,playername);
  49.     return string;
  50. }
  51.  
  52. /*Credits to Dracoblue*/
  53. stock udb_hash(buf[])
  54.     new length=strlen(buf);
  55.     new s1 = 1;
  56.     new s2 = 0;
  57.     new n;
  58.     for (n=0; n<length; n++)
  59.     {
  60.        s1 = (s1 + buf[n]) % 65521;
  61.        s2 = (s2 + s1)     % 65521;
  62.     }
  63.     return (s2 << 16) + s1;
  64. }
  65.  
  66. main()
  67. {
  68.         print("\n----------------------------------");
  69.         print(" Blank Gamemode by your name here");
  70.         print("----------------------------------\n");
  71. }
  72.  
  73. public OnGameModeInit()
  74. {
  75.         SetGameModeText("World War lll");
  76.         return 1;
  77. }
  78.  
  79. public OnGameModeExit()
  80. {
  81.         return 1;
  82. }
  83.  
  84. public OnPlayerRequestClass(playerid, classid)
  85. {
  86.         return 1;
  87. }
  88.  
  89. public OnPlayerConnect(playerid)
  90. {
  91.     if(fexist(UserPath(playerid)))
  92.     {
  93.         INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  94.         ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_WHITE"Type your password below to login.","Login","Quit");
  95.     }
  96.     else
  97.     {
  98.         ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT,""COL_WHITE"Registering...",""COL_WHITE"Type your password below to register a new account.","Register","Quit");
  99.     }
  100.     return 1;
  101. }
  102.  
  103. public OnPlayerDisconnect(playerid, reason)
  104. {
  105.     new INI:File = INI_Open(UserPath(playerid));
  106.     INI_SetTag(File,"data");
  107.     INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
  108.     INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
  109.     INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
  110.     INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
  111.     INI_Close(File);
  112.     return 1;
  113. }
  114.  
  115. public OnPlayerSpawn(playerid)
  116. {
  117.         return 1;
  118. }
  119.  
  120. public OnPlayerDeath(playerid, killerid, reason)
  121. {
  122.     PlayerInfo[killerid][pKills]++;
  123.     PlayerInfo[playerid][pDeaths]++;
  124.     return 1;
  125. }
  126.  
  127. public OnVehicleSpawn(vehicleid)
  128. {
  129.         return 1;
  130. }
  131.  
  132. public OnVehicleDeath(vehicleid, killerid)
  133. {
  134.         return 1;
  135. }
  136.  
  137. public OnPlayerText(playerid, text[])
  138. {
  139.         return 1;
  140. }
  141.  
  142. public OnPlayerCommandText(playerid, cmdtext[])
  143. {
  144.     //Admin Commands
  145.     dcmd(sethealth, 9, cmdtext);
  146.     dcmd(kick, 4, cmdtext);
  147.     dcmd(advehicles, 10, cmdtext);
  148.     return 0;
  149. }
  150.  
  151. dcmd_sethealth(playerid, params[])
  152. {
  153.     if(PlayerInfo[playerid][pAdmin] == 4 || IsPlayerAdmin(playerid)) // IsPlayerAdmin check (we want only RCON admins to use this command (error message at bottom if the player isn't logged into RCON)
  154.     {
  155.         new id, Float:amount, string[70], pName[MAX_PLAYER_NAME]; // Create the variables needed for this command. id = the id we want to set the health of, amount = the amount we're gonna set id's health to and pName is just where we store id's name.
  156.         if(sscanf(params, "uf", id, amount)) return SendClientMessage(playerid, 0xFF0000AA, "Usage: /sethealth (id) (amount)");
  157.        
  158.         if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000AA, "This player is not connected."); // ID is not connected, send an error message
  159.             else
  160.         {
  161.             GetPlayerName(id, pName, MAX_PLAYER_NAME);
  162.             SetPlayerHealth(id, amount);
  163.             format(string, sizeof(string), "You've Set %s's (%d) Health To %d.", pName, id, amount);
  164.             SendClientMessage(playerid, 0x00FF00AA, string);
  165.             return 1;
  166.         }
  167.     }
  168.     else SendClientMessage(playerid, 0xFF0000FF, "ERROR: You need to be Level 4 to use this command.");
  169.     return 1;
  170. }
  171.  
  172. dcmd_kick(playerid, params[])
  173. {
  174.     if(PlayerInfo[playerid][pAdmin] == 4 || IsPlayerAdmin(playerid))
  175.     {
  176.         new id;
  177.         new reason[64];
  178.         new idName[MAX_PLAYER_NAME];
  179.         new playeridName[MAX_PLAYER_NAME];
  180.         if(sscanf(params,"uz", id, reason)) SendClientMessage(playerid, 0xFF0000FF, "Usage: /kick (id) (reason)");
  181.         else if (id == INVALID_PLAYER_ID) SendClientMessage(playerid, 0xFF0000FF, "ERROR: Player not found");
  182.         else
  183.         {
  184.             GetPlayerName(id, idName, MAX_PLAYER_NAME);
  185.             GetPlayerName(playerid, playeridName, MAX_PLAYER_NAME);
  186.             SendClientMessage(id, 0xFF0000FF, "You have been kicked by Administrator %s. Reason: %s", playeridName, reason);
  187.             Kick(id);
  188.             SendClientMessage(playerid, 0xFF0000FF, "You have succesfully kicked %s for reason: %s", idName, reason);
  189.             return 1;
  190.         }
  191.     }
  192.     else SendClientMessage(playerid, 0xFF0000FF, "ERROR: You need to be Level 4 to use this command.");
  193.     return 1;
  194. }
  195.  
  196. dcmd_advehicles(playerid)
  197. {
  198.     if(PlayerInfo[playerid][pAdmin] == 2 || IsPlayerAdmin(playerid))
  199.     {
  200.         ShowPlayerDialog(playerid, DIALOG_ADVEHICLES, DIALOG_STYLE_LIST, "Admin Vehicles", "Rhino\nHydra\nPatriot\nHunter\nMaverick\nS.W.A.T. Van\nBarracks\nFiretruck", "Spawn", "Cancel");
  201.     }
  202.     else SendClientMessage(playerid, 0xFF0000FF, "ERROR: You need to be Level 2 to use this command");
  203.     return 1;
  204. }
  205.  
  206.        
  207.  
  208. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  209. {
  210.         return 1;
  211. }
  212.  
  213. public OnPlayerExitVehicle(playerid, vehicleid)
  214. {
  215.         return 1;
  216. }
  217.  
  218. public OnPlayerStateChange(playerid, newstate, oldstate)
  219. {
  220.         return 1;
  221. }
  222.  
  223. public OnPlayerEnterCheckpoint(playerid)
  224. {
  225.         return 1;
  226. }
  227.  
  228. public OnPlayerLeaveCheckpoint(playerid)
  229. {
  230.         return 1;
  231. }
  232.  
  233. public OnPlayerEnterRaceCheckpoint(playerid)
  234. {
  235.         return 1;
  236. }
  237.  
  238. public OnPlayerLeaveRaceCheckpoint(playerid)
  239. {
  240.         return 1;
  241. }
  242.  
  243. public OnRconCommand(cmd[])
  244. {
  245.         return 1;
  246. }
  247.  
  248. public OnPlayerRequestSpawn(playerid)
  249. {
  250.         return 1;
  251. }
  252.  
  253. public OnObjectMoved(objectid)
  254. {
  255.         return 1;
  256. }
  257.  
  258. public OnPlayerObjectMoved(playerid, objectid)
  259. {
  260.         return 1;
  261. }
  262.  
  263. public OnPlayerPickUpPickup(playerid, pickupid)
  264. {
  265.         return 1;
  266. }
  267.  
  268. public OnVehicleMod(playerid, vehicleid, componentid)
  269. {
  270.         return 1;
  271. }
  272.  
  273. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  274. {
  275.         return 1;
  276. }
  277.  
  278. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  279. {
  280.         return 1;
  281. }
  282.  
  283. public OnPlayerSelectedMenuRow(playerid, row)
  284. {
  285.         return 1;
  286. }
  287.  
  288. public OnPlayerExitedMenu(playerid)
  289. {
  290.         return 1;
  291. }
  292.  
  293. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  294. {
  295.         return 1;
  296. }
  297.  
  298. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  299. {
  300.         return 1;
  301. }
  302.  
  303. public OnRconLoginAttempt(ip[], password[], success)
  304. {
  305.         return 1;
  306. }
  307.  
  308. public OnPlayerUpdate(playerid)
  309. {
  310.         return 1;
  311. }
  312.  
  313. public OnPlayerStreamIn(playerid, forplayerid)
  314. {
  315.         return 1;
  316. }
  317.  
  318. public OnPlayerStreamOut(playerid, forplayerid)
  319. {
  320.         return 1;
  321. }
  322.  
  323. public OnVehicleStreamIn(vehicleid, forplayerid)
  324. {
  325.         return 1;
  326. }
  327.  
  328. public OnVehicleStreamOut(vehicleid, forplayerid)
  329. {
  330.         return 1;
  331. }
  332.  
  333. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  334. {
  335.     switch( dialogid )
  336.     {
  337.         case DIALOG_REGISTER:
  338.         {
  339.             if (!response) return Kick(playerid);
  340.             if(response)
  341.             {
  342.                 if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, ""COL_WHITE"Registering...",""COL_RED"You have entered an invalid password.\n"COL_WHITE"Type your password below to register a new account.","Register","Quit");
  343.                 new INI:File = INI_Open(UserPath(playerid));
  344.                 INI_SetTag(File,"data");
  345.                 INI_WriteInt(File,"Password",udb_hash(inputtext));
  346.                 INI_WriteInt(File,"Cash",0);
  347.                 INI_WriteInt(File,"Admin",0);
  348.                 INI_WriteInt(File,"Kills",0);
  349.                 INI_WriteInt(File,"Deaths",0);
  350.                 INI_Close(File);
  351.  
  352.                 SetSpawnInfo(playerid, 0, 0, 1958.33, 1343.12, 15.36, 269.15, 0, 0, 0, 0, 0, 0);
  353.                 SpawnPlayer(playerid);
  354.                 ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"Great! Your Y_INI system works perfectly. Relog to save your stats!","Ok","");
  355.                         }
  356.         }
  357.         case DIALOG_LOGIN:
  358.         {
  359.             if ( !response ) return Kick ( playerid );
  360.             if( response )
  361.             {
  362.                 if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
  363.                 {
  364.                     INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  365.                     GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
  366.                     ShowPlayerDialog(playerid, DIALOG_SUCCESS_2, DIALOG_STYLE_MSGBOX,""COL_WHITE"Success!",""COL_GREEN"You have successfully logged in!","Ok","");
  367.                 }
  368.                 else
  369.                 {
  370.                     ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""COL_WHITE"Login",""COL_RED"You have entered an incorrect password.\n"COL_WHITE"Type your password below to login.","Login","Quit");
  371.                 }
  372.                 return 1;
  373.             }
  374.         }
  375.         case DIALOG_ADVEHICLES:
  376.         {
  377.             if(response)
  378.             {
  379.             switch(listitem)
  380.             {
  381.                 case 0:
  382.                 {
  383.                     CreateVehicleForPlayer(playerid, "432", -1, -1, 1000);
  384.                 }
  385.                 case 1:
  386.                 {
  387.                     CreateVehicleForPlayer(playerid, "520", -1, -1, 1000);
  388.                 }
  389.                 case 2:
  390.                 {
  391.                     CreateVehicleForPlayer(playerid, "470", -1, -1, 1000);
  392.                 }
  393.                 case 3:
  394.                 {
  395.                     CreateVehicleForPlayer(playerid, "425", -1, -1, 1000);
  396.                 }
  397.                 case 4:
  398.                 {
  399.                     CreateVehicleForPlayer(playerid, "487", -1, -1, 1000);
  400.                 }
  401.                 case 5:
  402.                 {
  403.                     CreateVehicleForPlayer(playerid, "601", -1, -1, 1000);
  404.                 }
  405.                 case 6:
  406.                 {
  407.                     CreateVehicleForPlayer(playerid, "433", -1, -1, 1000);
  408.                 }
  409.                 case 7:
  410.                 {
  411.                     CreateVehicleForPlayer(playerid, "407", -1, -1, 1000);
  412.                 }
  413.             }
  414.         }
  415.         else
  416.         {
  417.             SendClientMessage(playerid, 0xFF0000FF, "You have cancelled!");
  418.             switch(listitem)
  419.             {
  420.                 case 0:
  421.                 {
  422.                     //Selected Item: "Rhino"
  423.                 }
  424.                 case 1:
  425.                 {
  426.                     //Selected Item: "Hydra"
  427.                 }
  428.                 case 2:
  429.                 {
  430.                     //Selected Item: "Patriot"
  431.                 }
  432.                 case 3:
  433.                 {
  434.                     //Selected Item: "Hunter"
  435.                 }
  436.                 case 4:
  437.                 {
  438.                     //Selected Item: "Maverick"
  439.                 }
  440.                 case 5:
  441.                 {
  442.                     //Selected Item: "S.W.A.T. Van"
  443.                 }
  444.                 case 6:
  445.                 {
  446.                     //Selected Item: "Barracks"
  447.                 }
  448.                 case 7:
  449.                 {
  450.                     //Selected Item: "Firetruck"
  451.                 }
  452.             }
  453.         }
  454.     }
  455.     return 1;
  456. }
  457.  
  458. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  459. {
  460.         return 1;
  461. }
Advertisement
Add Comment
Please, Sign In to add comment