17.09.2011, 16:28
MAKING OUR OWN SPEEDCAMERAS
WHAT?
Hello, and welcome to my tutorial.
I'll be showing you how to make your own speedcameras, WITH LOTS OF ADDITIONS
Yes, that's right, with lots of additions.
WHY?
Well this is actually scripted for my own server.
First I decided to just download a speedcamera script/include, and create my cameras ingame...
Very soon already it seemed that both of the available speedcam scripts on this forums did not work... (I don't know if it works for you, but for me it doesn't)
I kept having problems with it so, I started to get mad and before I almost broke my laptop out of rageness I decided to create my own...
NOTE: I have been inspired by the gCamera INCLUDE (wich did not work for me), so you might find some idea's in the gCamera script in here too...
An other advantage of creating your own SpeedCam script is that you can add alot of stuff that you need in your GM.
F.E: You want that when a player gets caught by a speedcam his wanted level will increase if he does not pay...
If you want that addition in the gCamera script you will have to edit the include, wich is not such a good idea since it's quiet easy to mess up the entire include like that...
STEP 1 |Objects and defines|
First of all we are going to create the objects, the speedcams itself.
This is not needed but it's kinda stupid if the player will be caught by a speedtrap, when he can't see a speedtrap at all...
So for the Object we'll use objectid 18880.
This object is almost a perfect copy of a real life speedcamera...
This is just the perfect object for creating this script...
But here we have our first problem already... This object only supports 0.3C
Wich means that you cannot make the map with MTA map editor since it hasn't the 0.3C objects included...
So we'll need another Object Editor.
I recommend GarObject(by Garsino, an awesome scripter!): http://forum.sa-mp.com/showthread.ph...ight=GarObject
Follow the instructions to download and install.
Go ingame and use the functions to create the objects.
Remember the object we are going to use is objectid 18880
NOTE: It's important to make either the 90KPH speedcams or the 120 speedcams map first, do not put both cam types in one map, since it will be very confusing for u to work with later on, in our GM.
An other option to make the map is using this object editor: https://sampforum.blast.hk/showthread.php?tid=282801
but I have no idea how to work with that one...
Ok, so another thing wich is standard when making a new script are Variables/Defines
here is a list of Variables we are going to use:
just add under the defines. it's a variable to store the player's speed in
another variable, to define the ticket price
add this one under our prev variable. You'll know why we are going to use it later on...
now add this:
under OnPlayerConnect...
ok, next we'll need a define:
add this above our new stuff...
just copy this, this will set the dialogid of our dialog we are going to use.
STEP 2 |Objects_part 2|
Now we are going to add the objects in our GM.
Ok, so open your GM/FS and add this under the defines in your script:
Replace the x,y,z with the x,y,z from your objects you have created with the map Editor.
change [3]/[2] into the amount of objects.
There are 2 Float:Gobjects here.
one for the 90 KPH speedcams and one for the 120KPH speedcams
Next we are going to our OnGameModeInit (OnFilterScriptInit if you are using a FS) callback and add this:
IMPORTANT: You have to copy the CreateObject stuff u got from your map editor, the chords that are shown here, are just my speedcams... SO DO NOT JUST COPY THIS You will see the speedcams in the wrong position...
STEP 3 |SCRIPT|
Ok, now we are going to script the speedcam stuff...
so, we need something that checks if the player is near one of our speedcams and if the player is driving to fast...
To make this, the best callback to use is OnPlayerUpdate
Wich gets called every 0.5 seconds I guess...
will look like this:
So, let's first make the 90KPH speedcams...
Add this under
OnPlayerUpdate
{
ok so let's start explaining...
This is a loop that will loop through all our gObjects90
This is where our new gObjects90[3][3] is for...
This makes that we can only continue if the player is near our x,y,z chord of our gObjects90
The [0] stands for the x chord
The [1] for the y
and the [2] for the z
This will add a second if statement to our previous, IsPlayerInRangeOfPoint if statement.
This if statement will make sure that the player can only be caught by a speedtrap when he/she is in a vehicle...
this will add a 3rd if statement
This will make sure that passengers won't be caught too...
ok, so this is our following code we are going to put under our previous code...
I'll explain why we need this variable later on...
NOTE: THIS IS OPTIONAL
This will make that a cop cannot be caught by speedtraps, since he's a cop...
change TEAM_COPS in what you defined as the team of the cops in your script...
if you do not want this addition, then just don't add it...
Next code we need:
Ok, now this code is needed to find out what speed you are driving...
Now you can check the player's speed using, final_speed_int.
Explaining all this will be hard, so I recomend you to just copy it...
next code we'll need:
Will create an if statement to check if the player is driving faster than 90KPH...
just to make it look better...
ok so this will create a message that says you were driving to fast...
The money you will have to pay is the player's speed doubled...
string formulas:
just tells how fast you were driving when the cam got you
will tell the player he has to pay the double of their speed...
This will send the player the message that we have just created above...
Creates a fancy GameText, it's always fun to have some fancy in our scripts, isn't it?
This will make a good looking message that the player will get in their dialog
The amount that the player will have to pay...
telling the player how much faster he drove than the allowed speed...
Will show the player a dialog, where he can either choose to pay the ticket or to not pay the ticket...
Change "pay" and "fuckoff!" in to whatever you want to insert in the little tabs.
Will call the function to create the flash [inspired by gCamera FS]
used to reset the variable I did not explain yet......
the variable i'll explain later
will define the price you have to pay, will be easier to use when we make dialog response...
ok, so next you just have to close all the statements...
and you will have this:
STEP 4 |FLASH|
Ok, so now we are going to add something that the player will see a flash when he gets caught...
(inspired by gCamera)
For that we are going to need this code:
Add this somewhere in your script
shows the flash textdraw...
BUT we did not make this yet, so let's quick do that...
make a new thing:
and add this under OnGameModeInit (OnFilterScriptInit for FS)
ok, so now we have our flash textdraw created...
let's continue explaining:
will show our just created white screen...
this will set a timer, to remove our flash.
the flash will be removed after 1200 miliseconds (= 1.2 secs)
add this under our camflash(playerid)
this will simple hide our white flash...
STEP 5 |Dialog|
Ok, we are almost finished, now we just have to make the dialog where the player can either choose to pay or not pay the ticket he has recieved...
for that we go to OnDialogResponse
and add this:
ok, let's explain:
if statement to check if the dialog is our created dialog... just copy
if statement, wich is called when the player hits the "fuck off" button (decline button)
New stuff to track the name when someone hits fuck off...
here we make, the string.
the first one stands for the name, we have just created
the second one for the playerid...
sends everyone the message
NOTE: in my script it's SendClientMessageToAllCops(string);
if you have sendclientmessagetoallcops too use that one...
Just a message that the player has ignored their ticket, and that their wanted level has increased.
Increase the wanted level...
statement to be called when the player hits "pay"
simple message
sets the player money to ticket wich we defined earlier (the final speed doubled)
now, just close our brackets and we are done...
the last thing should look like this now:
STEP 6 |Adding another type of speedcam|
if you wanna use 120 KPH speedcams too, just do the same as we did for the 90KPH but change some stuff...
it should look like this:
add this under our previous thing under OnPlayerUpdate
and under OnDialogResponse add this:
FINAL STEP |that variable|
almost forgot. we need this: too
add this anywhere in your GM/FS
its that one never explained variable...
Why do we need this?
Well we need it to avoid a player getting caught by a speedtrap twice...
IMPORTANT
all things in this script like COLOR_RED (f.E.)
you have to either change in a hex color code or in the already defined code for your color...
otherwise you will get error:
Thanks for reading, hope you enjoyed.
NOTE
I believe that this is not the most efficient way of doing this, but it works... that's the most important.
Feel free to ask me anything about this script, in the comment section.
Byebye
Hello, and welcome to my tutorial.
I'll be showing you how to make your own speedcameras, WITH LOTS OF ADDITIONS
Yes, that's right, with lots of additions.
WHY?
Well this is actually scripted for my own server.
First I decided to just download a speedcamera script/include, and create my cameras ingame...
Very soon already it seemed that both of the available speedcam scripts on this forums did not work... (I don't know if it works for you, but for me it doesn't)
I kept having problems with it so, I started to get mad and before I almost broke my laptop out of rageness I decided to create my own...
NOTE: I have been inspired by the gCamera INCLUDE (wich did not work for me), so you might find some idea's in the gCamera script in here too...
An other advantage of creating your own SpeedCam script is that you can add alot of stuff that you need in your GM.
F.E: You want that when a player gets caught by a speedcam his wanted level will increase if he does not pay...
If you want that addition in the gCamera script you will have to edit the include, wich is not such a good idea since it's quiet easy to mess up the entire include like that...
STEP 1 |Objects and defines|
First of all we are going to create the objects, the speedcams itself.
This is not needed but it's kinda stupid if the player will be caught by a speedtrap, when he can't see a speedtrap at all...
So for the Object we'll use objectid 18880.
This object is almost a perfect copy of a real life speedcamera...
This is just the perfect object for creating this script...
But here we have our first problem already... This object only supports 0.3C
Wich means that you cannot make the map with MTA map editor since it hasn't the 0.3C objects included...
So we'll need another Object Editor.
I recommend GarObject(by Garsino, an awesome scripter!): http://forum.sa-mp.com/showthread.ph...ight=GarObject
Follow the instructions to download and install.
Go ingame and use the functions to create the objects.
Remember the object we are going to use is objectid 18880
NOTE: It's important to make either the 90KPH speedcams or the 120 speedcams map first, do not put both cam types in one map, since it will be very confusing for u to work with later on, in our GM.
An other option to make the map is using this object editor: https://sampforum.blast.hk/showthread.php?tid=282801
but I have no idea how to work with that one...
Ok, so another thing wich is standard when making a new script are Variables/Defines
here is a list of Variables we are going to use:
pawn Code:
new final_speed_int[MAX_PLAYERS];
pawn Code:
new ticket;
pawn Code:
new IsFlashed[MAX_PLAYERS];
now add this:
pawn Code:
IsFlashed[playerid] = 0;
ok, next we'll need a define:
pawn Code:
#define DIALOG_PAYME 2000
just copy this, this will set the dialogid of our dialog we are going to use.
STEP 2 |Objects_part 2|
Now we are going to add the objects in our GM.
Ok, so open your GM/FS and add this under the defines in your script:
pawn Code:
new Float:gObjects90[3][3] = {
{x, y, z},//90
{x, y, z},//90
{x, y, z}//90
};
new Float:gObjects120[2][3] = {
{x, y, z},//120
{x, y, z}//120
};
change [3]/[2] into the amount of objects.
There are 2 Float:Gobjects here.
one for the 90 KPH speedcams and one for the 120KPH speedcams
Next we are going to our OnGameModeInit (OnFilterScriptInit if you are using a FS) callback and add this:
pawn Code:
CreateObject(18880, 389.719177, -1357.502197, 13.781053, 0.000000, 0.000000, 300.000000);//90
CreateObject(18880, 399.502044, -1709.362670, 7.488409, 0.000000, 0.000000, 90.000000);//90
CreateObject(18880, 1103.722290, -941.490173, 41.883827, 0.000000, 0.000000, 270.000000);//90
CreateObject(18880, 1030.329345, -2237.417968, 12.163574, 0.000000, 0.000000, 20.000000);//120
CreateObject(18880, 2563.883544, -2163.019531, 12.190097, 0.000000, 0.000000, 90.000000);//120
STEP 3 |SCRIPT|
Ok, now we are going to script the speedcam stuff...
so, we need something that checks if the player is near one of our speedcams and if the player is driving to fast...
To make this, the best callback to use is OnPlayerUpdate
Wich gets called every 0.5 seconds I guess...
will look like this:
pawn Code:
//==============================================================================
//90 Speedcams
//==============================================================================
for(new i; i != sizeof gObjects90; ++i) {
if(IsPlayerInRangeOfPoint(playerid, 25.0, gObjects90[i][0], gObjects90[i][1], gObjects90[i][2]) && IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0) {
if(IsFlashed[playerid] == 0)
{
if(gTeam[playerid] == TEAM_COPS)
{
SendClientMessage(playerid,COLOR_LIGHTBLUE, "* Since you are a cop, you cannot be caught by speedtraps.");
IsFlashed[playerid] = 1;
return 1;
}
else
{
new Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[300],/*final_speed_int,*/speed_string2[300];
new vehicleid;
vehicleid = GetPlayerVehicleID(playerid);
GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136.666667;
final_speed_int[playerid] = floatround(final_speed,floatround_round);
if(final_speed_int[playerid] > 90)
{
SendClientMessage(playerid,COLOR_RED, " ");
format(speed_string,300,"* U were driving {FF6347}%i{FF0000}, while U were only allowed to drive {FF6347}90{FF0000}KPH, For that U must pay: ${FF6347}%i{FF0000}",final_speed_int[playerid], final_speed_int[playerid]*2);
SendClientMessage(playerid,COLOR_RED, speed_string);
GameTextForPlayer(playerid,"~r~B~y~U~b~S~g~T~w~E~p~D",5000,3);
format(speed_string2,300,"{FFFFFF}U must pay: ${FF6347}%i{FFFFFF}\nBecause You were Driving {FF6347}%i KPH{FFFFFF} Faster than allowed!\n\nIf you don't pay, U will becoma a suspect!",final_speed_int[playerid]*2,final_speed_int[playerid]-90);
ShowPlayerDialog(playerid,DIALOG_PAYME,DIALOG_STYLE_MSGBOX,"Speed Cam",speed_string2,"Pay","Fuck off!");
camflash(playerid);
SetTimerEx("resflashed",3000,false,"i",playerid);
IsFlashed[playerid] = 1;
ticket = final_speed_int[playerid]*2;
}
}
}
}
}
Add this under
OnPlayerUpdate
{
pawn Code:
//==============================================================================
//90 Speedcams
//==============================================================================
for(new i; i != sizeof gObjects90; ++i) {
if(IsPlayerInRangeOfPoint(playerid, 25.0, gObjects90[i][0], gObjects90[i][1], gObjects90[i][2]) && IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0) {
pawn Code:
for(new i; i != sizeof gObjects90; ++i) {
This is where our new gObjects90[3][3] is for...
pawn Code:
if(IsPlayerInRangeOfPoint(playerid, 25.0, gObjects90[i][0], gObjects90[i][1], gObjects90[i][2])
The [0] stands for the x chord
The [1] for the y
and the [2] for the z
pawn Code:
&& IsPlayerInAnyVehicle(playerid))
This if statement will make sure that the player can only be caught by a speedtrap when he/she is in a vehicle...
pawn Code:
&& GetPlayerVehicleSeat(playerid) == 0) {
This will make sure that passengers won't be caught too...
pawn Code:
if(IsFlashed[playerid] == 0)
{
if(gTeam[playerid] == TEAM_COPS)
{
SendClientMessage(playerid,COLOR_LIGHTBLUE, "* Since you are a cop, you cannot be caught by speedtraps.");
IsFlashed[playerid] = 1;
return 1;
}
else
{
}
pawn Code:
if(IsFlashed[playerid] == 0)
pawn Code:
if(gTeam[playerid] == TEAM_COPS)
{
SendClientMessage(playerid,COLOR_LIGHTBLUE, "* Since you are a cop, you cannot be caught by speedtraps.");
IsFlashed[playerid] = 1;
return 1;
}
else
{
This will make that a cop cannot be caught by speedtraps, since he's a cop...
change TEAM_COPS in what you defined as the team of the cops in your script...
if you do not want this addition, then just don't add it...
Next code we need:
pawn Code:
new Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[300],speed_string2[300];
new vehicleid;
vehicleid = GetPlayerVehicleID(playerid);
GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136.666667;
final_speed_int[playerid] = floatround(final_speed,floatround_round);
Now you can check the player's speed using, final_speed_int.
Explaining all this will be hard, so I recomend you to just copy it...
next code we'll need:
pawn Code:
if(final_speed_int[playerid] > 90)
{
SendClientMessage(playerid,COLOR_RED, " ");
format(speed_string,300,"* U were driving {FF6347}%i{FF0000}, while U were only allowed to drive {FF6347}90{FF0000}KPH, For that U must pay: ${FF6347}%i{FF0000}",final_speed_int[playerid], final_speed_int[playerid]*2);
SendClientMessage(playerid,COLOR_RED, speed_string);
GameTextForPlayer(playerid,"~r~B~y~U~b~S~g~T~w~E~p~D",5000,3);
format(speed_string2,300,"{FFFFFF}U must pay: ${FF6347}%i{FFFFFF}\nBecause You were Driving {FF6347}%i KPH{FFFFFF} Faster than allowed!\n\nIf you don't pay, U will becoma a suspect!",final_speed_int[playerid]*2,final_speed_int[playerid]-90);
ShowPlayerDialog(playerid,DIALOG_PAYME,DIALOG_STYLE_MSGBOX,"Speed Cam",speed_string2,"Pay","Fuck off!");
camflash(playerid);
SetTimerEx("resflashed",3000,false,"i",playerid);
IsFlashed[playerid] = 1;
ticket = final_speed_int[playerid]*2;
}
pawn Code:
if(final_speed_int[playerid] > 90)
{
pawn Code:
SendClientMessage(playerid,COLOR_RED, " ");
pawn Code:
format(speed_string,300,"* U were driving {FF6347}%i{FF0000}, while U were only allowed to drive {FF6347}90{FF0000}KPH, For that U must pay: ${FF6347}%i{FF0000}",final_speed_int[playerid], final_speed_int[playerid]*2);
The money you will have to pay is the player's speed doubled...
string formulas:
Code:
final_speed_int[playerid]
Code:
final_speed_int[playerid]*2
pawn Code:
SendClientMessage(playerid,COLOR_RED, speed_string);
pawn Code:
GameTextForPlayer(playerid,"~r~B~y~U~b~S~g~T~w~E~p~D",5000,3);
pawn Code:
format(speed_string2,300,"{FFFFFF}U must pay: ${FF6347}%i{FFFFFF}\nBecause You were Driving {FF6347}%i KPH{FFFFFF} Faster than allowed!\n\nIf you don't pay, U will becoma a suspect!",final_speed_int[playerid]*2,final_speed_int[playerid]-90);
Code:
final_speed_int[playerid]*2
Code:
final_speed_int[playerid]-90
pawn Code:
ShowPlayerDialog(playerid,DIALOG_PAYME,DIALOG_STYLE_MSGBOX,"Speed Cam",speed_string2,"Pay","Fuck off!");
Change "pay" and "fuckoff!" in to whatever you want to insert in the little tabs.
pawn Code:
camflash(playerid);
pawn Code:
SetTimerEx("resflashed",3000,false,"i",playerid);
pawn Code:
IsFlashed[playerid] = 1;
pawn Code:
ticket = final_speed_int[playerid]*2;
ok, so next you just have to close all the statements...
and you will have this:
pawn Code:
for(new i; i != sizeof gObjects90; ++i) {
if(IsPlayerInRangeOfPoint(playerid, 25.0, gObjects90[i][0], gObjects90[i][1], gObjects90[i][2]) && IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0) {
if(IsFlashed[playerid] == 0)
{
if(gTeam[playerid] == TEAM_COPS)
{
SendClientMessage(playerid,COLOR_LIGHTBLUE, "* Since you are a cop, you cannot be caught by speedtraps.");
IsFlashed[playerid] = 1;
return 1;
}
else
{
new Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[300],/*final_speed_int,*/speed_string2[300];
new vehicleid;
vehicleid = GetPlayerVehicleID(playerid);
GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136.666667;
final_speed_int[playerid] = floatround(final_speed,floatround_round);
if(final_speed_int[playerid] > 90)
{
SendClientMessage(playerid,COLOR_RED, " ");
format(speed_string,300,"* U were driving {FF6347}%i{FF0000}, while U were only allowed to drive {FF6347}90{FF0000}KPH, For that U must pay: ${FF6347}%i{FF0000}",final_speed_int[playerid], final_speed_int[playerid]*2);
SendClientMessage(playerid,COLOR_RED, speed_string);
GameTextForPlayer(playerid,"~r~B~y~U~b~S~g~T~w~E~p~D",5000,3);
format(speed_string2,300,"{FFFFFF}U must pay: ${FF6347}%i{FFFFFF}\nBecause You were Driving {FF6347}%i KPH{FFFFFF} Faster than allowed!\n\nIf you don't pay, U will becoma a suspect!",final_speed_int[playerid]*2,final_speed_int[playerid]-90);
ShowPlayerDialog(playerid,DIALOG_PAYME,DIALOG_STYLE_MSGBOX,"Speed Cam",speed_string2,"Pay","Fuck off!");
camflash(playerid);
SetTimerEx("resflashed",3000,false,"i",playerid);
IsFlashed[playerid] = 1;
ticket = final_speed_int[playerid]*2;
}
}
}
}
}
STEP 4 |FLASH|
Ok, so now we are going to add something that the player will see a flash when he gets caught...
(inspired by gCamera)
For that we are going to need this code:
pawn Code:
// =============================================================================
// CamFlash Function
// =============================================================================
camflash(playerid)
{
TextDrawShowForPlayer(playerid,flash);
SetTimerEx("RemoveFlash",1200,false,"i",playerid);
//Code
}
forward RemoveFlash(playerid);
public RemoveFlash(playerid)
{
TextDrawHideForPlayer(playerid,flash);
}
pawn Code:
camflash(playerid)
pawn Code:
TextDrawShowForPlayer(playerid,flash);
BUT we did not make this yet, so let's quick do that...
make a new thing:
pawn Code:
new Text:flash;
pawn Code:
flash = TextDrawCreate(-20.000000,2.000000,"|");
TextDrawUseBox(flash,1);
TextDrawBoxColor(flash,0xffffff66);
TextDrawTextSize(flash,660.000000,22.000000);
TextDrawAlignment(flash,0);
TextDrawBackgroundColor(flash,0x000000ff);
TextDrawFont(flash,3);
TextDrawLetterSize(flash,1.000000,52.200000);
TextDrawColor(flash,0xffffffff);
TextDrawSetOutline(flash,1);
TextDrawSetProportional(flash,1);
TextDrawSetShadow(flash,1);
let's continue explaining:
pawn Code:
TextDrawShowForPlayer(playerid,flash);
pawn Code:
SetTimerEx("RemoveFlash",1200,false,"i",playerid);
the flash will be removed after 1200 miliseconds (= 1.2 secs)
pawn Code:
forward RemoveFlash(playerid);
public RemoveFlash(playerid)
{
TextDrawHideForPlayer(playerid,flash);
}
this will simple hide our white flash...
STEP 5 |Dialog|
Ok, we are almost finished, now we just have to make the dialog where the player can either choose to pay or not pay the ticket he has recieved...
for that we go to OnDialogResponse
and add this:
pawn Code:
//==============================================================================
//Pay ticket when flashed
//==============================================================================
if(dialogid == DIALOG_PAYME)
{
if(!response)
{
new name[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "%s(%d) has ignored their ticket for driving to fast. Get that idiot!",name,playerid);
SendClientMessageToAllCops(string);
SendClientMessage(playerid,COLOR_ORANGE,"You have ignored your ticket, and your wanted level has increased by 2!");
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 2);
}
else
{
SendClientMessage(playerid,COLOR_SEXYGREEN,"You have paid your ticket!");
GivePlayerMoney(playerid,-ticket);
}
}
pawn Code:
if(dialogid == DIALOG_PAYME)
pawn Code:
if(!response)
pawn Code:
new name[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, name, sizeof(name));
pawn Code:
format(string, sizeof(string), "%s(%d) has ignored their ticket for driving to fast. Get that idiot!",name,playerid);
the first one stands for the name, we have just created
the second one for the playerid...
pawn Code:
SendClientMessageToAll(string);
NOTE: in my script it's SendClientMessageToAllCops(string);
if you have sendclientmessagetoallcops too use that one...
pawn Code:
SendClientMessage(playerid,COLOR_ORANGE,"You have ignored your ticket, and your wanted level has increased by 2!");
pawn Code:
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 2);
pawn Code:
}
else
{
pawn Code:
SendClientMessage(playerid,COLOR_SEXYGREEN,"You have paid your ticket!");
pawn Code:
SetPlayerMoney(playerid,GetPlayerMoney(playerid)-ticket);
now, just close our brackets and we are done...
the last thing should look like this now:
pawn Code:
//==============================================================================
//Pay ticket when flashed
//==============================================================================
if(dialogid == DIALOG_PAYME)
{
if(!response)
{
new name[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "%s(%d) has ignored their ticket for driving to fast. Get that idiot!",name,playerid);
SendClientMessageToAllCops(string);
SendClientMessage(playerid,COLOR_ORANGE,"You have ignored your ticket, and your wanted level has increased by 2!");
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 2);
}
else
{
SendClientMessage(playerid,COLOR_SEXYGREEN,"You have paid your ticket!");
GivePlayerMoney(playerid,-ticket);
}
}
STEP 6 |Adding another type of speedcam|
if you wanna use 120 KPH speedcams too, just do the same as we did for the 90KPH but change some stuff...
it should look like this:
pawn Code:
//==============================================================================
//120 Speedcams
//==============================================================================
for(new i; i != sizeof gObjects120; ++i) {
if(IsPlayerInRangeOfPoint(playerid, 25.0, gObjects90[i][0], gObjects90[i][1], gObjects90[i][2]) && IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0) {
if(IsFlashed[playerid] == 0)
{
if(gTeam[playerid] == TEAM_COPS)
{
SendClientMessage(playerid,COLOR_LIGHTBLUE, "* Since you are a cop, you cannot be caught by speedtraps.");
IsFlashed[playerid] = 1;
return 1;
}
else
{
new Float:speed_x,Float:speed_y,Float:speed_z,Float:final_speed,speed_string[300],/*final_speed_int,*/speed_string2[300];
new vehicleid;
vehicleid = GetPlayerVehicleID(playerid);
GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
final_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136.666667;
final_speed_int[playerid] = floatround(final_speed,floatround_round);
if(final_speed_int[playerid] > 120)
{
SendClientMessage(playerid,COLOR_RED, " ");
format(speed_string,300,"* U were driving {FF6347}%i{FF0000}, while U were only allowed to drive {FF6347}120{FF0000}KPH, For that U must pay: ${FF6347}%i{FF0000}",final_speed_int[playerid], final_speed_int[playerid]*2);
SendClientMessage(playerid,COLOR_RED, speed_string);
GameTextForPlayer(playerid,"~r~B~y~U~b~S~g~T~w~E~p~D",5000,3);
format(speed_string2,300,"{FFFFFF}U must pay: ${FF6347}%i{FFFFFF}\nBecause You were Driving {FF6347}%i KPH{FFFFFF} Faster than allowed!\n\nIf you don't pay, U will becoma a suspect!",final_speed_int[playerid]*2,final_speed_int[playerid]-120);
ShowPlayerDialog(playerid,DIALOG_PAYME+2,DIALOG_STYLE_MSGBOX,"Speed Cam",speed_string2,"Pay","Fuck off!");
camflash(playerid);
SetTimerEx("resflashed",3000,false,"i",playerid);
IsFlashed[playerid] = 1;
ticket = final_speed_int[playerid]*2;
}
}
}
}
}
and under OnDialogResponse add this:
pawn Code:
if(dialogid == DIALOG_PAYME+2)
{
if(!response)
{
new name[MAX_PLAYER_NAME], string[128];
GetPlayerName(playerid, name, sizeof(name));
format(string, sizeof(string), "%s(%d) has ignored their ticket for driving to fast. Get that idiot!",name,playerid);
SendClientMessageToAllCops(string);
SendClientMessage(playerid,COLOR_ORANGE,"You have ignored your ticket, and your wanted level has increased by 2!");
SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid) + 2);
}
else
{
SendClientMessage(playerid,COLOR_SEXYGREEN,"You have paid your ticket!");
SetPlayerMoney(playerid,GetPlayerMoney(playerid)-ticket);
}
}
FINAL STEP |that variable|
almost forgot. we need this: too
pawn Code:
forward resflashed(playerid);
public resflashed(playerid)
{
IsFlashed[playerid] = 0;
}
its that one never explained variable...
Why do we need this?
Well we need it to avoid a player getting caught by a speedtrap twice...
IMPORTANT
all things in this script like COLOR_RED (f.E.)
you have to either change in a hex color code or in the already defined code for your color...
otherwise you will get error:
Code:
undefined symbol: COLOR_RED
NOTE
I believe that this is not the most efficient way of doing this, but it works... that's the most important.
Feel free to ask me anything about this script, in the comment section.
Byebye