Guest User

King_Hual Exp Sys Vol.2

a guest
Oct 19th, 2011
2,503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 13.79 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dudb>
  3. #include <progress>
  4.  
  5. new Text:ExpText[MAX_PLAYERS];
  6. new Text:LevelText[MAX_PLAYERS];
  7. new Bar:bar[MAX_PLAYERS];
  8. new Text3D:LevelLabel[MAX_PLAYERS];
  9.  
  10. //You can change these values.
  11. #define ExpForLevel 1000 //How much exp you need to pass a level. The Exp gets multiplied by the level. If you've got 1000 total exp then for lvl 2 it will be 2000
  12. #define MaxLevel 99 //The maximum level a player can achieve.
  13. #define UseProgBar // Define wheater to use the progress bar or not. Comment the line if you don't want a progress bar and leave like that if you do want a progress bar.
  14. #define ProgBarColor 0x0000FFFF //The experience bar's color.
  15. #define TextLabelColor 0x00FFFFFF // The textlabel's color.
  16. #define CashForLevelUp 300 //This is the cash you get for levelling up. It gets multiplied by the level you achieved and one more time by a number you define.
  17. #define CashMultiplier 1 //This multiplies the Cash * Level achieved by the number you want.
  18. #define GameTextStyle 4 //This defines the GameText's style used for the GivePlayerExp function.
  19. #define GameTextTime 3000 //This defines the time for which the GameText for the GivePlayerExp function will be visible
  20.  
  21. //Don't change these values.
  22. #define mustlogin
  23. #define autologin
  24.  
  25. #pragma unused strtok
  26. #pragma unused ret_memcpy
  27.  
  28. //Declaring New
  29. new logged_in[MAX_PLAYERS];
  30. new Retries[MAX_PLAYERS];
  31.  
  32. //The function which gives exp. Usage: GivePlayerExp(playerid, ammount, reason);
  33. stock GivePlayerExp(playerid, exp, reason[])
  34. {
  35.     new pfile[100], pname[MAX_PLAYER_NAME], string2[126], string3[126], string4[126];
  36.     GetPlayerName(playerid, pname, sizeof(pname));
  37.     format(pfile, sizeof(pfile), "HAccounts/%s.ini",pname);
  38.     dini_IntSet(pfile, "Exp", dini_Int(pfile, "Exp") +exp);
  39.     if (dini_Int(pfile, "Exp") >= dini_Int(pfile, "TotalExp"))
  40.     {
  41.         if (dini_Int(pfile, "ExpLevel") < MaxLevel)
  42.         {
  43.             while (dini_Int(pfile, "Exp") >= dini_Int(pfile, "TotalExp"))
  44.             {
  45.                 dini_IntSet(pfile, "Exp", dini_Int(pfile, "Exp") - dini_Int(pfile, "TotalExp"));
  46.                 dini_IntSet(pfile, "ExpLevel", dini_Int(pfile, "ExpLevel") + 1);
  47.                 dini_IntSet(pfile, "TotalExp", dini_Int(pfile, "ExpLevel") * ExpForLevel);
  48.                 format(string3, sizeof(string3), "Level: %02d",dini_Int(pfile, "ExpLevel"));
  49.                 TextDrawSetString(LevelText[playerid], string3);
  50.                 GivePlayerMoney(playerid, CashForLevelUp * dini_Int(pfile, "ExpLevel") * CashMultiplier);
  51.                 format(string4, sizeof(string4), "~p~You got %d Exp for ~n~%s !~n~~g~Level up!", exp, reason);
  52.             }
  53.         }
  54.         else
  55.         {
  56.             GameTextForPlayer(playerid, "~g~Max Level Reached!", GameTextTime, GameTextStyle);
  57.             dini_IntSet(pfile, "Exp", dini_Int(pfile, "TotalExp"));
  58.         }
  59.     }
  60.     else
  61.     {
  62.         format(string4, sizeof(string4), "~p~You got %d Exp for ~n~%s !", exp, reason);
  63.     }
  64.     format(string2, sizeof(string2), "Exp: %05d/%05d",dini_Int(pfile, "Exp"), dini_Int(pfile, "TotalExp"));
  65.     TextDrawSetString(ExpText[playerid], string2);
  66.     #if defined UseProgBar
  67.     SetProgressBarValue(bar[playerid], dini_Int(pfile, "Exp"));
  68.     SetProgressBarMaxValue(bar[playerid], dini_Int(pfile, "TotalExp"));
  69.     UpdateProgressBar(bar[playerid], playerid);
  70.     #endif
  71.     GameTextForPlayer(playerid, string4, GameTextTime, GameTextStyle);
  72.     format(string3, sizeof(string3), "Level: %02d",dini_Int(pfile, "ExpLevel"));
  73.     Update3DTextLabelText(LevelLabel[playerid], TextLabelColor, string3);
  74. }
  75.  
  76. //The function to get a player's level. Usage: GetPlayerLevel(playerid)
  77. stock GetPlayerExpLevel(playerid)
  78. {
  79.     new pfile[100], pname[MAX_PLAYER_NAME], Plevel;
  80.     GetPlayerName(playerid, pname, sizeof(pname));
  81.     format(pfile, sizeof(pfile), "HAccounts/%s.ini",pname);
  82.     Plevel = dini_Int(pfile, "ExpLevel");
  83.     return Plevel;
  84. }
  85.  
  86. //The function to get a player's experience. Usage: GetPlayerExp(playerid)
  87. stock GetPlayerExp(playerid)
  88. {
  89.     new pfile[100], pname[MAX_PLAYER_NAME], PExp;
  90.     GetPlayerName(playerid, pname, sizeof(pname));
  91.     format(pfile, sizeof(pfile), "HAccounts/%s.ini",pname);
  92.     PExp = dini_Int(pfile, "Exp");
  93.     return PExp;
  94. }
  95.  
  96. //The function to get a player's experience needed to lvl up. Usage: GetPlayerTotalExp(playerid)
  97. stock GetPlayerTotalExp(playerid)
  98. {
  99.     new pfile[100], pname[MAX_PLAYER_NAME], PTotalExp;
  100.     GetPlayerName(playerid, pname, sizeof(pname));
  101.     format(pfile, sizeof(pfile), "HAccounts/%s.ini",pname);
  102.     PTotalExp = dini_Int(pfile, "TotalExp");
  103.     return PTotalExp;
  104. }
  105.  
  106. public OnFilterScriptInit()
  107. {
  108.     print("\n--------------------------------------");
  109.     print(" King_Hual's Experience & Simple Account System Filterscript.");
  110.     print("--------------------------------------\n");
  111.     return 1;
  112. }
  113.  
  114. public OnFilterScriptExit()
  115. {
  116.     return 1;
  117. }
  118.  
  119. public OnPlayerRequestClass(playerid, classid)
  120. {
  121.     SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
  122.     SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
  123.     SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
  124.     return 1;
  125. }
  126.  
  127. public OnPlayerConnect(playerid)
  128. {
  129.     new pname[MAX_PLAYER_NAME],string2[126], string3[126];
  130.     Retries[playerid] = 0;
  131.     SendDeathMessage(INVALID_PLAYER_ID, playerid, 200);
  132.     new pfile[100];
  133.     GetPlayerName(playerid, pname, sizeof(pname));
  134.     format(pfile, sizeof(pfile), "HAccounts/%s.ini",pname);
  135.     if (!dini_Exists(pfile))
  136.     {
  137.     ShowPlayerDialog(playerid,101,DIALOG_STYLE_INPUT,"Registration","Please enter a password to register this account!","Register","Cancel");
  138.     }
  139.     else if (dini_Exists(pfile)) ShowPlayerDialog(playerid,100,DIALOG_STYLE_INPUT,"Login","Please enter a password to login to this account!","Login","Cancel");
  140.     #if defined UseProgBar
  141.     bar[playerid] = CreateProgressBar(500.00, 5.00, 137.50, 15.19, ProgBarColor, 100.0);
  142.     #endif
  143.     format(string2, sizeof(string2), "Exp: %05d/%05d",dini_Int(pfile, "Exp"), dini_Int(pfile, "TotalExp"));
  144.     format(string3, sizeof(string3), "Level: %02d",dini_Int(pfile, "ExpLevel"));
  145.     ExpText[playerid] = TextDrawCreate(500.000000,3.000000,string2);
  146.     TextDrawAlignment(ExpText[playerid],0);
  147.     TextDrawBackgroundColor(ExpText[playerid],0x000000ff);
  148.     TextDrawFont(ExpText[playerid],1);
  149.     TextDrawLetterSize(ExpText[playerid],0.399999,1.800000);
  150.     TextDrawColor(ExpText[playerid],0xffff00ff);
  151.     TextDrawSetOutline(ExpText[playerid],1);
  152.     TextDrawSetProportional(ExpText[playerid],1);
  153.  
  154.     LevelText[playerid] = TextDrawCreate(546.000000,25.000000,string3);
  155.     TextDrawAlignment(LevelText[playerid],0);
  156.     TextDrawBackgroundColor(LevelText[playerid],0x000000ff);
  157.     TextDrawFont(LevelText[playerid],2);
  158.     TextDrawLetterSize(LevelText[playerid],0.299999,1.400000);
  159.     TextDrawColor(LevelText[playerid],0x00ff0099);
  160.     TextDrawSetOutline(LevelText[playerid],1);
  161.     TextDrawSetProportional(LevelText[playerid],1);
  162.     TextDrawSetShadow(LevelText[playerid],1);
  163.     return 1;
  164. }
  165.  
  166. public OnPlayerDisconnect(playerid, reason)
  167. {
  168.     TextDrawDestroy(ExpText[playerid]);
  169.     TextDrawDestroy(ExpText[playerid]);
  170.     #if defined UseProgBar
  171.     DestroyProgressBar(bar[playerid]);
  172.     #endif
  173.     Delete3DTextLabel(LevelLabel[playerid]);
  174.     Retries[playerid] = 0;
  175.     if(logged_in[playerid] == 1)
  176.     {
  177.     new pfile[100], pname[MAX_PLAYER_NAME];
  178.     GetPlayerName(playerid, pname, sizeof(pname));
  179.     format(pfile, sizeof(pfile), "HAccounts/%s.ini",pname);
  180.     dini_IntSet(pfile, "Cash", GetPlayerMoney(playerid));
  181.     dini_IntSet(pfile, "Score", GetPlayerScore(playerid));
  182.     }
  183.     logged_in[playerid] = 0;
  184.     SendDeathMessage(INVALID_PLAYER_ID, playerid, 201);
  185.     return 1;
  186. }
  187.  
  188. public OnPlayerSpawn(playerid)
  189. {
  190.     GivePlayerWeapon(playerid, 24, 500);
  191.     return 1;
  192. }
  193.  
  194. public OnPlayerDeath(playerid, killerid, reason)
  195. {
  196.     if (killerid != playerid) {
  197.         if (GetPlayerExpLevel(playerid) < GetPlayerExpLevel(killerid))
  198.         {
  199.             GivePlayerExp(killerid, 100, "killing a lower level player");
  200.         }
  201.         else if (GetPlayerExpLevel(playerid) > GetPlayerExpLevel(killerid))
  202.         {
  203.             GivePlayerExp(killerid, 300, "killing a higher level player");
  204.         }
  205.         else
  206.         {
  207.             GivePlayerExp(killerid, 200, "killing a player at your own level");
  208.         }
  209.     } // An example of using my exp system.
  210.     return 1;
  211. }
  212.  
  213. public OnVehicleSpawn(vehicleid)
  214. {
  215.     return 1;
  216. }
  217.  
  218. public OnVehicleDeath(vehicleid, killerid)
  219. {
  220.     return 1;
  221. }
  222.  
  223. public OnPlayerText(playerid, text[])
  224. {
  225.     return 1;
  226. }
  227.  
  228. public OnPlayerCommandText(playerid, cmdtext[])
  229. {
  230.     if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  231.     {
  232.         // Do something here
  233.         return 1;
  234.     }
  235.     return 0;
  236. }
  237.  
  238. public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
  239. {
  240.     return 1;
  241. }
  242.  
  243. public OnPlayerExitVehicle(playerid, vehicleid)
  244. {
  245.     return 1;
  246. }
  247.  
  248. public OnPlayerStateChange(playerid, newstate, oldstate)
  249. {
  250.     return 1;
  251. }
  252.  
  253. public OnPlayerEnterCheckpoint(playerid)
  254. {
  255.     return 1;
  256. }
  257.  
  258. public OnPlayerLeaveCheckpoint(playerid)
  259. {
  260.     return 1;
  261. }
  262.  
  263. public OnPlayerEnterRaceCheckpoint(playerid)
  264. {
  265.     return 1;
  266. }
  267.  
  268. public OnPlayerLeaveRaceCheckpoint(playerid)
  269. {
  270.     return 1;
  271. }
  272.  
  273. public OnRconCommand(cmd[])
  274. {
  275.     return 1;
  276. }
  277.  
  278. public OnPlayerRequestSpawn(playerid)
  279. {
  280.     if (logged_in[playerid] == 0)
  281.     {
  282.         SendClientMessage(playerid, 0xFF00FFFF, "*You need to login to spawn.*");
  283.         return 0;
  284.     }
  285.     else
  286.     {
  287.         return 1;
  288.     }
  289. }
  290.  
  291. public OnObjectMoved(objectid)
  292. {
  293.     return 1;
  294. }
  295.  
  296. public OnPlayerObjectMoved(playerid, objectid)
  297. {
  298.     return 1;
  299. }
  300.  
  301. public OnPlayerPickUpPickup(playerid, pickupid)
  302. {
  303.     return 1;
  304. }
  305.  
  306. public OnVehicleMod(playerid, vehicleid, componentid)
  307. {
  308.     return 1;
  309. }
  310.  
  311. public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
  312. {
  313.     return 1;
  314. }
  315.  
  316. public OnVehicleRespray(playerid, vehicleid, color1, color2)
  317. {
  318.     return 1;
  319. }
  320.  
  321. public OnPlayerSelectedMenuRow(playerid, row)
  322. {
  323.     return 1;
  324. }
  325.  
  326. public OnPlayerExitedMenu(playerid)
  327. {
  328.     return 1;
  329. }
  330.  
  331. public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
  332. {
  333.     return 1;
  334. }
  335.  
  336. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  337. {
  338.     return 1;
  339. }
  340.  
  341. public OnRconLoginAttempt(ip[], password[], success)
  342. {
  343.     return 1;
  344. }
  345.  
  346. public OnPlayerUpdate(playerid)
  347. {
  348.     return 1;
  349. }
  350.  
  351. public OnPlayerStreamIn(playerid, forplayerid)
  352. {
  353.     return 1;
  354. }
  355.  
  356. public OnPlayerStreamOut(playerid, forplayerid)
  357. {
  358.     return 1;
  359. }
  360.  
  361. public OnVehicleStreamIn(vehicleid, forplayerid)
  362. {
  363.     return 1;
  364. }
  365.  
  366. public OnVehicleStreamOut(vehicleid, forplayerid)
  367. {
  368.     return 1;
  369. }
  370.  
  371. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  372. {
  373.         if(dialogid == 101)
  374.         {
  375.         if(!strlen(inputtext) || !response) return ShowPlayerDialog(playerid,101,DIALOG_STYLE_INPUT,"Registration","ERROR: You did not enter a password.\nPlease enter a password to register this account!","Register","Cancel");
  376.         new pfile[128], pname[MAX_PLAYER_NAME], string2[64], string3[32];
  377.         GetPlayerName(playerid, pname, sizeof(pname));
  378.         format(pfile, sizeof(pfile), "HAccounts/%s.ini",pname);
  379.         new playerip[20];
  380.         GetPlayerIp(playerid, playerip, sizeof(playerip));
  381.         dini_Create(pfile);
  382.         dini_IntSet(pfile, "Password", udb_hash(inputtext));
  383.         dini_Set(pfile, "Ip", playerip);
  384.         dini_IntSet(pfile, "Cash", 0);
  385.         dini_IntSet(pfile, "ExpLevel", 1);
  386.         dini_IntSet(pfile, "Exp", 0);
  387.         dini_IntSet(pfile, "TotalExp", ExpForLevel);
  388.         dini_IntSet(pfile, "Score", 0);
  389.         logged_in[playerid] = 1;
  390.         SendClientMessage(playerid, 0x00FF00FF, "*You have been registered! You have also been logged in!*");
  391.         format(string2, sizeof(string2), "Exp: %05d/%05d",dini_Int(pfile, "Exp"), dini_Int(pfile, "TotalExp"));
  392.         TextDrawSetString(ExpText[playerid], string2);
  393.         format(string3, sizeof(string3), "Level: %02d",dini_Int(pfile, "ExpLevel"));
  394.         TextDrawSetString(LevelText[playerid], string3);
  395.         TextDrawShowForPlayer(playerid, ExpText[playerid]);
  396.         TextDrawShowForPlayer(playerid, LevelText[playerid]);
  397.         #if defined UseProgBar
  398.         ShowProgressBarForPlayer(playerid, bar[playerid]);
  399.         SetProgressBarMaxValue(bar[playerid], dini_Int(pfile, "TotalExp"));
  400.         SetProgressBarValue(bar[playerid], dini_Int(pfile, "Exp"));
  401.         UpdateProgressBar(bar[playerid], playerid);
  402.         #endif
  403.         LevelLabel[playerid] = Create3DTextLabel(string3, TextLabelColor, 0, 0, 0, 50, 0);
  404.         Attach3DTextLabelToPlayer(LevelLabel[playerid], playerid, 0, 0, 0.7);
  405.         }
  406.         if(dialogid == 100)
  407.         {
  408.             if(!strlen(inputtext) || !response) return ShowPlayerDialog(playerid,100,DIALOG_STYLE_INPUT,"Login","ERROR: You did not enter a password.\nPlease enter a password to login to this account!","Login","Cancel");
  409.             new pfile[100], pname[MAX_PLAYER_NAME];
  410.             GetPlayerName(playerid, pname, sizeof(pname));
  411.             format(pfile, sizeof(pfile), "HAccounts/%s.ini",pname);
  412.             new tmp[256];
  413.             tmp = dini_Get(pfile, "Password");
  414.             if(udb_hash(inputtext) == strval(tmp))
  415.             {
  416.                 new playerip[20], string[32];
  417.                 GetPlayerIp(playerid, playerip, sizeof(playerip));
  418.                 dini_Set(pfile, "Ip", playerip);
  419.                 GivePlayerMoney(playerid, dini_Int(pfile, "Cash"));
  420.                 SetPlayerScore(playerid, dini_Int(pfile, "Score"));
  421.                 logged_in[playerid] = 1;
  422.                 SendClientMessage(playerid, 0x00FF00FF, "*You have been logged in!*");
  423.                 TextDrawShowForPlayer(playerid, ExpText[playerid]);
  424.                 TextDrawShowForPlayer(playerid, LevelText[playerid]);
  425.                 #if defined UseProgBar
  426.                 SetProgressBarValue(bar[playerid], dini_Int(pfile, "Exp"));
  427.                 SetProgressBarMaxValue(bar[playerid], dini_Int(pfile, "TotalExp"));
  428.                 UpdateProgressBar(bar[playerid], playerid);
  429.                 #endif
  430.                 format(string, sizeof(string), "Level: %02d",dini_Int(pfile, "ExpLevel"));
  431.                 LevelLabel[playerid] = Create3DTextLabel(string, TextLabelColor, 0, 0, 0, 50, 0);
  432.                 Attach3DTextLabelToPlayer(LevelLabel[playerid], playerid, 0, 0, 0.7);
  433.             }
  434.             else
  435.             {
  436.                 ShowPlayerDialog(playerid,100,DIALOG_STYLE_INPUT,"Login","ERROR: Invalid Password.\nPlease enter a password to login to this account!","Login","Cancel");
  437.                 Retries[playerid]++;
  438.                 if (Retries[playerid] == 5)
  439.                 {
  440.                     SendClientMessage(playerid, 0xFF0000, "*You have been kicked for 5 incorrect password inputs.*");
  441.                     Kick(playerid);
  442.                 }
  443.             }
  444.         }
  445.         return 1;
  446. }
  447.  
  448. public OnPlayerClickPlayer(playerid, clickedplayerid, source)
  449. {
  450.     return 1;
  451. }
  452.  
Advertisement
Add Comment
Please, Sign In to add comment