Author Topic: LAN Code Problem  (Read 714 times)

I recently started hosting LAN so that my brother and I could play together. We were having fun and going about when it came to a building script, with us requiring resources. The problem was I had the resources and he didn't, so when I tried building it tried using his resources rather than mine. I think this is due to the fact that while playing LAN, Blockland thinks we are using the same key since we have the same BLID, LAN. So since he was the last to join, the function attempts to use him as the player who is trying to build, when I am trying to build and he isn't. I whipped up this code in attempt for a fix but to no avail:
Code: [Select]
if(%client.bl_ID == 999999)
{
for (%i = 0; %i < ClientGroup.getCount(); %i++)
{
if(ClientGroup.getObject(%i).RPData.value["login"] $= "Gordo12699")
{
%playercheck++;
}

if(%playercheck >= 1)
{
if (%brick.client.RPData.value["login"] $= "Gordo12699")
{
%client = findclientbyname("Gordo12699");
warn("Add-Ons/RP_Money/bricks.cs (39): Client Login Name Gordo12699 found. Setting %client to whoevers login name is Gordo12699...");
}
else
{
warn("Add-Ons/RP_Money/bricks.cs (43): No Login Name found. Will not change %client value.");
}
}
}
}
If anyone can find a fix for when I try to build it uses his resources but when he tried to build it doesn't use my resources problem, that would be greatly appreciated.

Edit: When i try planting a brick it echos: No Login Name found. Will not change %client value. Even when I am logged in.
« Last Edit: February 06, 2013, 05:56:52 PM by Gordo12699 »

bump. still looking for some help :/

Firstly, where did you put this code? Where is it located in the bigger script?



if(%client.bl_ID == 999999)
      {
         for (%i = 0; %i < ClientGroup.getCount(); %i++)
         {
            if(ClientGroup.getObject(%i).RPData.value["login"] $= "Gordo12699")
            {
               %playercheck++; Why are you using an integer instead of a boolean?
            }
         
            if(%playercheck >= 1) Use a boolean and check for it here
            {
               if (%brick.client.RPData.value["login"] $= "Gordo12699") Bricks don't have clients
               {
                     You set %client and then don't do anything with it? Why is this necessary?
                  %client = findclientbyname("Gordo12699");
                  warn("Add-Ons/RP_Money/bricks.cs (39): Client Login Name Gordo12699 found. Setting %client to whoevers login name is Gordo12699...");
               }
               else
               {
                  warn("Add-Ons/RP_Money/bricks.cs (43): No Login Name found. Will not change %client value.");
               }
            }
         }
      }



Comments in bold.

Also why can't you just disable whatever add-on is causing the problem? Do you need it enabled?
« Last Edit: February 07, 2013, 09:11:23 PM by AlsoSulfate »

if (%brick.client.RPData.value["login"] $= "Gordo12699") Bricks don't have clients
Bricks do have a client


This script should be somewhere packaged into a function called with the RP script when planting a brick, I assume. I have no idea if he actually placed it there.

The other things he pointed out in your script need to be changed.
Why not just make this much simpler, whenever the RP script calls for resources, just do the findClientByName("Gordo12699") and if the client doesnt exist, then throw the error and return.

Code: [Select]
%client = findClientByName("Gordo12699");
if(!isObject(%client))
{
echo("Didn't find him, boss");
return;
}
//Code here that does all the resources and what not with the correct client

All this has to be put into the correctly packaged function remember

Bricks do have a client

Hm. Learn something new every day I guess. I assumed you'd need a method to get it but I guess not.

The script is in the package I made that calls a function whenever a brick is planted and the %client is set for the rest of the code having to do with resources and whatnot and I couldn't make it do it so when the brick is planted it has to find my name and set that as the client because there are two players in the LAN server and I don't want it to so when my brother plants a brick it wastes my bricks. See, the problem is that when my brother plants a brick it wastes His resources and when I plant a brick it wastes his resources, I want it so we waste our own resources individually and I don't understand what you mean by use a Boolean. Please make an example or explain the Boolean factor you are talking about and I do need this add-on enabled for testing purposes. DYLANzzz I haven't tried your little script but I will try it, althought I do not have my hopes up.

The script is in the package I made that calls a function whenever a brick is planted and the %client is set for the rest of the code having to do with resources and whatnot and I couldn't make it do it so when the brick is planted it has to find my name and set that as the client because there are two players in the LAN server and I don't want it to so when my brother plants a brick it wastes my bricks. See, the problem is that when my brother plants a brick it wastes His resources and when I plant a brick it wastes his resources, I want it so we waste our own resources individually and I don't understand what you mean by use a Boolean. Please make an example or explain the Boolean factor you are talking about and I do need this add-on enabled for testing purposes. DYLANzzz I haven't tried your little script but I will try it, althought I do not have my hopes up.
Ooooh, I thought you wanted it so your brother uses your resources so he could build (because he didnt have sufficient or something). Btw, all my script does is find you, because I thought this is what you wanted.
The other thing is, you say that you packaged it so that whenever you plant a brick it sets the client. I'm not sure if you understand this but setting %client doesnt set it for the entire script, just your little section (where the variable is in scope).

I think the way to fix your problem will be to actually modify the RP script itself as packaging the fxDTSBrick:onPlant function wouldn't be sufficient (no idea how the RP mod gets its client but it's not something a package can fix). I'm assuming the RP script gets the client from a BL_ID somewhere which is why it's getting you instead of him. You're going to have to modify where ever it does that so it gets it though some other means that doesn't rely on the BL_ID because it just wouldn't be accurate in the case of a LAN server.

Sad faec, Alright, thanks.