Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local isReloading=false; local bullets_fired=0; local last_fired = 0;
- SetTimerEx( "ShootPlayer", 60, 0, pid );
- function ShootPlayer( pid )
- {
- if( IsPlayerStreamedIn( pid ) && GetPlayerState(pid) != PLAYER_STATE_WASTED )
- {
- local pos = GetPlayerPos( pid );
- local weapon = GetPlayerArmedWeapon( npcid );
- if( GetDistanceFromMeToPoint( pos ) < 90.0 )
- {
- local now = GetTickCount();
- if( !isReloading || now - last_fired >= 1000 )
- {
- isReloading = false;
- /* Checking interval between 2 bullets. In milliseconds. */
- if( now - last_fired >= 150 ) // 150ms is firing rate of rifle ruger
- {
- //Decrease Ammo by One.
- local NewAmmo = GetLocalValue(I_CURWEP_AMMO) - 1;
- if( NewAmmo <= 0 )
- NewAmmo = 1; //fool the server
- SetLocalValue( I_CURWEP_AMMO, NewAmmo );
- ShootAt( pos );
- bullets_fired++;
- if( bullets_fired % 30 == 0 ) //rifle has 30 bullets in one catridge
- isReloading = true;
- last_fired = now; //Store tick
- }else
- {
- //Send a packet, same as last one. ( for Sync Issues )
- SendOnFootSyncDataLV();
- }
- }else
- {
- //still reloading... Call function 'ShootAt' with 'isReloading' as 'true'
- ShootAt( pos, true );
- }
- }
- }
- }
- function ShootAt(tPos, isReloading = false, isHeadShot=false)
- {
- if(isHeadShot)
- tPos.z+=0.627299;
- local Pos= GetMyPos();
- local angle= atan2(-(tPos.x-Pos.x), tPos.y-Pos.y);
- local aimPos= Vector(tPos.x,tPos.y,tPos.z);
- local aimDir = Vector( PI, PI, -angle );
- SendOnFootSyncData( KEY_ONFOOT_FIRE, Pos.x,Pos.y, Pos.z, angle, GetPlayerHealth( npcid ), GetPlayerArmour( npcid ), GetPlayerArmedWeapon( npcid ),GetLocalValue(I_CURWEP_AMMO ), 0.0, 0.0, 0.0, aimPos.x, aimPos.y, aimPos.z, PI, PI, -angle, false, isReloading );
- }
- function OnNPCConnect(myplayerid)
- {
- npcid<-myplayerid;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement