SA-MP Forums Archive
OnPlayerShootDynamicObject issue - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: OnPlayerShootDynamicObject issue (/showthread.php?tid=608998)



OnPlayerShootDynamicObject issue - TwinkiDaBoss - 07.06.2016

Alright so there is one problem with this, it will delete the entire map for some reason.

PHP Code:
public OnPlayerShootDynamicObject(playeridweaponidobjectidFloat:x,Float:y,Float:z) {
    for(new 
0sizeof(dInfo); i++) {
        if(
objectid == dInfo[i][DeerObject]) {
            if(
IsValidDynamicObject(dInfo[i][DeerObject])) {
            
                new 
Float:Pos[3];
                
GetDynamicObjectPos(dInfo[i][DeerObject],Pos[0],Pos[1],Pos[2]);
                new 
Float:rr frandomEx(1.00,10.00);
                
CreateMeatObject(rr,Pos[0],Pos[1],Pos[2],0.0,0.0,0.0);
                
SetDynamicObjectPos(dInfo[i][DeerObject],0.0,0.0,2500.0);
                
DestroyDynamicObject(dInfo[i][DeerObject]);
                
printf("Breaking object ID: %i",objectid);
                break;
            }
        }
    }
    
printf("Breaking object ID: %i",objectid);
    return 
1;

It will only print the object ID that it has destroyed but it will destroy all CreateDynamicObject


Re: OnPlayerShootDynamicObject issue - IstuntmanI - 07.06.2016

When you destroy dInfo[i][DeerObject] set its value to 0. Also, you shouldn't set its position right before destroying it.
pawn Code:
DestroyDynamicObject(dInfo[i][DeerObject]);

dInfo[i][DeerObject] = 0;
The problem about deleting the entire map (I guess not the GTA:SA map ?) of CreateDynamicObject s (?) is a problem from your storing of IDs.


Re: OnPlayerShootDynamicObject issue - TwinkiDaBoss - 07.06.2016

Yeah I was testing something with the SetDynamicObjectPos so I left it there, forgot to remove it

Regarding the object id's, not sure mate.. It reads the ID correctly. It prints out that object ID 85 has been removed and after 1 sec it removes the entire map lol (all dynamic objects from the map)


EDIT: This is the code which spawns it

PHP Code:
public DeerRespawn() {
    new 
SpawnTimes 0;
        
    for(new 
0sizeof(dInfo); i++) {
        new 
rand random(sizeof(DeerLocation));
        
DestroyDynamicObject(dInfo[i][DeerObject]);
             
          
dInfo[i][dx] = DeerLocation[rand][0];
           
dInfo[i][dy] = DeerLocation[rand][1];
           
dInfo[i][dz] = DeerLocation[rand][2];
        
dInfo[i][DeerObject] = CreateDynamicObject(19315,dInfo[i][dx],dInfo[i][dy],dInfo[i][dz],0.0,0.0,0.0);
        
printf("Deer %i spawned at %.2f,%.2f,%.2f",i,DeerLocation[rand][0],DeerLocation[rand][1],DeerLocation[rand][2]);
        
SpawnTimes += 1;
    }

The first deer doesnt remove the map, only the second one does.

Map respawns when the deer respawns and then after X seconds it dissapears again.


Re: OnPlayerShootDynamicObject issue - TwinkiDaBoss - 07.06.2016

AHA seems that something else is causing it

Without the function CreateMeatObject it delete anything but with it it does.
PHP Code:
CreateMeatObject(rr,Pos[0],Pos[1],Pos[2],0.0,0.0,0.0);
CreateMeatObject(Float:amountFloat:XFloat:YFloat:ZFloat:RXFloat:RYFloat:RZ) {
    for(new 
0sizeof(mInfo); i++) {
        
mInfo[i][meatObject] = CreateDynamicObject(2806XYZRXRYRZ);
        
mInfo[i][mX] = X;
        
mInfo[i][mY] = Y;
        
mInfo[i][mZ] = Z;
        
mInfo[i][meatAmount] = amount;
    }
}
enum MEAT_DATA {
    
Float:mX,
    
Float:mY,
    
Float:mZ,
    
Float:meatAmount,
    
meatObject
};
new 
mInfo[MAX_MEAT][MEAT_DATA];
#define MAX_MEAT 255 
Instead of spawning 2nd meat, it deletes the map


Also after shooting the 2nd deer, its giving me some different results
PHP Code:
[22:02:33Breaking object ID375
[22:02:35Breaking object ID194