Jump to content

Triggerclientevent event gets executed before server functio


aintaro

Recommended Posts

Hello guys,

The problem is I want my server sided function to finish before it executes the triggerClientEvent.

Here is the code server sided:

local vc1, vc2, vc3, vc4 
function spawnOwnedVehicle(source, commandName, vehicleType) 
     
    for y = 1, table.getn(playerVehicle) do 
        outputChatBox(vehicleType) 
        --if (playerVehicle[y] == tonumber(vehicleType)) then --found vehicle now load colors plx 
            for x = 1, 5 do 
                --outputChatBox(tostring(playerVehicle[y][x])) 
                if (x == 2) then 
                    vc1 = playerVehicle[y][x]  --loading colors 
                    outputChatBox(vc1) 
                elseif (x == 3) then 
                    vc2 = playerVehicle[y][x]  --loading colors 
                elseif( x== 4) then 
                    vc3 = playerVehicle[y][x]  --loading colors 
                elseif (x== 5) then 
                    vc4 = playerVehicle[y][x]  --loading colors 
                end 
            end 
        --end 
         
    end 
outputChatBox("Server send the trigger") 
    triggerClientEvent ( "spawnPersonalVehicle", getRootElement(), spawnPersonalVehicle,  vehicleType, vc1, vc2, vc3, vc4) --send the configs to the client so we can spawn this vehicle 
end 
  
  
  
addCommandHandler("spawnvehicles", spawnOwnedVehicle, source) 

code client sided :

function spawnPersonalVehicle(localPlayer, pvehicleId, pvc1, pvc2 ,pvc3, pvc4) 
   outputChatBox("Client got the server trigger") 
    outputChatBox(pvehicleId) 
    outputChatBox("pvc1"..pvc1) 
    outputChatBox("pvc2"..pvc2) 
    outputChatBox("pvc3"..pvc3) 
    outputChatBox("pvc4"..pvc4) 
    local x, y , z = getElementPosition(source) 
    local personalVehicle = createVehicle ( getVehicleNameFromModel ( tonumber(pvehicleId) ), x + 5, y, z) 
    setVehicleColor ( personalVehicle, tonumber(pvc1), tonumber(pvc2), tonumber(pvc3), tonumber(pvc4)) 
end 
addEvent("spawnPersonalVehicle", true) 
addEventHandler("spawnPersonalVehicle", root, spawnPersonalVehicle) 
  

output :

Client got the server trigger

[some parameters]

Server send the trigger

ps : No idea why lua tags are not working :S

Thanks in advance,

Greetz Aintaro

Link to comment

The server side script does load before triggering client event, it's just that outputChatBox server side seems to have lower priority than triggerClientEvent or something so triggerClientEvent is processed before outputChatBox.

So you dont have to worry about it.

Link to comment
The server side script does load before triggering client event, it's just that outputChatBox server side seems to have lower priority than triggerClientEvent or something so triggerClientEvent is processed before outputChatBox.

So you dont have to worry about it.

It also does something to do with your connection, and its related to this. you will see almost the same effect going from client to server side.

Link to comment

I'm not sure, but I have seen the Chat being really laggy on certain servers because of blocked traffic.

I don't know how their scripts look like but triggerLatentClientEvent got this written down in wiki:

"...other network traffic is not blocked while the data is being transferred."

Maybe you should try that.

Link to comment
I'm not sure, but I have seen the Chat being really laggy on certain servers because of blocked traffic.

I don't know how their scripts look like but triggerLatentClientEvent got this written down in wiki:

"...other network traffic is not blocked while the data is being transferred."

Maybe you should try that.

thanks man ,I didn't know that

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...