RC Tiger isn't shooting rockets
#1

Код:
new FireShot[MAX_PLAYERS];
new gRocketObj[MAX_PLAYERS];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(GetPlayerVehicleID(playerid) == 564 && FireShot[playerid] == 0 && KEY_FIRE & newkeys && IsValidObject(gRocketObj[playerid]))   // Only run the code if the object doesn't already exist, otherwise more objects will take up gRocketObj and the previous ones won't be deleted
 	{
  		SetPlayerTime(playerid,0,0);
        new
        	vehicleid = GetPlayerVehicleID(playerid),
         	Float:x,
            Float:y,
            Float:z,
            Float:r,
            Float:dist = 50.0,
            Float:tmpang,
            Float:tmpx,
            Float:tmpy,
            Float:tmpz;

		FireShot[playerid] = 1;
        SetTimerEx("ShotFire", 1000, 0, "i", playerid);
        GetVehiclePos(vehicleid, x, y, z);
        GetVehicleZAngle(vehicleid, r);
        new rand = random(12);
        switch(rand)
        {
        	case 0: gRocketObj[playerid] = CreateObject(18647, x, y, z, 0, 0, r);
            case 1: gRocketObj[playerid] = CreateObject(18648, x, y, z, 0, 0, r);
            case 2: gRocketObj[playerid] = CreateObject(18649, x, y, z, 0, 0, r);
            case 3: gRocketObj[playerid] = CreateObject(18650, x, y, z, 0, 0, r);
            case 4: gRocketObj[playerid] = CreateObject(18651, x, y, z, 0, 0, r);
            case 5: gRocketObj[playerid] = CreateObject(18652, x, y, z, 0, 0, r);
            case 6: gRocketObj[playerid] = CreateObject(18647, x, y, z, 0, 0, r+90);
            case 7: gRocketObj[playerid] = CreateObject(18648, x, y, z, 0, 0, r+90);
            case 8: gRocketObj[playerid] = CreateObject(18649, x, y, z, 0, 0, r+90);
            case 9: gRocketObj[playerid] = CreateObject(18650, x, y, z, 0, 0, r+90);
            case 10: gRocketObj[playerid] = CreateObject(18651, x, y, z, 0, 0, r+90);
            case 11: gRocketObj[playerid] = CreateObject(18652, x, y, z, 0, 0, r+90);
		}
		for(new i;i<MAX_PLAYERS;i++)
        {
            if(IsPlayerConnected(i))
        	if(i == playerid)continue;
            if(IsPlayerInRangeOfPoint(i, 50.0, x, y, z))
            {
            	GetPlayerPos(i, tmpx, tmpy, tmpz);
                tmpang = (90-atan2(tmpy-y, tmpx-x));
                if(tmpang < 0)tmpang = 360.0+tmpang;
                tmpang = 360.0 - tmpang;
                if(floatabs(tmpang-r) < 5.0)
                {
                	dist = GetPlayerDistanceFromPoint(i, x, y, z);
                }
            }
		}
		MoveObject(gRocketObj[playerid],x + (dist * floatsin(-r, degrees)),y + (dist * floatcos(-r, degrees)),z,100.0);                             // Nice and fast!
	}
}



forward ShotFire(playerid);
public ShotFire(playerid)
{
        FireShot[playerid] = 0;
        return 1;
}

public OnObjectMoved(objectid)
{
        for(new i;i<MAX_PLAYERS;i++)
        {
                if(objectid == gRocketObj[i])
                {
                    new
                    	Float:x,
                     	Float:y,
                      	Float:z;

                    GetObjectPos(gRocketObj[i], x, y, z);
                    CreateExplosion(x, y, z, 11, 3.0);
                    DestroyObject(gRocketObj[i]);
                }
        }
}
What's wrong with dis? :C
Reply
#2

PHP код:
if(GetPlayerVehicleID(playerid) == 564 && FireShot[playerid] == && KEY_FIRE newkeys && IsValidObject(gRocketObj[playerid])) 
You have not created an object but verify its existence before the shot

