JaQQeri

Simple job system

Dec 13th, 2011
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 5.72 KB | None | 0 0
  1. //Job system for stuoyto
  2. //Made by Jakku
  3. //(C) Copyright 2011
  4.  
  5. #include <a_samp>
  6. #include <Dini>
  7.  
  8.  
  9. #define MAX_JOBS 10
  10.  
  11. #define COLOR_ORANGE 0xFF9900AA
  12. #define COLOR_ORED 0xFF0000FF
  13.  
  14.  
  15. forward PayDay();
  16.  
  17. #define WLCM "This server is using the simple Job system by Jakku"
  18.  
  19. new PJob[MAX_PLAYERS];
  20.  
  21.  
  22. enum Jobs
  23. {
  24. Name[28],
  25. Skin,
  26. AdminOnly,
  27. Vehicles[5],
  28. };
  29.  
  30. new Job[MAX_JOBS][Jobs];
  31. new JobCount;
  32.  
  33.  
  34.  
  35. public PayDay()
  36. {
  37.     for (new i=0;i<MAX_PLAYERS;i++)
  38.     {
  39.         if (IsPlayerConnected(i))
  40.         {
  41.             if (PJob[i] > 0)
  42.             {
  43.             new PAY = 300;
  44.             new string[80];
  45.             format(string,sizeof(string),"You have earned from your job ($%d)", PAY);
  46.             SendClientMessage(i, COLOR_ORANGE,string);
  47.             GivePlayerMoney(i, PAY);
  48.             }
  49.         }
  50.     }
  51. }
  52.  
  53. public OnFilterScriptInit()
  54. {
  55.     print("\n--------------------------------------");
  56.     print("== Jobs Filterscript for stuoyto coded by Jakku (C) 2011 ==");
  57.     print("== Loaded successfully ==");
  58.     print("--------------------------------------\n");
  59.    
  60.    
  61.     //Initialize jobs
  62.    
  63.     //Syntax: CreateJob("jobname",skin_id,admins_only);
  64.    
  65.    
  66.     CreateJob("Police", 282,1); //Change the skin IDs, I just threw something in :P
  67.     CreateJob("Mechanic", 45,0);
  68.     CreateJob("Cardealer", 42,0);
  69.     CreateJob("Taxidriver", 42,0);
  70.     CreateJob("Busdriver", 42,0);
  71.     CreateJob("Army", 42,0);
  72.     CreateJob("Lawyer", 42,0);
  73.     CreateJob("Gundealer", 42,0);
  74.     CreateJob("Bodyguard", 42,0);
  75.    
  76.     SetTimer("PayDay",1800000,1);
  77.  
  78.     return 1;
  79. }
  80.  
  81. public OnFilterScriptExit()
  82. {
  83.     print("Thank you for using the Job system by Jakku. (C) 2011");
  84.     return 1;
  85. }
  86.  
  87.  
  88.  
  89. public OnPlayerConnect(playerid)
  90. {
  91.     SendClientMessage(playerid, COLOR_ORANGE, WLCM);
  92.     PJob[playerid] = 0;
  93.    
  94.     if (!dini_Exists(UserPath(playerid)))
  95.     {
  96.     dini_Create(UserPath(playerid));
  97.     }
  98.     else
  99.     {
  100.     PJob[playerid] = dini_Int(UserPath(playerid), "Job");
  101.     }
  102.     return 1;
  103. }
  104.  
  105. public OnPlayerDisconnect(playerid, reason)
  106. {
  107.     dini_IntSet(UserPath(playerid),"Job", PJob[playerid]);
  108.     return 1;
  109. }
  110.  
  111. public OnPlayerSpawn(playerid)
  112. {
  113.    
  114.     if (PJob[playerid] > 0)
  115.     {
  116.     new string[60];
  117.     format(string,sizeof(string),"Job: %s", GetJobName(PJob[playerid]));
  118.     SendClientMessage(playerid, COLOR_ORANGE, string);
  119.     }
  120.     return 1;
  121. }
  122.  
  123. public OnPlayerCommandText(playerid, cmdtext[])
  124. {
  125.     new cmd[30];
  126.     new idx;
  127.     cmd = strtok(cmdtext, idx);
  128.  
  129.     if(strcmp(cmd, "/job", true) == 0)
  130.     {
  131.         new tmp[30];
  132.         tmp = strtok(cmdtext, idx);
  133.  
  134.         new jobid = strval(tmp);
  135.         if (PJob[playerid] != 0) return SendClientMessage(playerid, COLOR_ORED,"You already have a job!");
  136.         if (jobid == 0) return SendClientMessage(playerid, COLOR_ORANGE,"Usage: /job [id]");
  137.         if (jobid < 1 || jobid > JobCount) return SendClientMessage(playerid, COLOR_ORED,"Invalid ID!");
  138.         if (Job[jobid][AdminOnly] == 1 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_ORED,"This job is for admins only!");
  139.         PJob[playerid] = jobid;
  140.         new string[120];
  141.         format(string,sizeof(string),"**%s has joined %s", PlayerName(playerid), GetJobName(jobid));
  142.         SendClientMessageToAll(COLOR_ORANGE,string);
  143.         dini_IntSet(UserPath(playerid),"Job", PJob[playerid]);
  144.         return 1;
  145.     }
  146.    
  147.     if(strcmp(cmdtext, "/jobskin", true) == 0)
  148.     {
  149.     if (PJob[playerid] == 0) return SendClientMessage(playerid, COLOR_ORED,"You are not in a job!");
  150.     SetPlayerSkin(playerid, Job[PJob[playerid]][Skin]);
  151.     return 1;
  152.     }
  153.    
  154.     if(strcmp(cmdtext, "/leavejob", true) == 0)
  155.     {
  156.     if (PJob[playerid] == 0) return SendClientMessage(playerid, COLOR_ORED,"You are not in a job!");
  157.     new string[120];
  158.     format(string,sizeof(string),"**%s has left %s", PlayerName(playerid), GetJobName(PJob[playerid]));
  159.     SendClientMessageToAll(COLOR_ORANGE,string);
  160.     PJob[playerid] = 0;
  161.     dini_IntSet(UserPath(playerid),"Job", PJob[playerid]);
  162.     return 1;
  163.     }
  164.    
  165.    
  166.     return 0;
  167. }
  168.  
  169.  
  170. public OnPlayerStateChange(playerid, newstate, oldstate)
  171. {
  172.     if (newstate == PLAYER_STATE_DRIVER) //Blocks player from driving other job vehicles
  173.     {
  174.         new vehicleid = GetPlayerVehicleID(playerid);
  175.  
  176.         for (new i=1;i<JobCount+1;i++)
  177.         {
  178.             for (new a=0;a<5;a++)
  179.             {
  180.                 if (vehicleid == Job[i][Vehicles][a] && i != PJob[playerid])
  181.                 {
  182.                 SendClientMessage(playerid, COLOR_ORED,"You are not authorized to use this vehicle!");
  183.                 RemovePlayerFromVehicle(playerid);
  184.                 }
  185.             }
  186.         }
  187.     }
  188.     return 1;
  189. }
  190.  
  191. stock CreateJob(name[28],skin,adminonly) //Create a job
  192. {
  193. JobCount++;
  194. if (JobCount > MAX_JOBS) return printf("Job- system alert: Increase the 'MAX_JOBS' size to add more jobs!");
  195. new id = JobCount;
  196. Job[id][Name] = name;
  197. Job[id][Skin] = skin;
  198. Job[id][AdminOnly] = adminonly;
  199. printf("Job '%s' added. (ID: %d)", name, id);
  200. return 1;
  201. }
  202.  
  203. stock strtok(const string[], &index)
  204. {
  205.     new length = strlen(string);
  206.     while ((index < length) && (string[index] <= ' '))
  207.     {
  208.         index++;
  209.     }
  210.  
  211.     new offset = index;
  212.     new result[20];
  213.     while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  214.     {
  215.         result[index - offset] = string[index];
  216.         index++;
  217.     }
  218.     result[index - offset] = EOS;
  219.     return result;
  220. }
  221.  
  222.  
  223. stock GetJobName(jobid) //Get job name
  224. {
  225. new jobname[28];
  226. format(jobname,sizeof(jobname),"%s",Job[jobid][Name]);
  227. return jobname;
  228. }
  229.  
  230.  
  231. stock UserPath(playerid) //Getting the file path
  232. {
  233. new path[40];
  234. format(path,sizeof(path),"Jobs_%s.ini", PlayerName(playerid));
  235. return path;
  236. }
  237.  
  238.  
  239. stock PlayerName(playerid) //Returns the player name with a simple function
  240. {
  241.   new name[24];
  242.   GetPlayerName(playerid, name, sizeof(name));
  243.   return name;
  244. }
  245.  
  246. stock GetPlayerJob(playerid, name[28])
  247. {
  248.     if (strcmp(name, GetJobName(PJob[playerid]), true) == 0)
  249.     {
  250.     //Success
  251.     return 1;
  252.     }
  253.        
  254.     return 0; //Fail
  255. }
  256.  
  257.  
Advertisement
Add Comment
Please, Sign In to add comment