Engine Help
#1

Код:
#define FILTERSCRIPT
#include <a_samp>
#include <zcmd>
#define red 0xAA3333AA //Change this to the error color you want.
#define COLOR_PURPLE 0xC2A2DAAA //prox detector color
new gLastCar[MAX_PLAYERS];




stock IsABoat(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
        case 430,446,452,453,454,472,473,484,493,595: return 1;
    }
    return 0;
}

stock IsAPlane(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
        case 460,464,476,511,512,513,519,520,553,577,592,593: return 1;
    }
    return 0;
}

stock IsAHelicopter(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
        case 417,425,447,465,469,487,488,497,501,548,563: return 1;
    }
    return 0;
}

stock IsATrain(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
        case 449,537,538,569,570,590: return 1;
    }
    return 0;
}

stock IsABike(vehicleid)
{
    switch(GetVehicleModel(vehicleid))
    {
        case 448,461,462,463,468,521,522,523,581,586,481,409,510: return 1;
    }
    return 0;
}

stock IsPlayerDriver(playerid)
{
	if(IsPlayerConnected(playerid) && GetPlayerState(playerid)==PLAYER_STATE_DRIVER)
	{
		return 1;
	}
	return 0;
}

stock ProxDetector(Float:radi, playerid, string[],col1,col2,col3,col4,col5)
{
	if(IsPlayerConnected(playerid))
	{
		new Float:posx, Float:posy, Float:posz;
		new Float:oldposx, Float:oldposy, Float:oldposz;
		new Float:tempposx, Float:tempposy, Float:tempposz;
		new invehicle[MAX_PLAYERS];
		new virtualworld = GetPlayerVirtualWorld(playerid);
		new interior = GetPlayerInterior(playerid);
		new vehicleid = GetPlayerVehicleID(playerid);
		new ivehicleid;
		if(vehicleid)
		{
			GetVehiclePos(vehicleid,oldposx,oldposy,oldposz);
		}
		else
		{
			GetPlayerPos(playerid, oldposx, oldposy, oldposz);
			vehicleid = GetPlayerVehicleID(playerid);
		}
		for(new i; i<MAX_PLAYERS; i++)
		{
			if(IsPlayerConnected(i))
			{
					if(GetPlayerVirtualWorld(i) == virtualworld)
					{
						if((GetPlayerInterior(i) == interior))
						{
						    if(vehicleid)
						    {
							    if(IsPlayerInVehicle(i,vehicleid))
							    {
	          						invehicle[i] = 1;
								}
							}
							if(!invehicle[i])
							{
							    if(IsPlayerInAnyVehicle(i))
								{
								    ivehicleid = GetPlayerVehicleID(i);
								    GetVehiclePos(ivehicleid,posx,posy,posz);
								} else {
					    			GetPlayerPos(i,posx,posy,posz);
								}
								tempposx = (oldposx -posx);
								tempposy = (oldposy -posy);
								tempposz = (oldposz -posz);
								if (((tempposx < radi/16) && (tempposx > -radi/16)) && ((tempposy < radi/16) && (tempposy > -radi/16)) && ((tempposz < radi/16) && (tempposz > -radi/16)))
								{
									SendClientMessage(i, col1, string);
								}
								else if (((tempposx < radi/8) && (tempposx > -radi/8)) && ((tempposy < radi/8) && (tempposy > -radi/8)) && ((tempposz < radi/8) && (tempposz > -radi/8)))
								{
									SendClientMessage(i, col2, string);
								}
								else if (((tempposx < radi/4) && (tempposx > -radi/4)) && ((tempposy < radi/4) && (tempposy > -radi/4)) && ((tempposz < radi/4) && (tempposz > -radi/4)))
								{
									SendClientMessage(i, col3, string);
								}
								else if (((tempposx < radi/2) && (tempposx > -radi/2)) && ((tempposy < radi/2) && (tempposy > -radi/2)) && ((tempposz < radi/2) && (tempposz > -radi/2)))
								{
									SendClientMessage(i, col4, string);
								}
								else if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
								{
									SendClientMessage(i, col5, string);
								}
							}
							else
							{
								SendClientMessage(i, col1, string);
							}
						}
					}
				} else {
					SendClientMessage(i, col1, string);
				}
			}
	}
	return 1;
}

