Guest User

King_Hual Exp Sys

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