All pastes #772692 Raw Edit

Driving License Filterscript

public text v1 · immutable
#772692 ·published 2007-11-13 23:55 UTC
rendered paste body
#include <a_samp>
#include <Dini>
#include <dutils>


#pragma tabsize 0

#define COLOR_ORANGE 0xFF9900AA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFF00
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_BLUE 0x0000BBAA


forward License_Dis(playerid);
forward License_No(playerid);
forward License_Yes(playerid);
new File:License;

new DMV[MAX_PLAYERS];


public OnFilterScriptInit()
{
        print("\n----------------------------------");
        print(" DrivingLicenseFilterScript Created By Nate660");
        print("----------------------------------\n");
        if(!fopen("License",io_read))
        {
                print("\r\n\r\nError: Driving License Data Not Found Creating New File.");
                License=fopen("License",io_readwrite);
        }
        else
        {
                print("\r\n\r\nDriving License Data Found Now Loading Data");
                License=fopen("License",io_readwrite);
        }
        fclose(License);
        return 1;
}
public OnFilterScriptExit()
{
    print("\n----------------------------------");
    print(" DrivingLicenseFilterScript Unloaded Successfully");
    print("----------------------------------\n");
	return 1;
}
public OnPlayerConnect(playerid)
{
        SendClientMessage(playerid, COLOR_YELLOW, "This server uses Nate660's Driving FilterScript VER:0.0.1!!");
    	DMV[playerid] = 0;
		new PName[MAX_PLAYER_NAME];
    	if(strcmp(dini_Get("License",PName),"ValidLicense",true)==0)
    	{
    	    fclose(License);
    	}
    	else if(strcmp(dini_Get("License",PName),"NoLicense",true)==0)
        {
            fclose(License);
        }
        else if(strcmp(dini_Get("License",PName),"SuspendedLicense",true)==0)
        {
            fclose(License);
        }
    	return 1;
}
public OnPlayerSpawn(playerid)
{
DMV[playerid] = 0;
return 1;
}
public OnPlayerCommandText(playerid, cmdtext[])
{
    			new tmp[256];
				new string[256];
				new cmd[256];
				new idx;
    			new tracedID;
                new tracedIDName[MAX_PLAYER_NAME];
                new PName[MAX_PLAYER_NAME];
				cmd = strtok(cmdtext, idx);
				
				if (!strcmp(cmdtext, "/mylicense", true))
{
if(strcmp(dini_Get("License",PName),"NoLicense",true)==0)
{
SendClientMessage(playerid,COLOR_WHITE, "|__________________Driver Stats__________________|");
SendClientMessage(playerid,COLOR_GREY, "Status:No License");
SendClientMessage(playerid,COLOR_GREY, "Type /schedule [Message] To Schedule a message with online Dmv's");
return 1;
}
if(strcmp(dini_Get("License",PName),"SuspendedLicense",true)==0)
{
SendClientMessage(playerid,COLOR_WHITE, "|__________________Driver Stats__________________|");
SendClientMessage(playerid,COLOR_GREY, "Status:License Suspended");
SendClientMessage(playerid,COLOR_GREY, "Do not Drive:/ If you do Make Sure Cops Don't Stop you If So JailTime For you Buddy");
return 1;
}
if(strcmp(dini_Get("License",PName),"ValidLicense",true)==0)
{
SendClientMessage(playerid,COLOR_WHITE, "|__________________Driver Stats__________________|");
SendClientMessage(playerid,COLOR_GREEN, "Status:You have a Valid DMV Issued license");
SendClientMessage(playerid,COLOR_GREEN, "Becareful on the Road Cops Can Take It Back");
return 1;
}
}
                if(strcmp(cmd, "/DMV_PASSHERE", true) == 0) {
		SendClientMessage(playerid, COLOR_WHITE, "SERVER:Your are now a Registerd DMV Instructor");
		SendClientMessage(playerid, COLOR_YELLOW, "Your Commands Are: /givelicense [ID] /takelicense [ID] /renewlicense [ID]");
        DMV[playerid] = 1;
        TogglePlayerControllable(playerid,1);
		SetPlayerColor(playerid, COLOR_WHITE);
		return 1;
	}
				if(strcmp(cmd, "/status", true) == 0) {//Status Command
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp)) {
                        SendClientMessage(playerid, COLOR_GREEN, "Usage: /status [Player ID]");
                        return 1;
                }
        		tracedID = strval(tmp);

        		if (DMV[playerid] == 1) {
            	if (IsPlayerConnected(tracedID)) {
            	GetPlayerName(tracedID, tracedIDName, sizeof(tracedIDName));
                                License=fopen("License",io_readwrite);
                                if(strcmp(dini_Get("License",tracedIDName),"ValidLicense",true)==0)
                                {
                                        format(string, sizeof(string), "%s (ID:%d) has a valid drivers license.",tracedIDName,tracedID);
                                        printf("%s (ID:%d) has had their license checked. Status: Clean license.",tracedIDName,tracedID);
                                        SendClientMessage(playerid,0x33AA33AA,string);
                                        fclose(License);
                                        return 1;
                                }
                                else if(strcmp(dini_Get("License",tracedIDName),"NoLicense",true)==0)
                                {
                                        format(string, sizeof(string), "%s (ID:%d) doesn't carry a valid drivers license.",tracedIDName,tracedID);
                                        SendClientMessage(playerid,0xFF000000,string);
                                        SendClientMessage(playerid,0xFF000000,"DMV: Jail them, or send them to driving school.");
                                        printf("%s (ID:%d) has had their license checked. Status: No license.",tracedIDName,tracedID);
                                        fclose(License);
                                        return 1;
                                }
                                else if(strcmp(dini_Get("License",tracedIDName),"SuspendedLicense",true)==0)
                                {
                                        format(string, sizeof(string), "%s (ID:%d) has been Suspended from driving.",tracedIDName,tracedID);
                                        SendClientMessage(playerid,0xFF000000,string);
                                        SendClientMessage(playerid,0xFF000000,"DMV: Jail them, at reasonable cost.");
                                        printf("%s (ID:%d) has been licence checked. Status: Suspended DriversLicense.",tracedIDName,tracedID);
                                        fclose(License);
                                        return 1;
                                }
                                else
                                {
                                        SendClientMessage(playerid,0xFF000000,"Error: Unable to establish licence status.");
                                        fclose(License);
                                        return 1;
                                }
                        }
                        else
                        {
                                SendClientMessage(playerid,0xFF000000,"That Player Is Not In Server");
                        }
						}
                        else
                        {
                                SendClientMessage(playerid,0xFF000000,"You are not an Offcial Cop");
                        }
                return 1;
        }

				if(strcmp(cmd, "/givelicense", true) == 0) {//Givelicense Command
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp)) {
                        SendClientMessage(playerid, COLOR_GREEN, "Usage: /givelicense [Player ID]");
                        return 1;
                }
        		tracedID = strval(tmp);

        		if (DMV[playerid] == 1) {
            	if (IsPlayerConnected(tracedID)) {
                      			GetPlayerName(tracedID, tracedIDName, sizeof(tracedIDName));
                                GetPlayerName(playerid, PName, sizeof(PName));
                                License=fopen("License",io_readwrite);
                                if(strcmp(dini_Get("License",tracedIDName),"NoLicense",true)==0)
                                {
                                        format(string, sizeof(string), "%s (ID:%d) has Recieved A valid Drivers License.",tracedIDName,tracedID);
                                        SendClientMessage(playerid,0xFF000000,string);
                                        printf("%s (ID:%d) has a Valid Drivers License Now.",tracedIDName,tracedID);
                                        format(string, sizeof(string), "%s (ID:%d) has received A Valid Drivers License by DMV Instructor: %s (ID:%d).",tracedIDName,tracedID,PName,playerid);
                                        SendClientMessageToAll(0xFF800000,string);
                                        License_Yes(tracedID);
                                        fclose(License);
                                		return 1;
                                        }else{
        format(string, sizeof(string), "Unable To Ustablish License Status!!");
		SendClientMessage(playerid, COLOR_YELLOW, string);
}
										}else{
        format(string, sizeof(string), "id %d Is an invalid ID!!", tracedID);
		SendClientMessage(playerid, COLOR_YELLOW, string);
}
                }else{
        format(string, sizeof(string), "You Are not a DMV Instructor", playerid);
        SendClientMessage(playerid, COLOR_WHITE, string);
}
				return 1;
}
                if(strcmp(cmd, "/renewlicense", true) == 0) {//Renewlicense Command
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp)) {
                        SendClientMessage(playerid, COLOR_GREEN, "Usage: /renewlicense [Player ID]");
                        return 1;
                }
        		tracedID = strval(tmp);

        		if (DMV[playerid] == 1) {
            	if (IsPlayerConnected(tracedID)) {
                      			GetPlayerName(tracedID, tracedIDName, sizeof(tracedIDName));
                                GetPlayerName(playerid, PName, sizeof(PName));
                                License=fopen("License",io_readwrite);
                                if(strcmp(dini_Get("License",tracedIDName),"SuspendedLicense",true)==0)
                                {
                                        format(string, sizeof(string), "%s (ID:%d) Have Had your license Renewed!!",tracedIDName,tracedID);
                                        SendClientMessage(playerid,0xFF000000,string);
                                        printf("%s (ID:%d) has a Valid Drivers License Now.",tracedIDName,tracedID);
                                        format(string, sizeof(string), "%s (ID:%d) has had there Suspended License Renewed by DMV Instructor: %s (ID:%d).",tracedIDName,tracedID,PName,playerid);
                                        SendClientMessageToAll(0xFF800000,string);
                                        License_Yes(tracedID);
                                        fclose(License);
                                		return 1;
                                        }else{
        format(string, sizeof(string), "Unable To Establish License Status!!");
		SendClientMessage(playerid, COLOR_YELLOW, string);
}
										}else{
        format(string, sizeof(string), "id %d Is an invalid ID!!", tracedID);
		SendClientMessage(playerid, COLOR_YELLOW, string);
}
                }else{
        format(string, sizeof(string), "You Are not a DMV Instructor", playerid);
        SendClientMessage(playerid, COLOR_WHITE, string);
}
				return 1;
}
                if(strcmp(cmd, "/suspendlicense", true) == 0) {//Suspendlicense Command
                tmp = strtok(cmdtext, idx);
                if(!strlen(tmp)) {
                        SendClientMessage(playerid, COLOR_GREEN, "Usage: /suspendlicense [Player ID]");
                        return 1;
                }
        		tracedID = strval(tmp);

        		if (DMV[playerid] == 1) {
            	if (IsPlayerConnected(tracedID)) {
            	GetPlayerName(tracedID, tracedIDName, sizeof(tracedIDName));
                GetPlayerName(playerid, PName, sizeof(PName));
                License=fopen("License",io_readwrite);
                if(strcmp(dini_Get("License",tracedIDName),"ValidLicense",true)==0)
                {
                format(string, sizeof(string), "%s (ID:%d) has had their licence suspended.",tracedIDName,tracedID);
                printf("%s (ID:%d) has been licence suspended.",tracedIDName,tracedID);
                SendClientMessage(playerid,0xFF000000,string);
                format(string, sizeof(string), "%s (ID:%d) has had their licence suspended by %s (ID:%d).",tracedIDName,tracedID,PName,playerid);
                SendClientMessageToAll(0xFF800000,string);
                License_Dis(tracedID);
                fclose(License);
                return 1;
                }else{
        format(string, sizeof(string), "Doesn't Have a License To Take");
		SendClientMessage(playerid, COLOR_YELLOW, string);
}
                      			}else{
        format(string, sizeof(string), "id %d Is an invalid ID!!", tracedID);
		SendClientMessage(playerid, COLOR_YELLOW, string);
}
                }else{
        format(string, sizeof(string), "You Are not a DMV Instructor", playerid);
        SendClientMessage(playerid, COLOR_WHITE, string);
}
				return 1;
}
                if(strcmp(cmd, "/instructors", true) == 0)
{
	new playername[24];
	new count = 0;
	SendClientMessage(playerid, 0xFFFF00AA, "Online DMV's:");
	for(new i=0; i<MAX_PLAYERS; i++)
	{
		if(IsPlayerConnected(i) && DMV[i])
		{
			GetPlayerName(i,playername,24);
			format(string,sizeof(string),"%s", playername);
			SendClientMessage(playerid, 0xFFFFFFAA, string);
			count++;
		}
	}
	if(count == 0)
	{
		SendClientMessage(playerid, 0xFFFFFFAA, "There are currently no Driving instructors online.");
	}
	return 1;
}
return 0;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new PName[MAX_PLAYER_NAME];

    GetPlayerName(playerid,PName,sizeof(PName));

        if((newstate==PLAYER_STATE_DRIVER)&&(strcmp(dini_Get("License",PName),"NoLicense",false)==0))
        {
            SendClientMessage(playerid,0xFF000000,"You are driving without a Valid DMV Issued License. You may be arrested.");
            printf("%s(ID:%d) is driving without a licence.",PName,playerid);
        }
        else if((newstate==PLAYER_STATE_DRIVER)&&(strcmp(dini_Get("License",PName),"SuspendedLicense",false)==0))
        {
            SendClientMessage(playerid,0xFF000000,"You are driving with a Suspended License. You are likely to be arrested.");
            printf("%s(ID:%d) is driving with a suspended licence.",PName,playerid);
        }
}
public License_No(playerid)
{
    new PName[MAX_PLAYER_NAME];

    GetPlayerName(playerid,PName,sizeof(PName));
    License=fopen("License",io_readwrite);
        dini_Set("License",PName,"NoLicense");
        fclose(License);
        return 1;
}
public License_Yes(playerid)
{
    new PName[MAX_PLAYER_NAME];

    GetPlayerName(playerid,PName,sizeof(PName));
    License=fopen("License",io_readwrite);
        dini_Set("License",PName,"ValidLicense");
        fclose(License);
        return 1;
}
public License_Dis(playerid)
{
    new PName[MAX_PLAYER_NAME];

    GetPlayerName(playerid,PName,sizeof(PName));
    License=fopen("License",io_readwrite);
    dini_Set("License",PName,"SuspendedLicense");
    fclose(License);
        return 1;
}