try this
PHP код:
if(GetPlayerVehicleID(playerid) == 564 && FireShot[playerid] == && KEY_FIRE newkeys
Reply
#3

Quote:
Originally Posted by Logofero
Посмотреть сообщение
PHP код:
if(GetPlayerVehicleID(playerid) == 564 && FireShot[playerid] == && KEY_FIRE newkeys && IsValidObject(gRocketObj[playerid])) 
You have not created an object but verify its existence before the shot

try this
PHP код:
if(GetPlayerVehicleID(playerid) == 564 && FireShot[playerid] == && KEY_FIRE newkeys
Continue to not shooting
Reply
#4

Quote:
Originally Posted by VanillaRain
Посмотреть сообщение
Continue to not shooting
At me shooting



Code
PHP код:
new FireShot[MAX_PLAYERS];
new 
gRocketObj[MAX_PLAYERS];
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
FireShot[playerid] == && KEY_FIRE newkeys)   // Only run the code if the object doesn't already exist, otherwise more objects will take up gRocketObj and the previous ones won't be deleted
     
{
          
SetPlayerTime(playerid,0,0);
        new
            
vehicleid GetPlayerVehicleID(playerid),
             
Float:x,
            
Float:y,
            
Float:z,
            
Float:r,
            
Float:dist 50.0,
            
Float:tmpang,
            
Float:tmpx,
            
Float:tmpy,
            
Float:tmpz;
        
FireShot[playerid] = 1;
        
SetTimerEx("ShotFire"10000"i"playerid);
        
GetVehiclePos(vehicleidxyz);
        
GetVehicleZAngle(vehicleidr);
        new 
rand random(12);
        switch(
rand)
        {
            case 
0gRocketObj[playerid] = CreateObject(18647xyz00r);
            case 
1gRocketObj[playerid] = CreateObject(18648xyz00r);
            case 
2gRocketObj[playerid] = CreateObject(18649xyz00r);
            case 
3gRocketObj[playerid] = CreateObject(18650xyz00r);
            case 
4gRocketObj[playerid] = CreateObject(18651xyz00r);
            case 
5gRocketObj[playerid] = CreateObject(18652xyz00r);
            case 
6gRocketObj[playerid] = CreateObject(18647xyz00r+90);
            case 
7gRocketObj[playerid] = CreateObject(18648xyz00r+90);
            case 
8gRocketObj[playerid] = CreateObject(18649xyz00r+90);
            case 
9gRocketObj[playerid] = CreateObject(18650xyz00r+90);
            case 
10gRocketObj[playerid] = CreateObject(18651xyz00r+90);
            case 
11gRocketObj[playerid] = CreateObject(18652xyz00r+90);
        }
        for(new 
i;i<MAX_PLAYERS;i++)
        {
            if(
IsPlayerConnected(i))
            if(
== playerid)continue;
            if(
IsPlayerInRangeOfPoint(i50.0xyz))
            {
                
GetPlayerPos(itmpxtmpytmpz);
                
tmpang = (90-atan2(tmpy-ytmpx-x));
                if(
tmpang 0)tmpang 360.0+tmpang;
                
tmpang 360.0 tmpang;
                if(
floatabs(tmpang-r) < 5.0)
                {
                    
dist GetPlayerDistanceFromPoint(ixyz);
                }
            }
        }
        
MoveObject(gRocketObj[playerid],+ (dist floatsin(-rdegrees)),+ (dist floatcos(-rdegrees)),z,100.0);                             // Nice and fast!
    
}
}
forward ShotFire(playerid);
public 
ShotFire(playerid)
{
        
FireShot[playerid] = 0;
        return 
1;
}
public 
OnObjectMoved(objectid)
{
        for(new 
i;i<MAX_PLAYERS;i++)
        {
                if(
objectid == gRocketObj[i])
                {
                    new
                        
Float:x,
                         
Float:y,
                          
Float:z;
                    
GetObjectPos(gRocketObj[i], xyz);
                    
CreateExplosion(xyz113.0);
                    
DestroyObject(gRocketObj[i]);
                }
        }

Reply
#5

Add code
PHP код:
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 564 && FireShot[playerid] == && KEY_FIRE newkeys
Reply
#6

Quote:
Originally Posted by Logofero
Посмотреть сообщение
Add code
PHP код:
if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 564 && FireShot[playerid] == && KEY_FIRE newkeys
Код:
new FireShot[MAX_PLAYERS];
new gRocketObj[MAX_PLAYERS];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 564 && FireShot[playerid] == 0 && KEY_FIRE & newkeys)// Only run the code if the object doesn't already exist, otherwise more objects will take up gRocketObj and the previous ones won't be deleted
 	{
  		SetPlayerTime(playerid,0,0);
        new
        	vehicleid = GetPlayerVehicleID(playerid),
         	Float:x,
            Float:y,
            Float:z,
            Float:r,
            Float:dist = 50.0,
            Float:tmpang,
            Float:tmpx,
            Float:tmpy,
            Float:tmpz;

		FireShot[playerid] = 1;
        SetTimerEx("ShotFire", 1000, 0, "i", playerid);
        GetVehiclePos(vehicleid, x, y, z);
        GetVehicleZAngle(vehicleid, r);
        new rand = random(12);
        switch(rand)
        {
        	case 0: gRocketObj[playerid] = CreateObject(18647, x, y, z, 0, 0, r);
            case 1: gRocketObj[playerid] = CreateObject(18648, x, y, z, 0, 0, r);
            case 2: gRocketObj[playerid] = CreateObject(18649, x, y, z, 0, 0, r);
            case 3: gRocketObj[playerid] = CreateObject(18650, x, y, z, 0, 0, r);
            case 4: gRocketObj[playerid] = CreateObject(18651, x, y, z, 0, 0, r);
            case 5: gRocketObj[playerid] = CreateObject(18652, x, y, z, 0, 0, r);
            case 6: gRocketObj[playerid] = CreateObject(18647, x, y, z, 0, 0, r+90);
            case 7: gRocketObj[playerid] = CreateObject(18648, x, y, z, 0, 0, r+90);
            case 8: gRocketObj[playerid] = CreateObject(18649, x, y, z, 0, 0, r+90);
            case 9: gRocketObj[playerid] = CreateObject(18650, x, y, z, 0, 0, r+90);
            case 10: gRocketObj[playerid] = CreateObject(18651, x, y, z, 0, 0, r+90);
            case 11: gRocketObj[playerid] = CreateObject(18652, x, y, z, 0, 0, r+90);
		}
		for(new i;i<MAX_PLAYERS;i++)
        {
            if(IsPlayerConnected(i))
        	if(i == playerid)continue;
            if(IsPlayerInRangeOfPoint(i, 50.0, x, y, z))
            {
            	GetPlayerPos(i, tmpx, tmpy, tmpz);
                tmpang = (90-atan2(tmpy-y, tmpx-x));
                if(tmpang < 0)tmpang = 360.0+tmpang;
                tmpang = 360.0 - tmpang;
                if(floatabs(tmpang-r) < 5.0)
                {
                	dist = GetPlayerDistanceFromPoint(i, x, y, z);
                }
            }
		}
		MoveObject(gRocketObj[playerid],x + (dist * floatsin(-r, degrees)),y + (dist * floatcos(-r, degrees)),z,100.0);                             // Nice and fast!
	}
}



