Team Spartan Cookies & Milk Forums
  • Issue Tracker
  • Donations
  • Search
  • Member List
  • Help

Register

Team Spartan Cookies & Milk Forums Garry's Mod Starfall v
1 2 3 4 5 … 18 Next »
Spooky action at a distance, remote callbacks (server only, client doesnt work?)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Linear Mode
Spooky action at a distance, remote callbacks (server only, client doesnt work?)
21-09-2025, 06:10 PM,
#1
Caprica Offline
Valued donator and member
****
Posts: 76
Threads: 24
Joined: Aug 2020
Spooky action at a distance, remote callbacks (server only, client doesnt work?)
It is entirely possible to trigger a callback on a different starfall chip (if both are on servers).
Below is  code that sends a function via channels, and in a different starfield chip I do a callback, and it will call the function (on the original chip).
I have found it very useful. Though you cannot do the same with net (see bottom).



    hook.add( "playerbuttonup", "hookname", function( ply, key )

        if ( key == input.KEY_8 ) then

            print('SenderServer trigger')

            if ( channels.canSend() ) then

                local command = {}
                command["callback"] = function(response)

                    print('SenderServer ' .. response)
                    serverResponse = response

                end

                channels.sendPrivate(command)

            end

        elseif ( key == input.KEY_7 ) then

            print(serverResponse)

        end

    end )

--ENTIRELY SEPERATE STARFALL--
channels.listenPrivate( 'ReceiverTest', function(chip, received)

        print('ReceiverNet received')

        received["callback"](time.curTime())

    end )


--NET Configuration--

In this scenario, the callback doesnt work, as the function is not sent. If you print the table out the function is missing, i do not know if it was intentional. If it was possible to do this, it would be very cool as you could access variables directly. 



if ( SERVER ) then

    hook.add( "net", "hookname", function( length, player )

        local received = net.readTable()

        received["callback"](time.curTime())

    end )

    hook.add( "playerbuttonup", "hookname", function( ply, key )

        if ( key == input.KEY_8 ) then

            print('SenderServer trigger')

            if ( channels.canSend() ) then

                local command = {}
                command["callback"] = function(response)

                    print('SenderServer ' .. response)
                    serverResponse = response

                end

                channels.sendPrivate(command)

            end

        elseif ( key == input.KEY_7 ) then

            print(serverResponse)

        end

    end )

elseif ( CLIENT ) then


    hook.add( "playerbuttonup", "hookname", function( ply, key )

        if ( key == input.KEY_9 ) then

            print('SenderClient trigger')

            if ( net.start() ) then

                local command = {}
                command["callback"] = function(response)

                    print('SenderClient ' .. response)

                end

                net.writeTable(command)

                net.sendToServer()

            end

        end


    end )

end

Find
Reply
« Next Oldest | Next Newest »


Messages In This Thread
Spooky action at a distance, remote callbacks (server only, client doesnt work?) - by Caprica - 21-09-2025, 06:10 PM
RE: Spooky action at a distance, remote callbacks (server only, client doesnt work?) - by The17thDoctor - 22-09-2025, 03:28 AM
RE: Spooky action at a distance, remote callbacks (server only, client doesnt work?) - by Caprica - 22-09-2025, 03:14 PM

  • View a Printable Version
Forum Jump:


Users browsing this thread: 1 Guest(s)
Contact UsTeam Spartan Cookies & MilkReturn to TopLite (Archive) ModeMark all forums readRSS Syndication

Powered By MyBB, © 2002-2026 MyBB Group.