Raised This Month: $12 Target: $400
 3% 

Solved Difference between DispatchKeyValue() And SetEntProp()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Nezur0s
Junior Member
Join Date: Feb 2020
Old 02-17-2020 , 18:02   Difference between DispatchKeyValue() And SetEntProp()
Reply With Quote #1

Hello,I'am asking to know the difference between DispatchKeyValue() and SetEntProp(),

Someone already asked this question and he got told that DispatchKeyValue only works before entity spawn and that SetEntProp() only after spawn.
1) But I already saw someone using SetEntProp() before spawning it so are they all wrong ?!

Well i am gonna tell you what I thought i knew about how the memory management of an entity works

I thought all the properties were stored in precise offsets from the This pointer of the entity and you can edit those different values to make differents adjustements.
at this point I only knew about SetEntProp().
But after learning about DispatchKeyValue() I am getting really confused,
2) Does it create a new property for the object:

Like this object before didn't have the property "model", and you created a property named model for it .
that would mean you can create properties for everything you want with this command.
3) Or was there already a Key named model and you just inserted the value for it ???
4) Are the properties of enteties stored as I think? Like different offsets from the this pointer of the entity(I don't get where all of this KeyValue thing intervenes there)

TLDR:
-How are properties of enteties managed inside the memory before DispatchSpawn and after
DispatchSpawn.

-Why do we use two different functions (SetEntProp and DispatchKeyValue)
-Does dispatchKeyValue make a whole new property for the entity or does it just modify the old value of an already existing key,
And what happens if we don't set this KeyValue, Does the property remain and can we set it with SetEntProp.
I searched this topic for over 6 hours now and I think I am too lost to even know what to search for
Any help will be appreciated ,Thanks very much !

Last edited by Nezur0s; 02-20-2020 at 12:13. Reason: Clarity
Nezur0s is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 02-18-2020 , 09:04   Re: Difference between DispatchKeyValue() And SetEntProp()
Reply With Quote #2

SetEntProp allows you to change almost every entity property (for both net and data props).
You can dump these properties using sm_dump_netprops (also sm_dump_netprops_xml) and sm_dump_datamaps commands.
As i know DispatchKeyValue allows you to change only Key Value (entity properties marked with Key flag).

For example (from datamaps dump):
- m_iClassname (Offset 92) (Save|Key)(4 Bytes) - classname
In this case classname is the Key name and you can use DispatchKeyValue here,
m_iClassname is the property name and you must use Get/SetEntProp for this.
So, if you see Key flag (in brackets) you can propably use DispatchKeyValue.

Some properties don't have Key flag and Key name so you can't use DispatchKeyValue in this case.

Also, DispatchKeyValue used to modify only existing keys so you can use this plugin to set/get some custom keys.

So, you should use DispatchKeyValue only before spawning entities and only if property has key name (existing key).
In other cases use SetEntProp (even before DispatchSpawn).
__________________

Last edited by MAGNAT2645; 02-18-2020 at 09:11.
MAGNAT2645 is offline
Nezur0s
Junior Member
Join Date: Feb 2020
Old 02-18-2020 , 11:23   Re: Difference between DispatchKeyValue() And SetEntProp()
Reply With Quote #3

Thanks,So if dispatchKeyValue changes a property why can't we use it after entity spawn?
Nezur0s is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 02-18-2020 , 12:47   Re: Difference between DispatchKeyValue() And SetEntProp()
Reply With Quote #4

You can but shouldn't. Key Values are meant to setup entity before spawning it into game.
Entity Properties are their "real" values.
__________________
MAGNAT2645 is offline
Balimbanana
Member
Join Date: Jan 2017
Old 02-18-2020 , 13:41   Re: Difference between DispatchKeyValue() And SetEntProp()
Reply With Quote #5

There are certain things that you should always use DispatchKeyValue() instead of SetEntProp(). The engine handles DispatchKeyValue when setting up the entity before spawning. SetEntProp can change a lot of values after spawning. But a lot of properties are not networked, or don't update on the entity correctly for some engine calls.
For instance, "target", template, and npc makers will fail to initialize if you don't set them before spawning, and will auto delete themselves as null entities. Same with a lot of scripted entities: scripted_sequence, logic_choreographed_scene, etc.
When changing a classname, it can have very different outcomes if you set it by DispatchKeyValue or SetEntProp. Take something like a weapon.
Code:
int weapon = CreateEntityByName("weapon_pistol");
DispatchKeyValue(weapon,"classname","weapon_glock");
DispatchSpawn(weapon);
ActivateEntity(weapon);
This will actually create a base weapon_pistol, but then load the weapon script for a weapon_glock.
If you set the classname after the DispatchSpawn, the classname would be weapon_glock, but no properties of the weapon_glock would be read.
A majority of vehicles also must have all their values set before spawning or the console will be spammed with several errors constantly about uninitialized vehicles.

Basically, if there is a Key that you can set with DispatchKeyValue(), you should use that instead of SetEntProp() unless you can't because the entity is already spawned in.
Balimbanana is offline
Nezur0s
Junior Member
Join Date: Feb 2020
Old 02-19-2020 , 13:17   Re: Difference between DispatchKeyValue() And SetEntProp()
Reply With Quote #6

Thanks magnat and balimbanana but one final question after dumping data maps I noticed that the type of the property is not precised(like I don't know what type of Set/GetEntProp I should use)Is there a work around for this ?
Nezur0s is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 02-20-2020 , 06:47   Re: Difference between DispatchKeyValue() And SetEntProp()
Reply With Quote #7

sm_dump_netprops dumps Prop_Send (networkable) properties.
sm_dump_datamaps dumps Prop_Data properties.
__________________

Last edited by MAGNAT2645; 02-20-2020 at 06:49. Reason: Bold want some love
MAGNAT2645 is offline
Nezur0s
Junior Member
Join Date: Feb 2020
Old 02-20-2020 , 07:28   Re: Difference between DispatchKeyValue() And SetEntProp()
Reply With Quote #8

Ah Thanks that makes sense actually x)
Nezur0s is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:33.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode