C4 System - Using Zcmd -
adri[4]Life - 12.05.2017
How To Make a C4 System
Introduction: Hello Guys, this is my first tutorial, This will show you how to make a Simple C4 System Along time Ago i Searched For One but i couldn't find a Tutorial But a Filterscript so Now i've decided To Make My Own One
How It Works?:
When The Player Type Plantc4 Command Server Will check if playerid have at Least One C4 & If he have no already planted C4 Then With PlantingC4 function It wil Get the player Position And Create an Object at playerid's co-ordinates & Toggle Player Controllable (player won't be able to do anything while planting C4) And apply BOMB Animation And it will give the player -1 C4 Finally The timer will start (2.5 seconds)
When the time is out (Timer will stop), The player's controllable will be set to 1 (Player is no longer frozen)
And Finally playerid will receive a Msg (You have successful Planted c4) .
Now We Have Planted The C4 & Applied animation And finally Sent the player MSG & given him -1 C4
It's time For making a CMD to detonate it:
When the player will type detonate CMD, Server will Get C4object's position Then Create Explosion at it's co-ordinates
And finally the C4object will disappear And Player's plantedc4 will be set To 0 (so he ll be able to plant C4s again)
Easy right? :d This is my way to create a C4 System it's not the best or the worst one.
We Have an easy way To Create that System, now it's time for coding it:
CODE:
Includes: (in the Top of the script)
Code:
#include <a_samp>
#include <zcmd>
We Will Need some colors define: (on the top of the script)
Code:
//Instead of writing the color code each time, we can just Define a name for the colors
#define COLOR_RED 0xFF0000FF
#define COLOR_GREEN 0x15FF00FF
#define COLOR_BLUE 0x0000BBFF
Needed Variables: (after the includes)
Code:
new C4[MAX_PLAYERS]; //For How many Are the C4s of the player :v
new plantedC4[MAX_PLAYERS]; //To Get If There is an already PlantedC4
new C4Object[MAX_PLAYERS]; //For The C4 Object
new C4Timer[MAX_PLAYERS]; //Timer for Planting
new StopC4Timer[MAX_PLAYERS]; //To Stop The Planting Timer:v
Forwards: (the top of the script After Includes too )
Code:
//Forwards Gives You the ability to Make the function wherever you want So There won't be a problem if u use Plantc4Timer After Or Before It's code
forward plantingC4(playerid);
forward PlantC4Timer(playerid);
We Will Have To Set Player's C4(Under OnplayerConnect):
Code:
public OnPlayerConnect(playerid)
{
C4[playerid] = 0; //When The Player Connects it Set his C4s to 0
return 1;
}
Now We Will Have to Give The Player a C4 When He spawns (Under OnPlayerSpawn):
Code:
OnPlayerSpawn(playerid)
{
C4[playerid] = 1; //To Set Player's C4s to 1 when he spawn
return 1;
}
We Have To Make a CMD For Planting a C4:
Code:
CMD:plantc4(playerid)
{
if(C4[playerid] == 0) return SendClientMessage(playerid, COLOR_RED,"ERROR: You Do Not Have C4 You Can Buy Ones From Briefcase Or Wait For The Next Spawn"); //If the player don't have C4 send him an error msg
if(plantedC4[playerid] == 1) return SendClientMessage(playerid, COLOR_RED,"You Already Planted a C4 Use /Detonate To Detonate it!"); //if the player has already planted a C4 Send him an error Msg :v
plantingC4(playerid);
return 1;
}
We Will need a function For the planting C4 player
Code:
plantingC4(playerid)
{
if(plantedC4[playerid] == 0)
{
new Float:x,Float:y,Float:z; //x,y,z Position For The C4 object
GetPlayerPos(playerid,x,y,z); //Get The Player's Position
C4Object[playerid] = CreateDynamicObject(1252,x,y,z-0.90,270.0,0.0,0.0); //Will Make The C4 Object In The Player's Positon
plantedC4[playerid]++; //To set player's Planted C4 to 1 (Max C4 planted is 1)
C4[playerid]--; //Give the player -1 C4
TogglePlayerControllable(playerid, 0); //To Toggle Controllable player
ApplyAnimation(playerid, "BOMBER", "BOM_Plant", 4.0, 0, 0, 0, 2500, 2000); //To Apply Bomber Animation For playerid
C4Timer[playerid] = SetTimerEx("PlantC4Timer",2500,1,"u",playerid); //To Set the toggled controllable player's delay
StopC4Timer[playerid] = 0; //Start the timer (read the other code for more explication)
}
}
Now Make This function which will Stop The PlantingC4 After 2.5 seconds
Code:
public PlantC4Timer(playerid)
{
if(StopC4Timer[playerid] == 0)
{
StopC4Timer[playerid]++; //To Stop the timer
TogglePlayerControllable(playerid, 1); //to toggle controllable back
SendClientMessage(playerid, COLOR_GREEN,"C4 Has Been Planted!"); //to Send player message
}
}
Now it's time for making a Cmd to detonate the C4
Code:
CMD:detonate(playerid)
{
if(plantedC4[playerid] != 1) return SendClientMessage(playerid, COLOR_RED,"ERROR: You Have To Plant C4 To Detonate it!"); //if the player didn't plant a C4 send him an error msg
new Float:x,Float:y,Float:z; //This will be used to get the C4 object position
plantedC4[playerid]--; //To Set The plantedC4 of playerid 0
GetDynamicObjectPos(C4Object[playerid], x, y, z); //To Get the C4 object position
CreateExplosion(x,y,z,2,50.0); //to create explosion in C4 position
DestroyDynamicObject(C4Object[playerid]); //to destroy C4 object
SendClientMessage(playerid, COLOR_BLUE,"C4 Has Been Detonated!"); //Send player msg that he successfully detonated the C4
return 1;
}
Now We Have to make another command To Buy C4 with :
Code:
CMD:buyc4(playerid)
{
if(GetPlayerMoney(playerid) < 5000) return SendClientMessage(playerid, COLOR_RED, "You Do Not Have Enough Money"); //To Get if the player have enough money
C4[playerid]++; //if player have enough money he ll get a C4
SendClientMessage(playerid, COLOR_BLUE,"You Have Bought a C4!"); // if player have enough money he ll receive a msg
return 1;
}
Hope this helps you
Credits:
-Adri1[4]Life For Coding This & For the tutorial
-Zeex For Zcmd
https://sampforum.blast.hk/showthread.php?tid=91354
-Kalcor & Samp Team For a_samp
Re: C4 System - Using Zcmd -
Hunud - 12.05.2017
Okey, from where should i start..
1. I'm not sure this is you're own work by checking you'r previous works and knownedge
2. Instead of copy/pasting, you could just try to explain to use each of these commands and their functions inside it, you've just explaini to use where should we place it and what we have to add!
-1 start
Re: C4 System - Using Zcmd -
adri[4]Life - 12.05.2017
Quote:
Originally Posted by Hunud
Okey, from where should i start..
1. I'm not sure this is you're own work by checking you'r previous works and knownedge
2. Instead of copy/pasting, you could just try to explain to use each of these commands and their functions inside it, you've just explaini to use where should we place it and what we have to add!
-1 start
|
First of all, if my previous works are bad that doesn't mean i'am unable to improve my scripting knowledge and will stay newbie forever You're making no sense buddy & this isn't reason to say that i have stolen the code
i Had No Free Time to Work hard On My From Scratch GameModes That's why i didn't release some of them here
And Being a good scripter doesn't mean you have to share all your good releases
second You Have to read the whole code before replying Look, Behind each function in the code, i explained the use of each function where and what should be added So i think i've added everything.
P.S: The Whole code Is Written by me but of course i checked some Examples of C4 systems to have some ideas about it Maybe it looks like another one's work Cause there are many C4 Systems
Re: C4 System - Using Zcmd -
Nakul - 12.05.2017
Good Job, well explained
Re: C4 System - Using Zcmd -
youssef2016 - 12.05.2017
Thx, I really needed it!
Re: C4 System - Using Zcmd -
JustMe.77 - 12.05.2017
Very weak "tutorial", 1 star.
Re: C4 System - Using Zcmd -
adri[4]Life - 12.05.2017
Quote:
Originally Posted by JustMe.77
Very weak "tutorial", 1 star.
|
instead of telling me very weak tutorial why don't u tell me how to improve it ?
Re: C4 System - Using Zcmd -
Vince - 12.05.2017
Quote:
Originally Posted by adrianlouise
instead of telling me very weak tutorial why don't u tell me how to improve it ? 
|
Start by not centering the entire thing. Makes it extremely annoying to read.
Quote:
Originally Posted by adrianlouise
add this(Under OnplayerConnect):
|
Quote:
Originally Posted by adrianlouise
Now Add This (Under OnPlayerSpawn):
|
Quote:
Originally Posted by adrianlouise
Add this command For C4 planting :
|
Quote:
Originally Posted by adrianlouise
You Have to add this Function :
|
"Add this" just teaches people to copy-paste. A good tutorial explains WHY you do something.
You'll know when you've advanced as a programmer/scripter when you start to question the WHY rather than the HOW.
Re: C4 System - Using Zcmd -
adri[4]Life - 12.05.2017
Quote:
Originally Posted by Vince
Start by not centering the entire thing. Makes it extremely annoying to read.
"Add this" just teaches people to copy-paste. A good tutorial explains WHY you do something.
You'll know when you've advanced as a programmer/scripter when you start to question the WHY rather than the HOW.
|
Thanks For The Advice Vince

Improved a little bit !
Re: C4 System - Using Zcmd -
Hansrutger - 13.05.2017
Regarding
Code:
public plantingC4(playerid)
https://sampwiki.blast.hk/wiki/Public_functions
I'd highly suggest to use dynamic objects also when it comes to these sort of things. Only use CreateObject for things that needs to be static, for instance floors where things shouldn't fall off (vehicles for instance).
Re: C4 System - Using Zcmd -
adri[4]Life - 13.05.2017
Quote:
Originally Posted by Hansrutger
Regarding
Code:
public plantingC4(playerid)
https://sampwiki.blast.hk/wiki/Public_functions
I'd highly suggest to use dynamic objects also when it comes to these sort of things. Only use CreateObject for things that needs to be static, for instance floors where things shouldn't fall off (vehicles for instance).
|
Done, thanks
Re: C4 System - Using Zcmd -
SyS - 13.05.2017
explaining the algorithm before introducing code would be better in my opinion
Re: C4 System - Using Zcmd -
adri[4]Life - 13.05.2017
Quote:
Originally Posted by SyS
explaining the algorithm before introducing code would be better in my opinion
|
Done Explained (in How It Works), Thanks!
Re: C4 System - Using Zcmd -
Bolex_ - 13.05.2017
Just fix these things up, and everything will be ok. Parameters aren't necessary, because you don't use them!
Solid tutorial as far, good for newbies 3 stars
Re: C4 System - Using Zcmd -
Misterenas - 13.05.2017
When it should explode?
Re: C4 System - Using Zcmd -
adri[4]Life - 13.05.2017
Quote:
Originally Posted by Misterenas
When it should explode?
|
When You type Detonate CMD :
Code:
CMD:detonate(playerid)
{
if(plantedC4[playerid] != 1) return SendClientMessage(playerid, COLOR_RED,"ERROR: You Have To Plant C4 To Detonate it!"); //if the player didn't plant a C4 send him an error msg
new Float:x,Float:y,Float:z; //This will be used to get the C4 object position
plantedC4[playerid]--; //To Set The plantedC4 of playerid 0
GetObjectPos(C4Object[playerid], x, y, z); //To Get the C4 object position
CreateExplosion(x,y,z,2,50.0); //to create explosion in C4 position
DestroyObject(C4Object[playerid]); //to destroy C4 object
SendClientMessage(playerid, COLOR_BLUE,"C4 Has Been Detonated!"); //Send player msg that he successfully detonated the C4
return 1;
}