forward ShotFire(playerid);
public ShotFire(playerid)
{
        FireShot[playerid] = 0;
        return 1;
}

public OnObjectMoved(objectid)
{
        for(new i;i<MAX_PLAYERS;i++)
        {
                if(objectid == gRocketObj[i])
                {
                    new
                    	Float:x,
                     	Float:y,
                      	Float:z;

                    GetObjectPos(gRocketObj[i], x, y, z);
                    CreateExplosion(x, y, z, 11, 3.0);
                    DestroyObject(gRocketObj[i]);
                }
        }
}
isn't shooting a damn :C
Reply
#7

Quote:
Originally Posted by VanillaRain
Посмотреть сообщение
Код:
new FireShot[MAX_PLAYERS];
new gRocketObj[MAX_PLAYERS];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 564 && FireShot[playerid] == 0 && KEY_FIRE & newkeys)// Only run the code if the object doesn't already exist, otherwise more objects will take up gRocketObj and the previous ones won't be deleted
 	{
  		SetPlayerTime(playerid,0,0);
        new
        	vehicleid = GetPlayerVehicleID(playerid),
         	Float:x,
            Float:y,
            Float:z,
            Float:r,
            Float:dist = 50.0,
            Float:tmpang,
            Float:tmpx,
            Float:tmpy,
            Float:tmpz;

		FireShot[playerid] = 1;
        SetTimerEx("ShotFire", 1000, 0, "i", playerid);
        GetVehiclePos(vehicleid, x, y, z);
        GetVehicleZAngle(vehicleid, r);
        new rand = random(12);
        switch(rand)
        {
        	case 0: gRocketObj[playerid] = CreateObject(18647, x, y, z, 0, 0, r);
            case 1: gRocketObj[playerid] = CreateObject(18648, x, y, z, 0, 0, r);
            case 2: gRocketObj[playerid] = CreateObject(18649, x, y, z, 0, 0, r);
            case 3: gRocketObj[playerid] = CreateObject(18650, x, y, z, 0, 0, r);
            case 4: gRocketObj[playerid] = CreateObject(18651, x, y, z, 0, 0, r);
            case 5: gRocketObj[playerid] = CreateObject(18652, x, y, z, 0, 0, r);
            case 6: gRocketObj[playerid] = CreateObject(18647, x, y, z, 0, 0, r+90);
            case 7: gRocketObj[playerid] = CreateObject(18648, x, y, z, 0, 0, r+90);
            case 8: gRocketObj[playerid] = CreateObject(18649, x, y, z, 0, 0, r+90);
            case 9: gRocketObj[playerid] = CreateObject(18650, x, y, z, 0, 0, r+90);
            case 10: gRocketObj[playerid] = CreateObject(18651, x, y, z, 0, 0, r+90);
            case 11: gRocketObj[playerid] = CreateObject(18652, x, y, z, 0, 0, r+90);
		}
		for(new i;i<MAX_PLAYERS;i++)
        {
            if(IsPlayerConnected(i))
        	if(i == playerid)continue;
            if(IsPlayerInRangeOfPoint(i, 50.0, x, y, z))
            {
            	GetPlayerPos(i, tmpx, tmpy, tmpz);
                tmpang = (90-atan2(tmpy-y, tmpx-x));
                if(tmpang < 0)tmpang = 360.0+tmpang;
                tmpang = 360.0 - tmpang;
                if(floatabs(tmpang-r) < 5.0)
                {
                	dist = GetPlayerDistanceFromPoint(i, x, y, z);
                }
            }
		}
		MoveObject(gRocketObj[playerid],x + (dist * floatsin(-r, degrees)),y + (dist * floatcos(-r, degrees)),z,100.0);                             // Nice and fast!
	}
}



