OnPlayerWeaponShot help
#1

Hi, I'm trying to make a weapon stats script that counts a shot on an empty vehicle as a miss, but counts a shot on an occupied vehicle as a hit. The script (below) is counting both empty and occupied vehicle shots as misses and I'm stuck

PHP код:
public OnPlayerWeaponShot(playeridweaponidhittypehitidFloat:fXFloat:fYFloat:fZ)
{
    if(!
IsPlayerConnected(playerid)) return 0;
    
shots[playerid] ++;
    if(
hittype == BULLET_HIT_TYPE_NONE
    
|| hittype == BULLET_HIT_TYPE_OBJECT
    
|| hittype == BULLET_HIT_TYPE_PLAYER_OBJECT)
    {
        
misses[playerid] ++;
    }
    if(
hittype == BULLET_HIT_TYPE_PLAYER)
    {
        
phits[playerid] ++;
    }
    if(
hittype == BULLET_HIT_TYPE_VEHICLE)
    {
        if(
VehicleOccupied(hitid))
        {
            
vhits[playerid] ++;
        }
        else
        {
            
misses[playerid] ++;
        }
    }
    return 
1;
}
stock VehicleOccupied(vehicleid)
{
    foreach (new 
Player)
    {
        if(
IsPlayerInVehicle(i,vehicleid)) return 1;
    }
    return 
0;

I appreciate any help thanks
Reply
#2

What are you saying? I don't understand.
You want that shots on empty vehicle should count as hit or miss?
Reply
#3

Quote:
Originally Posted by phoon
Посмотреть сообщение
What are you saying? I don't understand.
You want that shots on empty vehicle should count as hit or miss?
empty = miss, occupied = hit
Reply
#4

Код:
//what you asked for, only "counts a shot on an empty vehicle as a miss, but counts a shot on an occupied vehicle as a hit"
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ) 
{
	shots[playerid] ++;
    if(hittype == BULLET_HIT_TYPE_VEHICLE) 
    { 
        if(VehicleOccupied(hitid)) vhits[playerid] ++; 
        else misses[playerid] ++; 
    } 
    return 1; 
} 

//what i find more logic: counts a shot on a player or occupied vehicle as a hit and counts a shot anywhere else as a miss
public OnPlayerWeaponShot(playerid, weaponid, hittype, hitid, Float:fX, Float:fY, Float:fZ) 
{
	shots[playerid] ++;
	if (
		(hittype == BULLET_HIT_TYPE_PLAYER && hitid != playerid) ||
		(hittype == BULLET_HIT_TYPE_VEHICLE && VehicleOccupied(hitid))
	)
		vhits[playerid]++; else misses[playerid] ++;
    return 1; 
} 



//this function is called about 10 times as frequently as a fire rate, depending on the number of players shooting together. with the bool tag u use 4 times less space (from 4 bytes/return to 1 byte/return)
bool:VehicleOccupied(vehicleid) 
{ 
    foreach (new i : Player) if(IsPlayerInVehicle(i,vehicleid)) return true;
    return false; 
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)