Quantcast

Jump to content

» «
Photo

Detect "owner" or "creator" of game object

41 replies to this topic
julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#1

Posted 24 March 2014 - 10:33 PM

Hey guys, someone knows if its possible detect if a object/ped/car was created by game or by a custom script (.net, .asi, etc.)?


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#2

Posted 26 March 2014 - 04:26 PM

it sounds like u would want to hook the native function for creating peds/vehicles/objects and then when game tries to spawn a ped it calls your detoured function and maybe like that u can identify what is calling the function... u probably will need some reversing skills... take a look at thaCursedPie's github... he made a project to hook native functions... could at least give u a starting place


julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#3

Posted 26 March 2014 - 10:53 PM

the idea is reuse objects when i use command reloadscripts or avoid to use objects created by other scripts


InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#4

Posted 27 March 2014 - 05:27 AM

the idea is reuse objects when i use command reloadscripts or avoid to use objects created by other scripts

looks like you already did this with death race. care to share how you accomplished that? 


pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#5

Posted 27 March 2014 - 07:33 AM

I'm not seeing this being possible without implementation on the creating scripts. But even then I'm not seeing how it might work.


julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#6

Posted 27 March 2014 - 04:20 PM

 

the idea is reuse objects when i use command reloadscripts or avoid to use objects created by other scripts

looks like you already did this with death race. care to share how you accomplished that? 

 


Nope, death race is using any object that already exists or objects already created by the script that are in a "idle" list of objects



pedro2555: the biggest problem with object creation for me at least is that after some 20 creations they start to freeze, and only Load game solves the issue, this behavior seems to be more "agressive" with users that have not much video memory, some users with 512 mb of vid mem. had this issue with tank + buzzard while others with 1 gb didnt, here only happens after a lot reloadscripts command


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#7

Posted 27 March 2014 - 04:56 PM Edited by LordOfTheBongs, 27 March 2014 - 04:59 PM.

the idea is reuse objects when i use command reloadscripts or avoid to use objects created by other scripts

then do something like this when ur script needs to create an object, not sure why u need to know where it came from, if another script needs the object it will be marked required for mission and maybe just ignore those objects...

private GTA.Object FindOrCreateObject(Model model, Vector3 position, float range)
{
    foreach (GTA.Object obj in World.GetAllObjects())
    {
        if (!Game.Exists(obj)) continue;
        if (obj.Model != model) continue;
        if (obj.Position.DistanceTo(position) > range) continue;
 
        return obj;
    }
 
    return World.CreateObject(model, position);
}

InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#8

Posted 27 March 2014 - 10:33 PM

 

the idea is reuse objects when i use command reloadscripts or avoid to use objects created by other scripts

then do something like this when ur script needs to create an object, not sure why u need to know where it came from, if another script needs the object it will be marked required for mission and maybe just ignore those objects...

private GTA.Object FindOrCreateObject(Model model, Vector3 position, float range)
{
    foreach (GTA.Object obj in World.GetAllObjects())
    {
        if (!Game.Exists(obj)) continue;
        if (obj.Model != model) continue;
        if (obj.Position.DistanceTo(position) > range) continue;
 
        return obj;
    }
 
    return World.CreateObject(model, position);
}

very nice.
another way would be to save object handles to a file (theres probably a better way to say this, but i just woke up), then check the file on script load


julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#9

Posted 27 March 2014 - 11:11 PM

thx for the ideas, the file with objects handles idea may work i guess


pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#10

Posted 27 March 2014 - 11:13 PM

I think what Julio asked didn't get along to everyone.

 

Image the situation, your script populates multiple objects on calling a specific function. While debugging that function you will be doing a lot of 'reloadscripts', which means your function will recreate the same objects which another (older) instance of the same script had created. What he wants to achieve is garbage collection across script reloading, am I right on this Julio ?


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#11

Posted 27 March 2014 - 11:53 PM

make a debug script that deletes stuff then... i have these features in my trainer i made for myself... make a reset world function or in the constructor of his script he can clean stuff up


InfamousSabre
  • InfamousSabre

    Harpocrates

  • Members
  • Joined: 03 Jan 2013

#12

Posted 27 March 2014 - 11:59 PM

Lol trust me, I know the problem.. I have this issue with Silence! as well. I end up with multiple silencers attached to my arm after a few reloads.
Also with Pickups2.0... all these weapons laying around, and I cant pick them up after a reload =\

you can either delete the old objects and create new ones, or just re-use the old objects

 

if you know their position, LordOfTheBongs' method should work fine.

If not, saving their handle should allow you to do whatever you want with them. Its basically just using the file as memory that is safe from being erased by reloadscripts


julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#13

Posted 28 March 2014 - 04:32 AM

my biggest issue is the new objects "frozen", even if i ask game to delete them setting NoLongerNeeded + distant position after some time new objects will freeze, it also affects cars and peds, its interesting that R* does this very well because if we equip each cop with a rocket launcher they dont will cause this bug with their cj_rpg_rocket models, the create_obejct method have some misterious params for me, maybe one of them is the secret to avoid this "freeze" behavior


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#14

Posted 28 March 2014 - 05:45 AM Edited by LordOfTheBongs, 28 March 2014 - 05:53 AM.

i think it is because it is just a bad port from console and the memory isnt managed like a good pc port... read this

 

http://devblog.lcpdfr.com/author/lms/

 

http://devblog.lcpdf...iveflc-crashes/

 

i think the best thing to do is reduce the ped density and/or car density if u plan on doing a lot of spawning. I made a braveheart battle and i spawn 60 peds in less than a second, and never fails because i set the ped density to 0 and this stops the game spawning and messing up the ped pool which has a fixed length and when u overload gta with spawning the system breaks and u will see gta to begin acting weird

 

when u see peds start freezing it is because gta can't handle all the objects and it loses track of objects in memory which is probably why they freeze and u cant delete... the game cant even delete because they are lost... trhose articles explain the technical details... good job to lms ;)

 

edit: i just re read article and pool is 120 peds in game so if i delete all peds and set density to 0 i can make a 60 vs 60 battle xD


julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#15

Posted 28 March 2014 - 08:28 AM

nice, i did some tests with my ironman code (taht was causing the issue with more frequency) and made he only create to objects when equip armor or when get close to fixed objects in map  (like saved cars).
also im reusing the objects instead of creating new ones, only issue that remains is that this method can pickobjects from other mods, but this is not easy to happen because will happen randomly because is the user who decide when equip the armor for first time, i will make a test release and see if people will get errors with other mods.


julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#16

Posted 28 March 2014 - 10:35 PM

i made a test today and reduced my video memory to 450 +/- and reduce graphics quality until use half video memory (236 +/-)  and tested same mods, the result was frozen objects after some tries, so, im almost sure that amount of video memory is directly related to the frozen objects issue.

at least now i have a "excuse" for the users ^^


NTAuthority
  • NTAuthority

    hell, no, tunnel, no

  • Feroci
  • Joined: 09 Sep 2008
  • European-Union
  • Best Conversion 2014 [ViIV for GTANY]
    Most Knowledgeable [Tech] 2013
    Best Map 2013 [ViceCityStories PC Edition]
    Contribution Award [Mods]

#17

Posted 01 April 2014 - 12:16 PM

physical streaming memory should only ever cause issues for, well, streaming; the only thing I can imagine some kind of emergency cleanup routine gets triggered that breaks your entities in a similar way to how building entities get removed in these scenarios


jenksta
  • jenksta

    Player Hater

  • Members
  • Joined: 22 Dec 2008
  • United-Kingdom

#18

Posted 02 April 2014 - 01:38 PM Edited by jenksta, 02 April 2014 - 01:54 PM.

What do you mean when you say they become 'frozen'?

 

If you're mean no collision loaded for them, it's probably because of the CMissionCleanup class, everything script created/loaded is added to the CMissionCleanup class so the game can delete/unload objects from certain scripts or missions as and when it needs to. However unfortunately theres only 256 slots in the class, and as everything you create/load from scripts is added to the same slots (peds, vehicles, objects, blips, decision makers, ptfx, txds, viewports, groups, models) it fills up pretty quickly, and because (for some strange reason) the collision for vehicles, peds and objects is loaded by this class, as soon as all slots are filled this causes collision to not be loaded for any newly created vehicles, peds or objects. you should be able to fix this by calling the SET_LOAD_COLLISION_FOR_CAR/PED/OBJECT_FLAG native with 1 as the second parameter on the frozen entity.


julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#19

Posted 02 April 2014 - 02:17 PM

