SA-MP Forums Archive
Scripted Teargas - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Scripted Teargas (/showthread.php?tid=64322)



Scripted Teargas - Tannz0rz - 03.02.2009

Created a scripted teargas-like thing. The only problem that I'm currently having is defining this to the teargas weapon itself. While on foot, you can press the fire key with any weapon and it will do it. I originally thought that you have to use "GetWeaponName", but I can't seem to get it to work correctly.
If you dislike the order in which I have it set up, feel free to organize:
Код:
#include <a_samp>

#define FILTERSCRIPT
#define KEY_FOOT_FIRE 4
#define WEAPON_TEARGAS (17)

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Tear Gas Thing ");
	print("--------------------------------------\n");
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

new Smoke;
new Smoke2;
new Smoke3;
new Smoke4;
new Smoke5;

public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
{
	if((newkeys & KEY_FOOT_FIRE) == (KEY_FOOT_FIRE))
	{
	  if(!IsPlayerInAnyVehicle(playerid))
	  {
		  new Float:x, Float:y, Float:z, Float:a;
			GetPlayerPos(playerid, x, y, z);
			GetPlayerFacingAngle(playerid, a);
			x += (15 * floatsin(-a, degrees));
			y += (15 * floatcos(-a, degrees));
			Smoke = CreateObject(2780, x, y, z-3, 0.0, 0.0, 0.0);
			Smoke2 = CreateObject(2780, x, y+5, z-3, 0.0, 0.0, 0.0);
			Smoke3 = CreateObject(2780, x, y-5, z-3, 0.0, 0.0, 0.0);
			Smoke4 = CreateObject(2780, x+5, y, z-3, 0.0, 0.0, 0.0);
			Smoke5 = CreateObject(2780, x-5, y, z-3, 0.0, 0.0, 0.0);
			GetObjectPos(Smoke, x, y, z);
			GetObjectPos(Smoke2, x, y, z);
	        GetObjectPos(Smoke3, x, y, z);
	        GetObjectPos(Smoke4, x, y, z);
	        GetObjectPos(Smoke5, x, y, z);
			SetTimerEx("TearGasTimer2", 20000, 0, "d", playerid);

			if(IsPlayerInRangeOfPoint(playerid, 7, x, y, z))
			{
			  TogglePlayerControllable(playerid, 0);
				SetTimerEx("TearGasTimer", 20000, 0, "d", playerid);
				return 1;
			}
		}
	}
	return 0;
}

forward TearGasTimer(playerid);
public TearGasTimer(playerid)
{
	TogglePlayerControllable(playerid, 1);
	DestroyObject(Smoke);
	DestroyObject(Smoke2);
	DestroyObject(Smoke3);
	DestroyObject(Smoke4);
	DestroyObject(Smoke5);
	return 1;
}

forward TearGasTimer2(playerid);
public TearGasTimer2(playerid)
{
	DestroyObject(Smoke);
	DestroyObject(Smoke2);
	DestroyObject(Smoke3);
	DestroyObject(Smoke4);
	DestroyObject(Smoke5);
	return 1;
}

stock IsPlayerInRangeOfPoint(playerid, Float:range, Float:x, Float:y, Float:z)
{	// Created by ******

	new
		Float:px,
		Float:py,
		Float:pz;
	GetPlayerPos(playerid, px, py, pz);
	px -= x;
	py -= y;
	pz -= z;
	return ((px * px) + (py * py) + (pz * pz)) < (range * range);
}

#endif
Oh and thanks to Backwards for properly showing me how to use the "OnPlayerKeyStateChange". 10 points.


Re: Scripted Teargas - yezizhu - 03.02.2009

Never test but looks really nice^^
Why dont use animation instead of TogglePlayer and add DisablePlayerNameTag for better effect::P
REALLY NICE IDEA!


Re: Scripted Teargas - Ycto - 03.02.2009

You can use
Код:
GetPlayerWeapon(playerid)
Use it like
pawn Код:
if(GetPlayerWeapon(playerid) == [Insert Teargas Weapon ID Here])
{
Your code...
}
Sorry, was too lazy to look for the weapon ID myself :P It's on the wiki.

You could also just change
pawn Код:
if(!IsPlayerInAnyVehicle(playerid))
{
with

pawn Код:
if(!IsPlayerInAnyVehicle(playerid) && GetPlayerWeapon(playerid) == [Insert Teargas Weapon ID Here])
{
Don't know that last thing for sure though, didn't really look into your script =)


Re: Scripted Teargas - Tannz0rz - 03.02.2009

Thanks a lot.


Re: Scripted Teargas - Tannz0rz - 04.02.2009

Quote:
Originally Posted by yezizhu
Never test but looks really nice^^
Why dont use animation instead of TogglePlayer and add DisablePlayerNameTag for better effect::P
REALLY NICE IDEA!
The server that I'm going to be using this on doesn't have name tags to begin with. Feel free to use it if you want.


Re: Scripted Teargas - Karlip - 04.02.2009

Make it give the ''Choking'' animation,(The animation that comes when u spray someone with a spray can or extinguisher) instead of freezing.


Re: Scripted Teargas - Tannz0rz - 04.02.2009

SA:MP Wiki is down, do you happen to know the animation ID and name? lulz.