samp-incognito / samp-streamer-plugin

Streamer Plugin for SA-MP (San Andreas Multiplayer)
Apache License 2.0
235 stars 93 forks source link

Checkpoints restreaming bug #261

Open IstuntmanI opened 6 years ago

IstuntmanI commented 6 years ago

Originally posted by BeckzyBoi here: http://forum.sa-mp.com/showpost.php?p=3960733&postcount=5703


OnPlayerCommandText:

Streamer_ToggleItemUpdate(playerid, STREAMER_TYPE_CP, 0);
TogglePlayerAllDynamicCPs2(playerid, 0);
TogglePlayerSpectating(playerid, 1);

OnPlayerSpawn:

Streamer_ToggleItemUpdate(playerid, STREAMER_TYPE_CP, 1);
TogglePlayerAllDynamicCPs2(playerid, 1);

TogglePlayerDynamicCPs2:

TogglePlayerAllDynamicCPs2(playerid, toggle, exceptions[] = { -1 }, maxexceptions = sizeof exceptions)
{
    if (toggle == 0 && GetPlayerVisibleDynamicCP(playerid) != 0) {
        DisablePlayerCheckpoint(playerid);
    }
    TogglePlayerAllDynamicCPs(playerid, toggle, exceptions, maxexceptions);
}

When the player re-spawns in the range of a checkpoint, the checkpoint is not shown. They must re-enter the checkpoint streaming distance.


I think that this happens because the DisablePlayerCheckpoint function is used in this case to cancel a dynamic CP, but because the Streamer Plugin didn't hook the DisablePlayerCheckpoint function, the Streamer Plugin still thinks that the player sees an checkpoint, so it doesn't get restreamed yet. Probably hooking this function and setting player.visibleCheckpoint, player.activeCheckpoint and player.delayedCheckpoint to 0 would fix that ? (also doing this for race checkpoints)

IstuntmanI commented 6 years ago

By the way, with this SDK you can easily redirect AMX functions: https://github.com/maddinat0r/samp-plugin-sdk/

Example: https://github.com/udan11/samp-plugin-timerfix/blob/70a7477346d358bf5f613934298e18e7524f42f7/src/main.cpp#L77-L81

(not sure if hooking DisablePlayerCheckpoint and returning sampgdk::DisablePlayerCheckpoint in the hooked function would create an infinite loop, didn't test that yet, maybe @maddinat0r can respond to this ?)

samp-incognito commented 6 years ago

Yes, he shouldn't be using DisablePlayerCheckpoint. The right native to use in that case would be Streamer_ToggleItem (or TogglePlayerDynamicCP).

If you were to hook DisablePlayerCheckpoint, I would think you'd also have to hook SetPlayerCheckpoint and reset those variables (there's already some native hooking code here which could be refactored: https://github.com/samp-incognito/samp-streamer-plugin/blob/master/src/utility/amx.cpp#L47-L67). However, these natives will still ultimately be incompatible with the streamer plugin natives. The next time the streamer updates, the streamed checkpoint will just be set for the player again. There should be a note on the wiki about not using them together.

BeckzyBoi commented 6 years ago

The reason I'm using DisablePlayerCheckpoint is because neither Streamer_ToggleItem, TogglePlayerDynamicCP, or TogglePlayerAllDynamicCPs are hiding the checkpoint when used. DisablePlayerCheckpoint is the only way I can remove the checkpoint from the map when using Streamer_ToggleItemUpdate and TogglePlayerAllDynamicCPs

samp-incognito commented 6 years ago

The checkpoint should be hidden, but it won't take effect until the next update. You should call Streamer_ToggleItem, Streamer_Update, and then finally Streamer_ToggleItemUpdate.

BeckzyBoi commented 6 years ago

That doesn't hide the checkpoint either.

BeckzyBoi commented 6 years ago

For the life of me I can't get the visible checkpoint to disappear before using Streamer_ToggleItemUpdate and TogglePlayerAllDynamicCPs WITHOUT using DisablePlayerCheckpoint. Help?

karimcambridge commented 6 years ago

Not to bump this but.. maybe your doing something wrong.

I use Streamer_ToggleItem to stop showing checkpoints lets say when a player enters a custom transfender i made, then reenable it when they are done. It all works fine.