forward ShotFire(playerid);
public ShotFire(playerid)
{
        FireShot[playerid] = 0;
        return 1;
}

public OnObjectMoved(objectid)
{
        for(new i;i<MAX_PLAYERS;i++)
        {
                if(objectid == gRocketObj[i])
                {
                    new
                    	Float:x,
                     	Float:y,
                      	Float:z;

                    GetObjectPos(gRocketObj[i], x, y, z);
                    CreateExplosion(x, y, z, 11, 3.0);
                    DestroyObject(gRocketObj[i]);
                }
        }
}
isn't shooting a damn :C
As it does not fire unless shooting. Check your code better, can somewhere above error.

Reply
#8

Quote:
Originally Posted by Logofero
Посмотреть сообщение
As it does not fire unless shooting. Check your code better, can somewhere above error.

Код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>

#if defined FILTERSCRIPT
#define MAX_PLAYERS 500
public OnFilterScriptInit()
{
	print("\n--------------------------------------");
	print(" Blank Filterscript by your name here");
	print("--------------------------------------\n");
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

#else

main()
{
	
}

#endif

public OnGameModeInit()
{
	
	return 1;
}

public OnGameModeExit()
{
	return 1;
}



new FireShot[MAX_PLAYERS];
new gRocketObj[MAX_PLAYERS];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	if(GetVehicleModel(GetPlayerVehicleID(playerid)) == 564 && FireShot[playerid] == 0 && KEY_FIRE & newkeys)// Only run the code if the object doesn't already exist, otherwise more objects will take up gRocketObj and the previous ones won't be deleted
 	{
  		SetPlayerTime(playerid,0,0);
        new
        	vehicleid = GetPlayerVehicleID(playerid),
         	Float:x,
            Float:y,
            Float:z,
            Float:r,
            Float:dist = 50.0,
            Float:tmpang,
            Float:tmpx,
            Float:tmpy,
            Float:tmpz;

		FireShot[playerid] = 1;
        SetTimerEx("ShotFire", 1000, 0, "i", playerid);
        GetVehiclePos(vehicleid, x, y, z);
        GetVehicleZAngle(vehicleid, r);
        new rand = random(12);
        switch(rand)
        {
        	case 0: gRocketObj[playerid] = CreateObject(18647, x, y, z, 0, 0, r);
            case 1: gRocketObj[playerid] = CreateObject(18648, x, y, z, 0, 0, r);
            case 2: gRocketObj[playerid] = CreateObject(18649, x, y, z, 0, 0, r);
            case 3: gRocketObj[playerid] = CreateObject(18650, x, y, z, 0, 0, r);
            case 4: gRocketObj[playerid] = CreateObject(18651, x, y, z, 0, 0, r);
            case 5: gRocketObj[playerid] = CreateObject(18652, x, y, z, 0, 0, r);
            case 6: gRocketObj[playerid] = CreateObject(18647, x, y, z, 0, 0, r+90);
            case 7: gRocketObj[playerid] = CreateObject(18648, x, y, z, 0, 0, r+90);
            case 8: gRocketObj[playerid] = CreateObject(18649, x, y, z, 0, 0, r+90);
            case 9: gRocketObj[playerid] = CreateObject(18650, x, y, z, 0, 0, r+90);
            case 10: gRocketObj[playerid] = CreateObject(18651, x, y, z, 0, 0, r+90);
            case 11: gRocketObj[playerid] = CreateObject(18652, x, y, z, 0, 0, r+90);
		}
		for(new i;i<MAX_PLAYERS;i++)
        {
            if(IsPlayerConnected(i))
        	if(i == playerid)continue;
            if(IsPlayerInRangeOfPoint(i, 50.0, x, y, z))
            {
            	GetPlayerPos(i, tmpx, tmpy, tmpz);
                tmpang = (90-atan2(tmpy-y, tmpx-x));
                if(tmpang < 0)tmpang = 360.0+tmpang;
                tmpang = 360.0 - tmpang;
                if(floatabs(tmpang-r) < 5.0)
                {
                	dist = GetPlayerDistanceFromPoint(i, x, y, z);
                }
            }
		}
		MoveObject(gRocketObj[playerid],x + (dist * floatsin(-r, degrees)),y + (dist * floatcos(-r, degrees)),z,100.0);                             // Nice and fast!
	}
}