public OnFilterScriptInit()
{
	print("\n--------------------------------------------");
	print("| Vehicle Control System - By Joe Adonis |");
	print("--------------------------------------------\n");
	ManualVehicleEngineAndLights();
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
	{
	new newcar = GetPlayerVehicleID(playerid);
	gLastCar[playerid] = newcar;
	SendClientMessage(playerid, -1, "Type /engine to start your vehicle!"); //Remove if you don't have manual control
	}
return 1;
}

CMD:engine(playerid, params[])
{
	new string[128];
	new sendername[MAX_PLAYER_NAME];
	GetPlayerName(playerid, sendername, sizeof(sendername));
	new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
	if(!IsPlayerDriver(playerid))
	{
		SendClientMessage(playerid,red,"[Vehicle Control] You're not in a Vehicle with an engine!");
		return 1;
	}
		else if(IsPlayerDriver(playerid))
			{
    			if(engine != 0)
				{
				    engine = 1;
					SetVehicleParamsEx(GetPlayerVehicleID(playerid),VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
					SendClientMessage(playerid, 0xFFFFFFAA, "[Vehicle Control] You've turned the vehicle's engine {2F991A}ON");
					format(string, sizeof(string), "* %s puts a key into their ignition and turns on their engine.", sendername);
				    ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				    return 1;
				}
				else
				{
				    engine = 0;
					SetVehicleParamsEx(GetPlayerVehicleID(playerid),VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
					SendClientMessage(playerid, 0xFFFFFFAA, "[Vehicle Control] You've turned the vehicle's engine {E31919}OFF");
					format(string, sizeof(string), "* %s switches the key in their engine turning it off.", sendername);
				    ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				    return 1;
				}
		}
  	return engine;
}

/*CMD:objective(playerid, params[])
{
	new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
	if(!IsPlayerDriver(playerid))
	{
		SendClientMessage(playerid,red,"[Vehicle Control] You're not in a Vehicle to control the lights!");
		return 1;
	}
		else if(IsPlayerDriver(playerid))
			{
    			if(objective != 1)
				{
				    objective = 1;
					SetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,VEHICLE_PARAMS_ON);
					SendClientMessage(playerid, 0xFFFFFFAA, "[Vehicle Control] You've turned the vehicle's objective {2F991A}on!");
				    return 1;
				}
				else
				{
				    objective = 0;
					SetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,VEHICLE_PARAMS_OFF);
					SendClientMessage(playerid, 0xFFFFFFAA, "[Vehicle Control] You've turned the vehicle's objective {E31919}off!");
				    return 1;
				}
		}
  	return objective;
}*/ // Commented due to Non-RP on Roleplay Servers, feel free to un-comment if you wish to use it.

CMD:lights(playerid, params[])
{
	new string[128];
	new sendername[MAX_PLAYER_NAME];
	GetPlayerName(playerid, sendername, sizeof(sendername));
	new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
	if(!IsPlayerDriver(playerid))
	{
		SendClientMessage(playerid,red,"[Vehicle Control] You're not in a Vehicle to control the lights!");
		return 1;
	}
		else if(IsPlayerDriver(playerid))
			{
    			if(lights != 1)
				{
				    lights = 1;
					SetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,VEHICLE_PARAMS_ON,alarm,doors,bonnet,boot,objective);
					SendClientMessage(playerid, 0xFFFFFFAA, "[Vehicle Control] You've turned the vehicle's lights {2F991A}ON");
					format(string, sizeof(string), "* %s flicks a switch on the dashboard, switching on their lights.", sendername);
				    ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				    return 1;
				}
				else
				{
				    lights = 0;
					SetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,VEHICLE_PARAMS_OFF,alarm,doors,bonnet,boot,objective);
					SendClientMessage(playerid, 0xFFFFFFAA, "[Vehicle Control] You've turned the vehicle's lights {E31919}OFF");
					format(string, sizeof(string), "* %s flicks a switch on the dashboard, switching off their lights.", sendername);
				    ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				    return 1;
				}
		}
  	return lights;
}

