Is it possible to pass a lot variables to a custom-effect?

Hello.

Right now I’m working on some lua-made effects, but I currently have a problem.

The CEffectData metatable doesn’t include enough functions to pass all the required information from my script to my custom effect. :bang:
Does anyone know a way to pass a lot of information to an effect (preferred in a table format).
Possibly by creating a new function in the CEffectData metatable (But how? I can’t do self.WhateverVar = 123 within the new function, because an effect is a userdata value, it’ll give an error.)?

I know that I can hack around this problem by using global variables, but that looks incredible messy.

You could create more functions in the metatable. I haven’t worked much on effects, but I assume it would do what you wanted.

Edit: Just read that. Try it anyway, it will most likely work.

How much info are you trying to pass?

Nope it won’t.

[lua]–Clientside
local CEffectDataMeta = FindMetaTable(“CEffectData”)

function CEffectDataMeta:GetTable() --I tried _R.CEffectData instead of CEffectDataMeta too.
return self.DataTable
end

function CEffectDataMeta:SetTable(tbl)
self.DataTable = tbl
end[/lua]

Timer Error: …memode\g_extensions/client/metatable_CEffectData.lua:9: attempt to index local ‘self’ (a userdata value)
(Function is being called within a timer)

[editline]10:53PM[/editline]

Around 6 variables, including floats and tables. The definitive amount is unknown right now, as the script I’m working on is still a huge WIP.

Can’t you send any values with the default metatable functions?

What you could do is pass a Dummy Sent with it!

SENTS take up a lot more resources compared to a simple global variable. So this would be very inefficient to do.

Start, Normal, and the other position value all accept vectors as arguments. You could stick as much data into vectors as you could there.

Alternately, usermessage the data to the clients and create the effect clientside, but only if you can’t shoe-horn it in with the pre-existing functions.

SetNormal most likely doesn’t have a lot of precision, as it’s most likely sent with fewer bits than your usual vector.

I just had this crazy idea; maybe it works like usermessages, so you can use SetEntity etc. multiple times, and then read them multiple times.

SERVER
[lua]
effect:SetEntity(ent1)
effect:SetEntity(ent2)
[/lua]

EFFECT
[lua]
local ent1 = data:GetEntity()
local ent2 = data:GetEntity()
[/lua]

Has anyone tested this?

Effects can be issued clientside or serverside; so why not try using Usermessages to pass data and then running your effect?

You can use a usermessage to include any additional data you may need. When the usermessage is received clientside, the hook that handles it can read the data contained in it to a temporary table, and then create the effect you intended, which then will grab the temporary table you created.

It’s sort of hacky, but maybe something like this would work:
[lua]
function EFFECT:Init()
if _ExtraEffectData then
self.EffectData=_ExtraEffectData;
_ExtraEffectData=nil;
end
end
[/lua]

I don’t know why we can’t just grab the effect entity after creating an effect… that would give us access to it’s table at least.