frozen with collision enabled, they get stuck on spawn or detach position like if freezePosition is set to true, if we set they as noLongerNeeded and move then to a distant place we can start creating new ones without the "bug"


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#20

Posted 02 April 2014 - 02:59 PM Edited by LordOfTheBongs, 02 April 2014 - 03:01 PM.

@jenksta when GTA starts bugging out because some script is maybe screwing up the game's memory or maybe u spawned too many peds then a common bug is peds being loaded frozen in place... they have collision and can be killed but they stay in the same animation.. u can even drive a car full speed into them and they wont move, u will just wreck your car

 

a good way to avoid when u spawn a lot of peds is to reduce the ped density so gta and your script are not competing for positions in the ped pool


jenksta
  • jenksta

    Player Hater

  • Members
  • Joined: 22 Dec 2008
  • United-Kingdom

#21

Posted 02 April 2014 - 05:27 PM Edited by jenksta, 02 April 2014 - 05:33 PM.

It's not an issue with the games pools as if there were no slots left the ped wouldn't spawn whatsoever, and the population peds/vehicles are only spawned if there's at least 5 slots in the ped/vehicle pool, on top of that there's also a ClearSpaceForMissionEntity function which will delete any population around the area the entity is spawned, the reason it's fixed by calling MarkAsNoLongerNeeded is because that function removes the entity from CMissionCleanup (which obviously frees slots for the next entity your creating) and (from what I remember) marks it as a population entity so that the game will delete it when it wants. You could fix this issue with a simple hook which would force the game to use your own custom CMissionCleanup structure with more than 256 slots. (Also if the mission cleanup has no slots the collision will still be loaded for the entity but physics isn't applied to it so it'll just be stuck where it is like your describing).

julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#22

Posted 02 April 2014 - 05:42 PM

its interesting that the issue happens faster when we limit video memory, here on my tests with full vid mem it happens after some 100 cj_rpg_rocket spawns, and with 500 mb +/- of vid mem it happens with some 30 objects, and is not exact, sometimes we can create more sometimes less, the big issue here is that we cant make sure that other scripts are removing their objects when they dont need anymore, if they keep the objects, one time our script will obtain this issue when creating a new object.

my ironman mod was causing this issue, i had to rethink great part of code days ago to make it able to only create the objects when equipping armor


LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#23

Posted 02 April 2014 - 05:43 PM

yeah maybe... i just notice when it happens that there is usually access violation exceptions in the console dialog


jenksta
  • jenksta

    Player Hater

  • Members
  • Joined: 22 Dec 2008
  • United-Kingdom

#24

Posted 02 April 2014 - 05:44 PM

If you want I can create you an asi to increase the mission cleanup slots to see if it solves your issue?

LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#25

Posted 02 April 2014 - 05:56 PM

yeah u should make it and if it works it would only allow scripters to push gta further, i think it is something worth making and if ur will ing to share the source that would be cool as i never heard of this class before, i also have not done any reversing with gta


julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#26

Posted 03 April 2014 - 08:48 AM

thats good


jenksta
  • jenksta

    Player Hater

  • Members
  • Joined: 22 Dec 2008
  • United-Kingdom

#27

Posted 03 April 2014 - 08:43 PM

Ok see if this fixes your issue, haven't properly tested myself yet, supports IV patch 7 and EFLC patch 2 (source included).

Place limits.asi wherever your asi loader requires then just run the game as usual.

 

http://jenksta.iv-m....ion_cleanup.zip

  • LordOfTheBongs likes this

LordOfTheBongs
  • LordOfTheBongs

    Deceased

  • Members
  • Joined: 21 Sep 2013
  • None

#28

Posted 03 April 2014 - 09:23 PM Edited by LordOfTheBongs, 03 April 2014 - 09:25 PM.

nice job man, thanks for sharing, i learned something new  ;)


julionib
  • julionib

    Coder

  • Feroci
  • Joined: 13 Sep 2012
  • Brazil

#29

Posted 04 April 2014 - 01:12 PM

ok thx


pedro2555
  • pedro2555

    Open Sourcer

  • Members
  • Joined: 02 Sep 2012
  • Portugal

#30

Posted 04 April 2014 - 02:08 PM Edited by pedro2555, 04 April 2014 - 02:13 PM.

Wrong post, sorry.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users