CMD:hood(playerid, params[])
{
	new string[128];
	new sendername[MAX_PLAYER_NAME];
	GetPlayerName(playerid, sendername, sizeof(sendername));
	new engine,lights,alarm,doors,bonnet,boot,objective;
    new oldcar = gLastCar[playerid];
	new Float:cX, Float:cY, Float:cZ;
	GetVehicleParamsEx(oldcar, engine, lights, alarm, doors, bonnet, boot, objective);
	GetVehiclePos(oldcar, cX, cY, cZ);
	new vehicleid = GetPlayerVehicleID(playerid);
	if(!IsAPlane(vehicleid) || !IsAHelicopter(vehicleid) || !IsABike(vehicleid) || !IsATrain(vehicleid) || !IsABoat(vehicleid))
	{
		if(IsPlayerDriver(playerid) || IsPlayerInRangeOfPoint(playerid, 5, cX-2, cY, cZ))
			{
    			if(bonnet != 1)
				{
				    bonnet = 1;
					SetVehicleParamsEx(oldcar,engine,lights,alarm,doors,VEHICLE_PARAMS_ON,boot,objective);
					SendClientMessage(playerid, 0xFFFFFFAA, "[Vehicle Control] You've opened the hood!");
					format(string, sizeof(string), "* %s opens up the hood of the car.", sendername);
				    ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				    return 1;
				}
				else
				{
				    bonnet = 0;
					SetVehicleParamsEx(oldcar,engine,lights,alarm,doors,VEHICLE_PARAMS_OFF,boot,objective);
					SendClientMessage(playerid, 0xFFFFFFAA, "[Vehicle Control] You've shut the hood!");
					format(string, sizeof(string), "* %s closes the hood of the car.", sendername);
				    ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				    return 1;
				}
		}
	}
  	return bonnet;
}

CMD:trunk(playerid, params[])
{
	new string[128];
	new sendername[MAX_PLAYER_NAME];
	GetPlayerName(playerid, sendername, sizeof(sendername));
	new engine,lights,alarm,doors,bonnet,boot,objective;
    new oldcar = gLastCar[playerid];
	new Float:cX, Float:cY, Float:cZ;
	GetVehicleParamsEx(oldcar, engine, lights, alarm, doors, bonnet, boot, objective);
	GetVehiclePos(oldcar, cX, cY, cZ);
	new vehicleid = GetPlayerVehicleID(playerid);
	if(!IsAPlane(vehicleid) || !IsAHelicopter(vehicleid) || !IsABike(vehicleid) || !IsATrain(vehicleid) || !IsABoat(vehicleid))
	{
		if(IsPlayerDriver(playerid) || IsPlayerInRangeOfPoint(playerid, 5, cX+2, cY, cZ))
				{
    				if(boot != 1)
					{
				    	boot = 1;
						SetVehicleParamsEx(oldcar,engine,lights,alarm,doors,bonnet,VEHICLE_PARAMS_ON,objective);
						SendClientMessage(playerid, 0xFFFFFFAA, "[Vehicle Control] You've opened the trunk!");
						format(string, sizeof(string), "* %s opens up the trunk of the car.", sendername);
				    	ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				    	return 1;
					}
					else
					{
				    	boot = 0;
						SetVehicleParamsEx(oldcar,engine,lights,alarm,doors,bonnet,VEHICLE_PARAMS_OFF,objective);
						SendClientMessage(playerid, 0xFFFFFFAA, "[Vehicle Control] You've shut the trunk!");
						format(string, sizeof(string), "* %s closes the trunk of the car.", sendername);
				    	ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				    	return 1;
					}
			}
		}
  	return boot;
}

