Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define FILTERSCRIPT
- #include <a_samp>
- #include <SIF/SIF>
- #include <strlib>
- #include <YSI\y_timers>
- #define KNIFE_AIR_VELOCITY (20.0) // (20.0)
- #define KNIFE_STEP_DISTANCE (2.0) // (20.0)
- #define KNIFE_STEP_LIMIT (10)
- stock Float:Distance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
- return floatsqroot((((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))+((z1-z2)*(z1-z2))));
- new
- ItemType: item_Knife = INVALID_ITEM_TYPE;
- static
- Timer: PlayerKnifeUpdateTimer[MAX_PLAYERS];
- public OnFilterScriptInit()
- {
- for(new i; i < MAX_PLAYERS; i++)
- Streamer_ToggleIdleUpdate(i, true);
- item_Knife = DefineItemType("Knife", 335, ITEM_SIZE_SMALL);
- new
- Float:x,
- Float:y,
- Float:z;
- GetPlayerPos(0, x, y, z);
- CreateItem(item_Knife, x, y, z - 0.8);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- Streamer_ToggleIdleUpdate(playerid, true);
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(newkeys & KEY_FIRE)
- {
- new
- itemid,
- ItemType:itemtype;
- itemid = GetPlayerItem(playerid);
- itemtype = GetItemType(itemid);
- if(itemtype == item_Knife)
- {
- new
- Float:x,
- Float:y,
- Float:z,
- Float:angle,
- objectid;
- GetPlayerPos(playerid, x, y, z);
- GetPlayerFacingAngle(playerid, angle);
- // Uncomment below to make knives consumable.
- // Comment to make them infinite
- DestroyItem(itemid);
- objectid = CreateDynamicObject(335, x, y, z + 0.3, 0.0, 0.0, angle + 90.0);
- ApplyAnimation(playerid, "GRENADE", "WEAPON_throw", 4.0, 0, 0, 0, 0, 0);
- PlayerKnifeUpdateTimer[playerid] = defer UpdateKnife(playerid, objectid, 0, 0, 100, angle);
- }
- }
- }
- timer UpdateKnife[c](playerid, objectid, a, b, c, Float:heading)
- {
- new
- Float:x,
- Float:y,
- Float:z,
- Float:rx,
- Float:ry,
- Float:rz;
- GetDynamicObjectPos(objectid, x, y, z);
- GetDynamicObjectRot(objectid, rx, ry, rz);
- c = MoveDynamicObject(objectid,
- x + (KNIFE_STEP_DISTANCE * floatsin(-heading, degrees)),
- y + (KNIFE_STEP_DISTANCE * floatcos(-heading, degrees)),
- z - 0.1, // Gravity
- KNIFE_AIR_VELOCITY,
- 0.0,
- ry + 179.0,
- heading + 90.0);
- if(b < KNIFE_STEP_LIMIT) // knife flies for KNIFE_STEP_LIMIT * 100 milliseconds.
- {
- a = !a;
- b++;
- PlayerKnifeUpdateTimer[playerid] = defer UpdateKnife(playerid, objectid, a, b, c, heading);
- }
- else
- {
- DestroyDynamicObject(objectid);
- CreateItem(item_Knife, x, y, z);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement