Desblat Posted June 17, 2015 Share Posted June 17, 2015 (edited) For my mod I need to handle transfering data from client to host.I tried to do it in this way:-------------------------------------------------------------------------------------|||dc_target - is a component added to player.||| ......................... local player = self.inst -- target playerlocal appearence = "willow" -- string variablelocal nameof = "desblat" -- string variablelocal colour = {0.6,0.5,0.7} -- table variablelocal comedelay = 15 -- integer variablelocal leavedelay = 15 -- integer variableprint("==CLIENT SIDE== SENDING RPC----")SendModRPCToServer(MOD_RPC[modname]["DES_DARK_CLONE"], player, appearence, nameof, phrase, colour, comedelay, leavedelay)......................... -------------------------------------------------------------------------------------|||Modmain|||AddModRPCHandler(modname, "DES_DARK_CLONE", function(player, appearence, nameof, phrase, colour, comedelay, leavedelay)DesblatDarkCloneCall(player, appearence, nameof, phrase, colour, comedelay, leavedelay)end)function DesblatDarkCloneCall(player, appearence, nameof, phrase, colour, comedelay, telldelay, leavedelay)--placeholder for nowprint(appearence)print(nameof)print(comedelay)print(leavedelay)end----------------------------------------------------------------------------------------But this doesn't work. I guess the problem is with the RPC handling... Here is what log says:----------------------------------------------------------------------------------------||| log |||[00:03:19]: ==CLIENT SIDE== SENDING RPC----[00:03:19]: Invalid RPC data type[00:03:23]: Attempting to send resume request[00:03:23]: ReceiveResumeRequest[00:03:23]: Received request to resume from: session/08E000010992E3DE/KU_Rx7d8vZ__/0000000002[00:03:23]: OnResumeRequestLoadComplete - UserID KU_Rx7d8vZ_[00:03:23]: [Load] SPAWNING PLAYER AT: (-178.55, 0.00, 66.45)----------------------------------------------------------------------------------------Everytime I send RPC log says: "Invalid RPC data type", "Attempting to send resume request", "ReceiveResumeRequest"... And charcter gets reloaded into the game!What I am doing wrong? Edited June 17, 2015 by Desblat Link to comment Share on other sites More sharing options...
DarkXero Posted June 17, 2015 Share Posted June 17, 2015 The variable modname outside modmain is nil. Also, the player parameter gets sent by default, you don't put it as a parameter in SendModRPCToServer. So:-- |||dc_target - is a component added to player.|||SendModRPCToServer(MOD_RPC["des_dark_demon"]["DES_DARK_CLONE"], appearence, nameof, phrase, colour, comedelay, leavedelay)-- |||Modmain|||AddModRPCHandler("des_dark_demon", "DES_DARK_CLONE", function(player, appearence, nameof, phrase, colour, comedelay, leavedelay) DesblatDarkCloneCall(player, appearence, nameof, phrase, colour, comedelay, leavedelay)end) Link to comment Share on other sites More sharing options...
Desblat Posted June 17, 2015 Author Share Posted June 17, 2015 The variable modname outside modmain is nil. Also, the player parameter gets sent by default, you don't put it as a parameter in SendModRPCToServer. So:-- |||dc_target - is a component added to player.|||SendModRPCToServer(MOD_RPC["des_dark_demon"]["DES_DARK_CLONE"], appearence, nameof, phrase, colour, comedelay, leavedelay)-- |||Modmain|||AddModRPCHandler("des_dark_demon", "DES_DARK_CLONE", function(player, appearence, nameof, phrase, colour, comedelay, leavedelay) DesblatDarkCloneCall(player, appearence, nameof, phrase, colour, comedelay, leavedelay)end)Thanks for the answer.But I still have the problem...I changed the code as you suggested:--dc targetSendModRPCToServer(MOD_RPC["DES_DARK_DEMON_MOD"]["DES_DARK_CLONE"], appearence, nameof, phrase, colour, comedelay, telldelay, leavedelay)-------------------------------mod mainAddModRPCHandler("DES_DARK_DEMON_MOD", "DES_DARK_CLONE", function(player, appearence, nameof, phrase, colour, comedelay, telldelay, leavedelay) DesblatDarkCloneCall(player, appearence, nameof, phrase, colour, comedelay, telldelay, leavedelay) print("==SERVER SIDE== SERVER GOT REQUEST FROM DARK CLONE")end)I am still getting this weird strings in the log:[00:04:16]: ==CLIENT SIDE== ATTEMP TO BUILD CLONE [00:04:16]: building phrase [00:04:16]: torch phrase [00:04:16]: ==CLIENT SIDE== nameof = farmsloth [00:04:16]: ==CLIENT SIDE== appearance= wolfgang [00:04:16]: ==CLIENT SIDE== Phrase = Testing mod [00:04:16]: Invalid RPC data type[00:04:22]: ==CLIENT SIDE== NO DARKCLONE RETURN[00:04:22]: Attempting to send resume request[00:04:22]: ReceiveResumeRequest[00:04:22]: Received request to resume from: session/08E000010992E3DE/KU_Rx7d8vZ__/0000000003[00:04:22]: OnResumeRequestLoadComplete - UserID KU_Rx7d8vZ_[00:04:22]: ==CLIENT SIDE== DC_TARGET COMP IN GAME [00:04:23]: [Load] SPAWNING PLAYER AT: (-178.55, 0.00, 66.45) [00:04:23]: ReceiveResumeNotification[00:04:23]: Loading minimap from session/08E000010992E3DE/KU_Rx7d8vZ__/minimap[00:04:23]: Deserializing cached icon data: 64[00:04:23]: Deserializing tile data (425 x 425)[00:04:23]: ==CLIENT SIDE== ATTEMP TO BUILD CLONE This is endless loop. I load into the world, dc_target sends request to the server and... I am getting reloaded once again, I regain all stats, position, inventory. And the loop starts again...[00:04:16]: Invalid RPC data typeIs this a problem? Why so? Link to comment Share on other sites More sharing options...
DarkXero Posted June 18, 2015 Share Posted June 18, 2015 @Desblat, what are you trying to do?You have a component that sends an RPC to the server to do something? Perhaps if you put the RPC send in the component initialization, then something may be amiss.Post the mod. Also, dc target is inside modmain or is a separate component in the folder? Link to comment Share on other sites More sharing options...
Desblat Posted June 18, 2015 Author Share Posted June 18, 2015 @Desblat, what are you trying to do?You have a component that sends an RPC to the server to do something? Perhaps if you put the RPC send in the component initialization, then something may be amiss.Post the mod. Also, dc target is inside modmain or is a separate component in the folder? The mod adds this: If player is alone and he has low sanity the dark demon will appear - he looks like another player, has name, equipment, clone says random phrase wonders around and disappears coming off-screen. dc_target is a sepate component. This component is added to the player. dc_target component builds the demon up - setting name, stats, phrase etc, after building clone it sends it to the server, so server will spawn the demon. This is the only way I found to make clone work properly (especially to make his speech work as speech of real player). darkclone is a mob what server spawns. Here is the mod:desblat dark demon.zip Link to comment Share on other sites More sharing options...
DarkXero Posted June 18, 2015 Share Posted June 18, 2015 @Desblat, I found the issue: you can't send tables as parameters. Colour is a table, an invalid RPC data type. You should send colour1, colour2, and colour3 (replacing colour in the SendRPC), then make up the table inside the handler and pass it to your function. In your function some names were wrong and some globals were missing. I corrected all this. The problem here is that there are a lot of components and replicas added here and there server and client side, which will result in many crashes. I also saw that you replaced GetPlayer() with ThePlayer, which will make all clones be related to the host, since when running server side code, ThePlayer is the host. You got a lot of work ahead. After all, I don't think sending a RPC is needed, but do what you want. Link to comment Share on other sites More sharing options...
Desblat Posted June 18, 2015 Author Share Posted June 18, 2015 @Desblat, I found the issue: you can't send tables as parameters. Colour is a table, an invalid RPC data type. You should send colour1, colour2, and colour3 (replacing colour in the SendRPC), then make up the table inside the handler and pass it to your function. In your function some names were wrong and some globals were missing. I corrected all this. The problem here is that there are a lot of components and replicas added here and there server and client side, which will result in many crashes. I also saw that you replaced GetPlayer() with ThePlayer, which will make all clones be related to the host, since when running server side code, ThePlayer is the host. You got a lot of work ahead. After all, I don't think sending a RPC is needed, but do what you want.Thanks a lot for help. Now it works!I am learning new functions for now. This simple data-transfer is the key for the more complex mods such as Thirst, Injuries, there I don't know how to code without RPC requests. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now