/*CMD:lockv(playerid, params[])
{
    new oldcar = gLastCar[playerid];
	new Float:cX, Float:cY, Float:cZ;
	GetVehiclePos(oldcar, cX, cY, cZ);
	new string[128];
	new sendername[MAX_PLAYER_NAME];
	GetPlayerName(playerid, sendername, sizeof(sendername));
	new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(oldcar, engine, lights, alarm, doors, bonnet, boot, objective);
	if(!IsPlayerInRangeOfPoint(playerid, 4, cX, cY, cZ))
	{
		SendClientMessage(playerid,red,"[Vehicle Control] You're not in range/in the Vehicle you last drove!");
		return 1;
	}
		else if(IsPlayerInRangeOfPoint(playerid, 4, cX, cY, cZ))
			{
    			if(doors != 1)
				{
				    doors = 1;
					SetVehicleParamsEx(oldcar,engine,lights,alarm,VEHICLE_PARAMS_ON,bonnet,boot,objective);
					SendClientMessage(playerid, 0xFFFFFFAA, "[Vehicle Control] You've locked the vehicle!");
					format(string, sizeof(string), "* %s locks their vehicle.", sendername);
				    ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				    return 1;
				}
				else
				{
				    doors = 0;
					SetVehicleParamsEx(oldcar,engine,lights,alarm,VEHICLE_PARAMS_OFF,bonnet,boot,objective);
					SendClientMessage(playerid, 0xFFFFFFAA, "[Vehicle Control] You've unlocked the vehicle!");
					format(string, sizeof(string), "* %s unlocks his vehicle.", sendername);
				    ProxDetector(20.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
				    return 1;
				}
		}
  	return doors;
}*/
Does someone know how to make like a Timer for this Engine Command, like "Attempts to start vehicle's Engine" AND Remove this..



Source: Direct-Link to the Image
Reply
#2

Code EDITED found a small problem
pawn Код:
//put this somewhere at the bottume of your script
stock VehicleEngine(vehicleid,VAR)
{
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
if(VAR == 1)
    {
        new rand = random(4);//get a random number from 0-4 so we make the timer more realistic.
        new Frm[6];format(Frm,sizeof(Frm),"%d100",rand );//add the zeros at the end(changed to add "100" becouse the random might return a "0"
        SetTimerEx("StartEngine", strval(Frm), false, "ii", playerid,vehicleid);
       
    }else{
        SetVehicleParamsEx(vehicleid,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
    }
}
forward StartEngine(playerid,vehicleid);//start the engine after the random time
public StartEngine(playerid,vehicleid)
{
new engine,lights,alarm,doors,bonnet,boot,objective;
GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
SetVehicleParamsEx(vehicleid,VEHICLE_PARAMS_ON,lights,alarm,doors,bonnet,boot,objective);
return 1;
}
How to use this ?
Whenever you want to start the vehicles engine you do this:
Example
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
     VehicleEngine(vehicleid,true)
     return 1;
}
Reply
#3

I don't understand.. Should I put this in my Filterscript or Gamemode AND Where should I put this

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
     VehicleEngine(vehicleid,true)
     return 1;
}
Reply
#4

Replace this one...

Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
     VehicleEngine(vehicleid,true);
     return 1;
}
You forgot a token ^

Sorry for Double Post.
Reply
#5

That's an example I gave, what it will do is as soon as the player starts entering the vehicle the vehicles engine will turn on.
You can put
pawn Код:
VehicleEngine(vehicles,true/false);
Where ever you want in your script to toggle the vehicles engine, but you should know that the stock needs to be there as well in order for the function to work.
Reply
#6

I get an error.
Код:
C:\Users\Johan\Desktop\samp\gamemodes\vrc.pwn(1036) : error 017: undefined symbol "Strval"

Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#7

Quote:
Originally Posted by Lekinad
Посмотреть сообщение
I get an error.
Код:
C:\Users\Johan\Desktop\samp\gamemodes\vrc.pwn(1036) : error 017: undefined symbol "Strval"

Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Error.
sorry i edited my post its supposed to be a lower case letter !
pawn Код:
SetTimerEx("StartEngine", strval(Frm), false, "ii", playerid,vehicleid);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)