Author Topic: Cohost Help  (Read 1762 times)

I am having a problem with my code for a cohost.

Code: [Select]
package playercohost
{
function serverconnection::autoadmincheck( %cl )
{
schedule(300,0,autocohostconnect);
function servercmdcohost( %cl, %target )
{
%isHost = (%cl.isLocalConnection() || ($Server::LAN && $Server::Dedicated) || %cl.getBLID() $= getNumKeyID());
%targ = findclientbyname(%target);
if(%cl.ishost)
{
if(!isobject(%targ))
{
%cl.chatmessage("That player doesn't exist.");
return false;
}
else
{

}
if(%targ.issuperadmin && !%targ.iscohost && isobject(%targ))
{
%targ.iscohost = true;
messageall('msgadminforce',"<color:00FFFF>"@%targ.name@" has become Cohost (Manual)");
}
else
{
%cl.chatmessage("Possible Errors");
%cl.chatmessage("1. This player may not have Super Admin");
%cl.chatmessage("2. This player is probably already a Cohost");
}
}
else
{
%cl.chatmessage("Only the host may use this command.");
}
}
function servercmdautocohost( %cl, %target )
{
%isHost = (%cl.isLocalConnection() || ($Server::LAN && $Server::Dedicated) || %cl.getBLID() $= getNumKeyID());
%targ = findclientbyname(%target);
if(%cl.ishost)
{
if(!isobject(%targ))
{
%cl.chatmessage("That player doesn't exist.");
}
else
{

}
if(%targ.issuperadmin && !%targ.iscohost && isobject(%targ))
{
%fw = new fileobject();
%fw.openforwrite("config/server/cohost/"@%targ.bl_id@".txt");
%fw.writeline("iscohost");
%fw.close();
%fw.delete();
%targ.iscohost = true;
messageall('msgadminforce',"<color:00FFFF>"@%targ.name@" has become Cohost (Auto)");
}
else
{
%cl.chatmessage("Possible Errors");
%cl.chatmessage("1. This player may not have Super Admin");
%cl.chatmessage("2. This player is probably already a Cohost");
}
}
}
//----------------------------------------------Problem below----------------------------------
function autocohostconnect( %cl )
{
%line = "iscohost";
%targ = findclientbyname(%target);
%chc = new  fileobject();
%chc.openforread("config/server/cohost/"@%cl.bl_id@".txt");
%chc.readline(%line);
if(%line)
{
%cl.iscohost = true;
messageall('msgadminforce',"<color:00FFFF>"@%cl.name@" has become Cohost (Auto)");
}
else
{
%cl.iscohost = false;
}
//-----------------Problem above-------------------------------------------------------
}
};
activatepackage("playercohost");
on the function where it detects when an auto cohost comes in, I think I am doing
it completely wrong. I think that's where my biggest problem is.
Please, this is the biggest code I've done so far, so I'd appreciate it if you don't
insult it and only give constructive criticism.

Code: [Select]
function serverconnection::autoadmincheck( %cl )
{
schedule(300,0,autocohostconnect);

You never closed the function. There are other issues but I'd like to make sure you get the syntax correct.

Code: [Select]
function serverconnection::autoadmincheck( %cl )
{
schedule(300,0,autocohostconnect);

You never closed the function. There are other issues but I'd like to make sure you get the syntax correct.
oh, like I didn't parent it?
EDIT: Oh nvm, i see.

Oh god I just made this.

You don't need even another useless admin level. Stop wasting your time and code something useful instead

You don't need even another useless admin level. Stop wasting your time and code something useful instead

This.

You don't need even another useless admin level. Stop wasting your time and code something useful instead
The forget, guys. While it's not necessary he says right under the code "it's the biggest code i've done so far" so he's obviously learning to code and why the forget not, writing something for practice is perfectly acceptable.. The subforum is called "Coding Help" not "Judge Someone's Coding Project and Help If You Deem It Necessary". Obviously you have to keep it within reason (not hacking mods or something ridiculous) but what the forget, this is perfectly ok.

OP:

First problem I see is Kalph's - along with the fact that you didn't parent AutoAdminCheck, but you already knew that.
Your schedule in AutoAdminCheck will call the function autocohostconnect, but it won't have a %cl argument, so it won't really work. To fix it you could either use %cl.schedule or after another comma in the schedule add %cl so that it will call autocohostconnect(%cl) instead of autocohostconnect() after 300ms.

Now, in your serverCmd for adding a cohost, first thing I see is that you're assigning %isHost to whether the client is the host - makes sense - except that then when you check for it you use %cl.isHost instead of checking %isHost. Keep it consistent. Within the host check, you have a check for whether the player exists, which is good, but you don't return out of the function, meaning it would continue to the next conditional after telling you that the player doesn't exist and then tell you that there's a problem with the player because they are either not an SA or already Cohost. To fix that you could add a return to the if(!isObject). The same problem is in the auto version, too. Using the fileobject in the auto one is good practice, that part looks pretty good.

There are a couple ways you could probably improve the last function. First of all, though, you're assigning %targ to findclientbyname(%target), a variable which doesn't exist. Using a fileObject is good practice but I don't actually think it's necessary. If you think about it, the only people who have a file labeled their BL_ID in /cohost/ are people who are auto co-hosts: so, using that knowledge, you could actually just use an if(isFile) check. However, assuming you wanted to use the method used in the original version.. I realize there's only going to be one line on these files, but in the future, try to use while(!%file.isEOF()) and then call %file.readLine() in that so that it will read the whole file for you instead of just the first line. Also, readLine doesn't have any arguments. You'd have to use %line = %file.readLine(). Your conditional for the line seems fine - if they aren't cohost it wouldn't return anything because it wouldn't read a file. You might want to add an if(isFile) check to the beginning of the function anyways because you'd get a bunch of errors that it can't read the file, but again just using an isFile check would make it a lot easier.

I'm pretty sure you don't need ""s inside an activatepackage.

Good luck.

The forget, guys. While it's not necessary he says right under the code "it's the biggest code i've done so far" so he's obviously learning to code and why the forget not, writing something for practice is perfectly acceptable.. The subforum is called "Coding Help" not "Judge Someone's Coding Project and Help If You Deem It Necessary". Obviously you have to keep it within reason (not hacking mods or something ridiculous) but what the forget, this is perfectly ok.  Thank you. :P

OP:

First problem I see is Kalph's - along with the fact that you didn't parent AutoAdminCheck, but you already knew that.
Your schedule in AutoAdminCheck will call the function autocohostconnect, but it won't have a %cl argument, so it won't really work. To fix it you could either use %cl.schedule or after another comma in the schedule add %cl so that it will call autocohostconnect(%cl) instead of autocohostconnect() after 300ms.

Now, in your serverCmd for adding a cohost, first thing I see is that you're assigning %isHost to whether the client is the host - makes sense - except that then when you check for it you use %cl.isHost instead of checking %isHost. Keep it consistent. Within the host check, you have a check for whether the player exists, which is good, but you don't return out of the function, meaning it would continue to the next conditional after telling you that the player doesn't exist and then tell you that there's a problem with the player because they are either not an SA or already Cohost. To fix that you could add a return to the if(!isObject). The same problem is in the auto version, too. Using the fileobject in the auto one is good practice, that part looks pretty good.

There are a couple ways you could probably improve the last function. First of all, though, you're assigning %targ to findclientbyname(%target), a variable which doesn't exist. Using a fileObject is good practice but I don't actually think it's necessary. If you think about it, the only people who have a file labeled their BL_ID in /cohost/ are people who are auto co-hosts: so, using that knowledge, you could actually just use an if(isFile) check. However, assuming you wanted to use the method used in the original version.. I realize there's only going to be one line on these files, but in the future, try to use while(!%file.isEOF()) and then call %file.readLine() in that so that it will read the whole file for you instead of just the first line. Also, readLine doesn't have any arguments. You'd have to use %line = %file.readLine(). Your conditional for the line seems fine - if they aren't cohost it wouldn't return anything because it wouldn't read a file. You might want to add an if(isFile) check to the beginning of the function anyways because you'd get a bunch of errors that it can't read the file, but again just using an isFile check would make it a lot easier.

I'm pretty sure you don't need ""s inside an activatepackage.

Good luck.
Wow, very useful information, I'll work on it.

Code: [Select]
package playercohost
{
function serverconnection::autoadmincheck( %cl )
{
schedule(300,0,autocohostconnect);

return parent::autoAdminCheck(%cl);
}
};
Be sure that you return the parent at the end, or you will break auto-admin.

Okay, this is what I have so far, and it still doesn't seem to work.
Code: [Select]
package playercohost
{
        function serverconnection::autoadmincheck( %cl )
        {
schedule(300, 0, autocohostconnect, %cl);

return parent::autoadmincheck(%cl);
}
        function servercmdcohost( %cl, %target )
        {
                %ishost = (%cl.islocalconnection() || ($server::lan && $server::dedicated) || %cl.getblid() $= getnumkeyid());
                %targ = findclientbyname(%target);
                if(%ishost)
                {
                        if(!isobject(%targ))
                        {
                                %cl.chatmessage("That player doesn't exist.");
                                return false;
                        }
                        else
                        {
                                
                        }
                        if(%targ.issuperadmin && !%targ.iscohost && isobject(%targ))
                        {
                                %targ.iscohost = true;
                                messageall('MsgAdminForce',"<color:00ffff>"@%targ.name@" has become Cohost (Manual)");
                        }
                        else
                        {
                                %cl.chatmessage("Possible Errors");
                                %cl.chatmessage("1. This player may not have Super Admin");
                                %cl.chatmessage("2. This player is probably already a Cohost");                        
                        }
                }
                else
                {
                        %cl.chatmessage("Only the host may use this command.");
                }
        }
        function servercmdautocohost( %cl, %target )
        {
                %ishost = (%cl.islocalconnection() || ($server::lan && $server::dedicated) || %cl.getblid() $= getnumkeyid());
                %targ = findclientbyname(%target);
                if(%ishost)
                {
                        if(!isobject(%targ))
                        {
                                %cl.chatmessage("That player doesn't exist.");
return false;
                        }
                        else
                        {
                                
                        }
                        if(%targ.issuperadmin && !%targ.iscohost && isobject(%targ))
                        {
                                %file = new fileobject();
%file.openforappend("config/server/cohost/"@%targ.bl_id@".txt");
%file.close();
%file.delete();
                                %targ.iscohost = true;
                                messageall('MsgAdminForce',"<color:00ffff>"@%targ.name@" has become Cohost (Auto)");
                        }
                        else
                        {
                                %cl.chatmessage("Possible Errors");
                                %cl.chatmessage("1. This player may not have Super Admin");
                                %cl.chatmessage("2. This player is probably already a Cohost");                        
                        }
                }
        }
        function autocohostconnect( %cl )
        {
%filepath = "config/server/cohost/"@%cl.getblid@".txt";
if(isfile(%filepath))
{
%cl.iscohost = true;
messageall('MsgAdminForce',"<color:00ffff>"@%cl.name@" has become Cohost (Auto)");
echo("Cohost connected.");
}
        }
};
activatepackage(playercohost);
I'm pretty sure I did everything that Placid wanted me to do. Still not working.
EDIT: Wait, I think I know what I did wrong. I'll edit again if not. -_0
EDIT 2: Nope.
« Last Edit: July 07, 2013, 10:55:21 PM by Radíowave »

in autocohostconnect, the file looks like it's supposed to have a .txt extension.


in autocohostconnect, the file looks like it's supposed to have a .txt extension.


That doesn't seem to be the only problem.
Oh wait. *facepalm* I made a typo at gameconnectionconnection::autoadmincheck( %cl )

Excuse me for the double post, but the latest code is what the server.cs file now is.
But the thing is, it still doesn't work.

Quote from: Radíowave
Code: [Select]
function autocohostconnect( %cl )
        {
%filepath = "config/server/cohost/"@%cl.getblid@".txt";
getblid is not a variable of GameConnection it's a function. Add () after "getblid"