forward ShotFire(playerid);
public ShotFire(playerid)
{
        FireShot[playerid] = 0;
        return 1;
}

public OnObjectMoved(objectid)
{
        for(new i;i<MAX_PLAYERS;i++)
        {
                if(objectid == gRocketObj[i])
                {
                    new
                    	Float:x,
                     	Float:y,
                      	Float:z;

                    GetObjectPos(gRocketObj[i], x, y, z);
                    CreateExplosion(x, y, z, 11, 3.0);
                    DestroyObject(gRocketObj[i]);
                }
        }
}
Reply
#9

For me it work perfectly.
Do you have objects in near of you?
If not you can try to debug this callback.
Reply
#10

PHP код:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT
#include <a_samp>
#if defined FILTERSCRIPT
#define MAX_PLAYERS 500
public OnFilterScriptInit()
{
    print(
"\n--------------------------------------");
    print(
" Blank Filterscript by your name here");
    print(
"--------------------------------------\n");
    return 
1;
}
public 
OnFilterScriptExit()
{
    return 
1;
}
#else
main()
{
    
}
#endif 
try

PHP код:
// This is a comment
// uncomment the line below if you want to write a filterscript
#define FILTERSCRIPT
#include <a_samp>
#if defined FILTERSCRIPT
#define MAX_PLAYERS 500
public OnFilterScriptInit()
{
    print(
"\n--------------------------------------");
    print(
" Blank Filterscript by your name here");
    print(
"--------------------------------------\n");
    return 
1;
}
public 
OnFilterScriptExit()
{
    return 
1;
}
#else
main()
{
    
}
#endif 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)