03.02.2009, 12:02
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:
Oh and thanks to Backwards for properly showing me how to use the "OnPlayerKeyStateChange". 10 points.
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