Jump to content

[Help]Client shoud call up Server Funktion[Help]


cs8898

Recommended Posts

Hy guys

my client-script had to start a server funktion

but if i say

client:

 spawnInf () 

and the server:

function spawnInf(playerSource) 
car_id = getVehicleModelFromName ( "infernus" ) 
x,y,z = -1928, 272, 41 
createVehicle ( car_id, x, y, z, 0, 0, 180,getPlayerName(playerSource) ) 
outputChatBox ( "Order is at issue",playerSource, 255, 0, 255) 
end 

nothing happend but why

please help me

WFG

cs8898

Link to comment

Create an event with createEvent and call the event:

Call server event from client: triggerServerEvent

Call client event from server: triggerClientEvent

Call event from same side: triggerEvent

You can also use functions from Wiki "callClientFunction" and "callServerFunction" or this:

Client-side:

local aReturnValue = { } 
addEvent( 'OnServerCallClientFunction', true ) 
addEvent( 'OnFunctionCallGetReturn', true ) 
  
addEventHandler( 'OnFunctionCallGetReturn', root, 
    function( fn, returnValue ) 
        aReturnValue[fn] = returnValue 
    end 
) 
  
addEventHandler( 'OnServerCallClientFunction', root, 
    function( fn, ... ) 
        if( #{ ... } ~= 0 ) then 
            aReturnValue[fn] = _G[fn]( ... ) 
            triggerServerEvent( 'OnFunctionCallGetReturn', root, fn, aReturnValue[fn] ) 
        else 
            aReturnValue[fn] = _G[fn]( ) 
            triggerServerEvent( 'OnFunctionCallGetReturn', root, fn, aReturnValue[fn] ) 
        end 
    end 
) 
  
function callServerFunction( fn, ... ) 
    if( fn and type( fn ) == 'string' ) then 
        if( #{ ... } ~= 0 ) then 
            triggerServerEvent( 'OnClientCallServerFunction', root, fn, ... ) 
        else 
            triggerServerEvent( 'OnClientCallServerFunction', root, fn ) 
        return aReturnValue[fn] or false 
    end 
end 

Server-side:

local aReturnValue = { } 
addEvent( 'OnClientCallServerFunction', true ) 
addEvent( 'OnFunctionCallGetReturn', true ) 
  
addEventHandler( 'OnFunctionCallGetReturn', root, 
    function( fn, returnValue ) 
        aReturnValue[fn] = returnValue 
    end 
) 
  
addEventHandler( 'OnClientCallServerFunction', root, 
    function( fn, ... ) 
        if( #{ ... } ~= 0 ) then 
            aReturnValue[fn] = _G[fn]( ... ) 
            triggerClientEvent( 'OnFunctionCallGetReturn', root, fn, aReturnValue[fn] ) 
        else 
            aReturnValue[fn] = _G[fn]( ) 
            triggerClientEvent( 'OnFunctionCallGetReturn', root, fn, aReturnValue[fn] ) 
        end 
    end 
) 
  
function callClientFunction( fn, ... ) 
    if( fn and type( fn ) == 'string' ) then 
        if( #{ ... } ~= 0 ) then 
            triggerClientEvent( 'OnServerCallClientFunction', root, fn, ... ) 
        else 
            triggerClientEvent( 'OnServerCallClientFunction', root, fn ) 
        return aReturnValue[fn] or false 
    end 
end 

Not tested.

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...