Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Job system for stuoyto
- //Made by Jakku
- //(C) Copyright 2011
- #include <a_samp>
- #include <Dini>
- #define MAX_JOBS 10
- #define COLOR_ORANGE 0xFF9900AA
- #define COLOR_ORED 0xFF0000FF
- forward PayDay();
- #define WLCM "This server is using the simple Job system by Jakku"
- new PJob[MAX_PLAYERS];
- enum Jobs
- {
- Name[28],
- Skin,
- AdminOnly,
- Vehicles[5],
- };
- new Job[MAX_JOBS][Jobs];
- new JobCount;
- public PayDay()
- {
- for (new i=0;i<MAX_PLAYERS;i++)
- {
- if (IsPlayerConnected(i))
- {
- if (PJob[i] > 0)
- {
- new PAY = 300;
- new string[80];
- format(string,sizeof(string),"You have earned from your job ($%d)", PAY);
- SendClientMessage(i, COLOR_ORANGE,string);
- GivePlayerMoney(i, PAY);
- }
- }
- }
- }
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print("== Jobs Filterscript for stuoyto coded by Jakku (C) 2011 ==");
- print("== Loaded successfully ==");
- print("--------------------------------------\n");
- //Initialize jobs
- //Syntax: CreateJob("jobname",skin_id,admins_only);
- CreateJob("Police", 282,1); //Change the skin IDs, I just threw something in :P
- CreateJob("Mechanic", 45,0);
- CreateJob("Cardealer", 42,0);
- CreateJob("Taxidriver", 42,0);
- CreateJob("Busdriver", 42,0);
- CreateJob("Army", 42,0);
- CreateJob("Lawyer", 42,0);
- CreateJob("Gundealer", 42,0);
- CreateJob("Bodyguard", 42,0);
- SetTimer("PayDay",1800000,1);
- return 1;
- }
- public OnFilterScriptExit()
- {
- print("Thank you for using the Job system by Jakku. (C) 2011");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- SendClientMessage(playerid, COLOR_ORANGE, WLCM);
- PJob[playerid] = 0;
- if (!dini_Exists(UserPath(playerid)))
- {
- dini_Create(UserPath(playerid));
- }
- else
- {
- PJob[playerid] = dini_Int(UserPath(playerid), "Job");
- }
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- dini_IntSet(UserPath(playerid),"Job", PJob[playerid]);
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- if (PJob[playerid] > 0)
- {
- new string[60];
- format(string,sizeof(string),"Job: %s", GetJobName(PJob[playerid]));
- SendClientMessage(playerid, COLOR_ORANGE, string);
- }
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- new cmd[30];
- new idx;
- cmd = strtok(cmdtext, idx);
- if(strcmp(cmd, "/job", true) == 0)
- {
- new tmp[30];
- tmp = strtok(cmdtext, idx);
- new jobid = strval(tmp);
- if (PJob[playerid] != 0) return SendClientMessage(playerid, COLOR_ORED,"You already have a job!");
- if (jobid == 0) return SendClientMessage(playerid, COLOR_ORANGE,"Usage: /job [id]");
- if (jobid < 1 || jobid > JobCount) return SendClientMessage(playerid, COLOR_ORED,"Invalid ID!");
- if (Job[jobid][AdminOnly] == 1 && !IsPlayerAdmin(playerid)) return SendClientMessage(playerid, COLOR_ORED,"This job is for admins only!");
- PJob[playerid] = jobid;
- new string[120];
- format(string,sizeof(string),"**%s has joined %s", PlayerName(playerid), GetJobName(jobid));
- SendClientMessageToAll(COLOR_ORANGE,string);
- dini_IntSet(UserPath(playerid),"Job", PJob[playerid]);
- return 1;
- }
- if(strcmp(cmdtext, "/jobskin", true) == 0)
- {
- if (PJob[playerid] == 0) return SendClientMessage(playerid, COLOR_ORED,"You are not in a job!");
- SetPlayerSkin(playerid, Job[PJob[playerid]][Skin]);
- return 1;
- }
- if(strcmp(cmdtext, "/leavejob", true) == 0)
- {
- if (PJob[playerid] == 0) return SendClientMessage(playerid, COLOR_ORED,"You are not in a job!");
- new string[120];
- format(string,sizeof(string),"**%s has left %s", PlayerName(playerid), GetJobName(PJob[playerid]));
- SendClientMessageToAll(COLOR_ORANGE,string);
- PJob[playerid] = 0;
- dini_IntSet(UserPath(playerid),"Job", PJob[playerid]);
- return 1;
- }
- return 0;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if (newstate == PLAYER_STATE_DRIVER) //Blocks player from driving other job vehicles
- {
- new vehicleid = GetPlayerVehicleID(playerid);
- for (new i=1;i<JobCount+1;i++)
- {
- for (new a=0;a<5;a++)
- {
- if (vehicleid == Job[i][Vehicles][a] && i != PJob[playerid])
- {
- SendClientMessage(playerid, COLOR_ORED,"You are not authorized to use this vehicle!");
- RemovePlayerFromVehicle(playerid);
- }
- }
- }
- }
- return 1;
- }
- stock CreateJob(name[28],skin,adminonly) //Create a job
- {
- JobCount++;
- if (JobCount > MAX_JOBS) return printf("Job- system alert: Increase the 'MAX_JOBS' size to add more jobs!");
- new id = JobCount;
- Job[id][Name] = name;
- Job[id][Skin] = skin;
- Job[id][AdminOnly] = adminonly;
- printf("Job '%s' added. (ID: %d)", name, id);
- return 1;
- }
- stock strtok(const string[], &index)
- {
- new length = strlen(string);
- while ((index < length) && (string[index] <= ' '))
- {
- index++;
- }
- new offset = index;
- new result[20];
- while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
- {
- result[index - offset] = string[index];
- index++;
- }
- result[index - offset] = EOS;
- return result;
- }
- stock GetJobName(jobid) //Get job name
- {
- new jobname[28];
- format(jobname,sizeof(jobname),"%s",Job[jobid][Name]);
- return jobname;
- }
- stock UserPath(playerid) //Getting the file path
- {
- new path[40];
- format(path,sizeof(path),"Jobs_%s.ini", PlayerName(playerid));
- return path;
- }
- stock PlayerName(playerid) //Returns the player name with a simple function
- {
- new name[24];
- GetPlayerName(playerid, name, sizeof(name));
- return name;
- }
- stock GetPlayerJob(playerid, name[28])
- {
- if (strcmp(name, GetJobName(PJob[playerid]), true) == 0)
- {
- //Success
- return 1;
- }
- return 0; //Fail
- }
Advertisement
Add Comment
Please, Sign In to add comment