[Help] Fivem Events Inheritance

Hey there,

Sorry for my bad english in advance,

Let’s say i am running a script and i want to trigger an event with a specific parameter so the event can get to an “if” function where depending on the trigger it runs a different case every time.

Lets say i have this on one script:

RegisterNetEvent("script1:security1")
AddEventHandler("script1:security", function()
	TriggerClientEvent("script2:event2")
end)

and the other script event is this:

RegisterNetEvent("script2:event")
AddEventHandler("script2:event",function()
script2Function()
end)

and the script2Function is this:

if securityAccount == 1 then
	TriggerServerEvent('script2:serverEvent')
elseif securityAccount == 2 then
				

how can i implement a value of securityAccount on the First event, so as the last function can inherit that value?

I hope this was undestandable!

its my first steps on OOP

1 Like

Hey,
you mean like

  1. server(script1) triggers client(script1) event with a parameter
  2. client handles request with a function, in which the paramerter gets processed

This would be:

Server(script1)

TriggerClientEvent("script1:security1", [client], [parameter])

Client(script1)

RegisterNetEvent("script1:security1")
AddEventHandler("script1:security1", function(parameter)
    script1Function(parameter)
end)

function script1Function(parameter)
    if parameter == 1 then
        TriggerServerEvent("script1:serverEvent")
    elseif parameter == 2
        ...
    end
end

Or do you really want to send from client(script1) to server(script1) and then to client(script2)? This would be:

Client(Script1)

TriggerServerEvent('script1:test', parameter)

Server(Script1)

RegisterNetEvent('script1:test', function(parameter)
    TriggerClientEvent('script2:test', source, parameter)
end)

Client(Script2)

RegisterNetEvent('script2:test', function(parameter)
    if parameter == 1 then
        TriggerServerEvent("script1:serverEvent")
    elseif parameter == 2
        ...
    end
end)

Or am I understanding you wrong?

1 Like

First off thanks for spending time helping me!

No this is my bad i didnt make this clear

a client script firstly calls the client event of another script like so:

RegisterNetEvent("script1:security1")
AddEventHandler("script1:security", function()
	TriggerEvent("script2:event2")
end)

and then the other script’s client event (script2:event2) calls a function within it (within the client of script2) like so:

RegisterNetEvent("script2:event2")
AddEventHandler("script2:event2",function()
script2Function()
end)

and then somewhere within the code of script2function(), an if statement takes place (that calls a server event from script2’s server side) like so:

if parameter== 1 then
	TriggerServerEvent('script2:serverEvent')
elseif parameter == 2 then

BASICALLY
my problem is how do i make several cases of the parameter (with different values (like 1 or 2)
(in order to execute the code i want in every case) and how do i inherit the parameters from script1’s client event UP UNTIL script2’s client side!

RegisterNetEvent("script1:security1")
AddEventHandler("script1:security", function()
	TriggerEvent("script2:event2", param)
end)

RegisterNetEvent("script2:event2")
AddEventHandler("script2:event2",function(param)
script2Function(param)
end)

function script2Function(parameter)
if parameter== 1 then
	TriggerServerEvent('script2:serverEvent')
elseif parameter == 2 then
end
end
1 Like

what if i wanna set parameter = 1 on the first event on script 1?

and transfer its value all the way down to the script2Function?

Ok, here’s how it works. When creating an Event Handler, every parameter that you add in it’s function, will become parameters that you can use when triggering that event. Example:

AddEventHandler("script1:security", function(param1, param2, param3, param74759)
	print(param1)
print(param2)
print(param3)
print(param74759)
end)
-- this handle now has 4 params...sooooo
TriggerEvent("script1:security", 1,2,3,4) --this will print 1 2 3 4 in client console.

so basically in my case, i have to do it like that?

RegisterNetEvent("script1:security1")
AddEventHandler("script1:security", function(parameter)
	TriggerEvent("script2:event2", parameter)
end)

RegisterNetEvent("script2:event2")
AddEventHandler("script2:event2",function(parameter)
script2Function(parameter)
end)

function script2Function(parameter)
if parameter== 1 then
	TriggerServerEvent('script2:serverEvent')
elseif parameter == 2 then
end
end

and for every different parameter value i do

TriggerEvent("script1:security", 1)

OR

TriggerEvent("script1:security", 2)
1 Like

pretty much, yeah.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.