open.mp forum
[Pawn] IsDynamicActorStreamedIn always returns 0 - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Pawn Scripting (https://forum.open.mp/forumdisplay.php?fid=10)
--- Thread: [Pawn] IsDynamicActorStreamedIn always returns 0 (/showthread.php?tid=1522)



IsDynamicActorStreamedIn always returns 0 - c4p - 2021-01-13

Hey. In my mod there is a system which creates shop actors if a player goes inside, and destroys them when everybody went out.
Or at least that's the goal. Creating the actor works fine, as the mod detects if the actor is already created and doesnt spawn it again, etc.
But if anybody leaves the shop and my custom function gets called, the shop actor gets deleted immediately, no matter if someone else got the actor streamed in.

My code:
Code:
DestroyShopActorIfUnstreamed(virtualworldid)
{
? ? if (!IsValidDynamicActor(shopactor[virtualworldid])) return 1;
for(new i = 0; i < MAX_PLAYERS  1; i)
? ? {
? ? ? ? if (IsDynamicActorStreamedIn(shopactor[virtualworldid], i))
? ? ? ? {
? ? ? ? ? ? print("streamed");
? ? ? ? ? ?break;
? ? ? ? }
? ? printf("shopactor %i deleted", virtualworldid);
? ? DestroyDynamicActor(shopactor[virtualworldid]);
? ? }
return 1;
}

I know i messed up something with the code


RE: IsDynamicActorStreamedIn always returns 0 - Bakr - 2021-01-17

If the actor is not streamed in for ID 0 you delete it immediately after. Move the DestroyDynamicActor line outside the loop, and switch the break to a return statement.


RE: IsDynamicActorStreamedIn always returns 0 - Expert* - 2021-01-18

You don't need to delete actors if u use streamer plugin. They 'r automagicly deleted/creatated and don't occupy a slot in default actor? -POOL?? - ( when not visable ).

I'd say delete dynamic actors this way only if they are usless/random.



Now, we have multiple mistakes in your code.



for(new i = 0; i < MAX_PLAYERS 1; i) >> for(new i = 0; i < MAX_PLAYERS; i)



? ? ? ? if (IsDynamicActorStreamedIn(shopactor[virtualworldid], i))

? ? ? ? {

? ? ? ? ? ? print("streamed");

? ? ? ? ? break;

? ? ? ? }



>>>



? ? ? ? if (IsDynamicActorStreamedIn(shopactor[virtualworldid], i))

? ? ? ? {

? ? ? ? ? ? print("streamed");

? ? ? ? ? return 0; // or 1

? ? ? ? }





And, consider adding IsPlayerConnected.