21.04.2015, 17:18
Quote:
Parabйns, bom trabalho. Deveria tentar(de novo) fazer para aqueles de mira fixa.
|
Code:
#define WEAPON_MODE_RELEASE 0 #define WEAPON_MODE_HOLD 1 #define WEAPON_MODE_AIM 2 #define PRESSED(%0) \ (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) #define RELEASED(%0) \ (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0))) forward CheckAimLock(playerid); enum TargetInfo { targetid, Float:pos_x, Float:pos_y, Float:pos_z } new AimLockTarget[MAX_PLAYERS][TargetInfo]; new bool:IsPlayerAiming[MAX_PLAYERS]; new AimLockCheck[MAX_PLAYERS]; new AimAccuracy[MAX_PLAYERS]; GetPlayerSpeed(playerid) { new Float:vx, Float:vy, Float:vz; GetPlayerVelocity(playerid, vx, vy, vz); return floatsqroot(floatpower(vx, 2) + floatpower(vy, 2) + floatpower(vz, 2)); } public OnPlayerConnect(playerid) { AimLockTarget[playerid][targetid] = -1; AimLockTarget[playerid][pos_x] = -1.0; AimLockTarget[playerid][pos_y] = -1.0; AimLockTarget[playerid][pos_z] = -1.0; IsPlayerAiming[playerid] = false; AimAccuracy[playerid] = 0; return 1; } public OnPlayerKeyStateChange(playerid, oldkeys, newkeys) { new weapon = GetPlayerWeapon(playerid); if(RELEASED(KEY_AIM) && && IsPlayerAiming[playerid] && !IsPlayerInAnyVehicle(playerid)) { IsPlayerAiming[playerid] = false; OnPlayerAim(playerid, weapon, WEAPON_MODE_RELEASE); return 1; } if(PRESSED(KEY_AIM) && !IsPlayerAiming[playerid] && !IsPlayerInAnyVehicle(playerid))//detect if player is holding aim { switch(weapon) { case 22..34, 38: { IsPlayerAiming[playerid] = true; OnPlayerAim(playerid, weapon, WEAPON_MODE_HOLD); } } return 1; } if(newkeys & KEY_AIM && !IsPlayerAiming[playerid] && !IsPlayerInAnyVehicle(playerid))//detect if player is holding aim { switch(weapon) { case 22..34, 38: { IsPlayerAiming[playerid] = true; OnPlayerAim(playerid, weapon, WEAPON_MODE_AIM); } } return 1; } return 1; } forward OnPlayerAim(playerid, &weapon, &mode); public OnPlayerAim(playerid, &weapon, &mode) { if(!mode) { AimLockTarget[playerid][targetid] = -1; AimLockTarget[playerid][pos_x] = -1.0; AimLockTarget[playerid][pos_y] = -1.0; AimLockTarget[playerid][pos_z] = -1.0; return KillTimer(AimLockCheck[playerid]); } switch(weapon) { case 22..33: { AimLockCheck[playerid] = SetTimerEx("CheckAimlock", 100, true, "i", playerid); } } return 1; } /*----------------> events <-------------------*/ public OnPlayerDeath(playerid, killerid, weapon) { return 1; } public OnPlayerDisconnect(playerid) { return 1; } /*---------------------------------------------*/ public CheckAimLock(playerid) { if(!IsPlayerAiming(playerid)) { AimLockTarget[playerid][targetid] = -1; AimLockTarget[playerid][pos_x] = -1.0; AimLockTarget[playerid][pos_y] = -1.0; AimLockTarget[playerid][pos_z] = -1.0; return KillTimer(AimLockCheck[playerid]); } if(AimLockTarget[playerid][targetid] >= 0 && AimLockTarget[playerid][targetid] <= MAX_PLAYERS) { if(!IsPlayerAimingAtPlayer(playerid, AimLockTarget[playerid][targetid])) { AimLockTarget[playerid][targetid] = -1; AimLockTarget[playerid][pos_x] = -1.0; AimLockTarget[playerid][pos_y] = -1.0; AimLockTarget[playerid][pos_z] = -1.0; AimAccuracy[playerid] --; } } new Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z); for(new i; i < MAX_PLAYERS; i++) { if(!IsPlayerConnected(playerid)) continue; if(!IsPlayerInRangeOfPoint(playerid, 20.0, x, y, z)) continue; new Float:tx, Float:ty, Float:tz; GetPlayerPos(i, tx, ty, tz); if(!IsPlayerAimingAtPlayer(playerid, i)) continue; if(GetPlayerSpeed(i) < 0.1) return 1; AimLockTarget[playerid][targetid] = i; AimLockTarget[playerid][pos_x] = tx; AimLockTarget[playerid][pos_y] = ty; AimLockTarget[playerid][pos_z] = tz; return AimAcuraccy[playerid] ++; } return 1; }