[Tutorial] C4 System - Using Zcmd
#1

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

Reply


Messages In This Thread
C4 System - Using Zcmd - by adrianlouise - 12.05.2017, 16:12
Re: C4 System - Using Zcmd - by Hunud - 12.05.2017, 17:36
Re: C4 System - Using Zcmd - by adrianlouise - 12.05.2017, 17:46
Re: C4 System - Using Zcmd - by Nakul - 12.05.2017, 18:16
Re: C4 System - Using Zcmd - by youssef2016 - 12.05.2017, 18:42
Re: C4 System - Using Zcmd - by JustMe.77 - 12.05.2017, 19:16
Re: C4 System - Using Zcmd - by adrianlouise - 12.05.2017, 19:16
Re: C4 System - Using Zcmd - by Vince - 12.05.2017, 19:54
Re: C4 System - Using Zcmd - by adrianlouise - 12.05.2017, 19:58
Re: C4 System - Using Zcmd - by Hansrutger - 13.05.2017, 00:03
Re: C4 System - Using Zcmd - by adrianlouise - 13.05.2017, 10:54
Re: C4 System - Using Zcmd - by SyS - 13.05.2017, 11:29
Re: C4 System - Using Zcmd - by adrianlouise - 13.05.2017, 13:33
Re: C4 System - Using Zcmd - by Bolex_ - 13.05.2017, 17:10
Re: C4 System - Using Zcmd - by Misterenas - 13.05.2017, 19:53
Re: C4 System - Using Zcmd - by adrianlouise - 13.05.2017, 19:55

Forum Jump:


Users browsing this thread: 1 Guest(s)