Pottus / ColAndreas

Collision Plugin For San Andreas Multiplayer
GNU General Public License v3.0
68 stars 44 forks source link

Ability to cancel CA_RemoveBuilding function #51

Closed NexiusTailer closed 4 years ago

NexiusTailer commented 6 years ago

As we all know, we have only RemoveBuildingForPlayer function, which removes default map objects only for a specific player. And if this player relogs and in the same time we stop applying this function to new players, then the default objects will be still exist. So because of that I propose to add the cancellation of CA_RemoveBuilding function so that at any time it will be possible to restore the collisions of any previously removed default objects.

Crayder commented 6 years ago

Temporarily you could make use of the every-object database from TS instead of using CA_Init.

https://github.com/Pottus/Texture-Studio/raw/master/scriptfiles/tstudio/allbuildings.db https://github.com/Pottus/Texture-Studio/blob/master/filterscripts/tstudio/allobjects.pwn

AO_RESULT = db_query(AO_DB, "SELECT * FROM `buildings`");
do
{
    CA_CreateObject(db_get_field_float(AO_RESULT, 1), db_get_field_float(AO_RESULT, 4), db_get_field_float(AO_RESULT, 5), db_get_field_float(AO_RESULT, 6), db_get_field_float(AO_RESULT, 7), db_get_field_float(AO_RESULT, 8), db_get_field_float(AO_RESULT, 9));
}
while(db_next_row(AO_RESULT));

Simply incorporate a way to keep track of the added objects and remove the ones you don't need, add back the ones that are added back etc, etc.

NexiusTailer commented 6 years ago

I use ColAndreas in my Ultimate Creator (object editor), so it would be nice to see this feature in it instead of using another external database.

NexiusTailer commented 4 years ago

I've noticed you released a draft of 1.4.1. So what about that issue and other fixes/improvements?

AmyrAhmady commented 4 years ago

@NexiusTailer What do you exactly mean by canceling RemoveBuilding? are you talking about some way or function to revert what happens by using RemoveBuilding? to bring it back?

NexiusTailer commented 4 years ago

@AmyrAhmady yes, exactly this.

AmyrAhmady commented 4 years ago

@NexiusTailer Well, how do you think it should be? like RemoveBuilding can return a value then you make use of that by a new function (also suggest a name). for example:

new removedBuilding = CA_RemoveBuilding(....);
CA_BringBackRemovedBuilding(removedBuilding);
NexiusTailer commented 4 years ago

@AmyrAhmady I think you've already done it in a good way

AmyrAhmady commented 4 years ago

@NexiusTailer then I will start doing that and make a PR we can also wait for @Crayder 's opinion till then.

Crayder commented 4 years ago

Well, ya see, CA_RemoveBuilding acts like RemoveBuildingForPlayer. It doesn't remove just one, it removes all objects that match the parameters given. So, when doing this we will need to track all of the removed ones and store them somewhere that can be pointed to via the returned remove id.

OR, what I propose, is this.

CA_RestoreBuilding(same params as the remove function)

This function would simply do the inverse. Loop through the SA map objects, if they are in range and they are already removed, recreate them.

👐 See https://github.com/Pottus/ColAndreas/blob/bf10c85a4d2d974325d6c0def33210fc7ecba2c8/src/ColObject.cpp#L366

NexiusTailer commented 4 years ago

OR, what I propose, is this.

CA_RestoreBuilding(same params as the remove function)

This function would simply do the inverse. Loop through the SA map objects, if they are in range and they are already removed, recreate them.

I like this idea most of all, since the logic will completely coincide with that which the default samp native has.

AmyrAhmady commented 4 years ago

Alright, seems like now you two decided what we should. I can work on it when I get free time (tomorrow).

Crayder commented 4 years ago

I'm not sure how effective it would be performance wise... but you could perhaps also support -1 modelid for recreating ALL currently removed objects. This would also coincide with the default native, in which using -1 removes all SA created objects.

AmyrAhmady commented 4 years ago

I think it should be more efficient than the normal one cause right now what i did is looping through all of them and having three conditions: 1. position (ofc) 2. modelid 3. removed so for -1, it means one condition less, no need to check for modelid

AmyrAhmady commented 4 years ago

@NexiusTailer Can you give me a sample code so I can test it? I'm already done with implementing this function; All I need is someone who can test it or maybe a simple script so I can do it myself

NexiusTailer commented 4 years ago

Here's the link. So, first of all you will be spawned in the place where all object collisions around are removed and you should see "No collision found here" that means the point where you stare at don't have collision detect. If you see this while your camera set at real object - then the first step passed and ColAndreas removed these objects before start. To restore them via your function just type /restore command to restore all objects separately (like CA_RestoreObject(4321, 1555.0, 1444.0, 133.0, 12.765) etc) or /restoreall to restore all objects on the gta sa map at once (like CA_RestoreObject(-1, 0.0, 0.0, 0.0, 3000.0)). After that you must see that the places where you was looking at before without collisions become collidable after any of the command applied.

Btw, sorry for delay.

AmyrAhmady commented 4 years ago

@NexiusTailer Thanks, it works, there were some issues and needed to be fixed creating a PR now