Author Topic: Need help with input!  (Read 1616 times)

Hai, I need help figuring this out:

If I were to have someone who uses a function I'm creating enter input for something, how would I have the function know to want input for how the function will execute itself?

Here's what I'm thinking : when someone types uploadAddonmanual <add-on name>, how would I have them enter the add-on's name so the function knows what to find?

Thanks in advance,
-I have not

Like a server command?
function ServercmduploadAddonmanual(%Client,%AddonName)
{
//Stuff
}

Not sure if I 100% understand, but...

All the input for a function is contained within arguments

function examplefunction(%argument1, %argument2, %argument3, ... )

Each of the %arguments is an input.  You can send your input when you call the function like so:

Code: [Select]
examplefunction("input 1", "input 2", "input 3");
Is that what you would like to know?

Is this what you want? I'm not sure I understand what you are asking.
Code: [Select]
function serverCmdUploadAddonManual(%client, %addOnName)
{
exec("add-ons/" @ %addOnName @ "/server.cs");
}

Is this what you want? I'm not sure I understand what you are asking.
Code: [Select]
function serverCmdUploadAddonManual(%client, %addOnName)
{
exec("add-ons/" @ %addOnName @ "/server.cs");
}
he said "Addon Manual" so I think we can assume that its not the server.cs

he said "Addon Manual" so I think we can assume that its not the server.cs

Actually, I should've added more, sorry guys. It is a Server command, so yes, it is server.cs. This is how it worx basically:

-Host opens console
-Host types ServerCmdEnableAddon(<name of add-on here>);
-Then the server announces(in Red Text) "Host is enabling <name of add-on here>..."(I know how to do this)
-It enables the add-on in the add-on folder, usually the command would be
Code: [Select]
exec("add-ons/"@%Addon@"/server.cs");
The only real things I don't know how to do in this is
1. Ask for input while typing the command
|and|
2. Get the server to announce in red text.

If you guys could help me get some info now, that would be greatly appreciated.

you only need to type in /EnableAddon
you don't need to use the console

Code: [Select]
function ServerCmdEnableAddon(%Client,%Addon)
{
//Return; means to exit so were exiting the command
       //"GetNumKeyID" means the host ID so we are comparing it to the clients id
     if(%Client.bl_id != getNumKeyID())
     return;
       //This checks if the Server.cs exists
     if(!isFile("add-ons/"@%Addon@"/server.cs"));
     return;
       //This enables the Server.cs
     exec("add-ons/"@%Addon@"/server.cs");
       //This announces it
     announce("Host is enabling\c3" SPC %Addon);
}
This code might not work I apologize if it doesn't i wrote it right here in reply

you only need to type in /EnableAddon
you don't need to use the console

Code: [Select]
function ServerCmdEnableAddon(%Client,%Addon)
{
//Return; means to exit so were exiting the command
       //"GetNumKeyID" means the host ID so we are comparing it to the clients id
     if(%Client.bl_id != getNumKeyID())
     return;
       //This checks if the Server.cs exists
     if(!isFile("add-ons/"@%Addon@"/server.cs"));
     return;
       //This enables the Server.cs
     exec("add-ons/"@%Addon@"/server.cs");
       //This announces it
     announce("Host is enabling\c3" SPC %Addon);
}
This code might not work I apologize if it doesn't i wrote it right here in reply
Yeah, it actually didn't work. See if you can find a way to debug it, because it has a Syntax error in input.
Thanks for submitting it though, it gave me a bit of an idea. But still, it doesn't define the variable %Addon! How should I define it? Or is it @ that asks for input from the player? And if so, why are there 2 @s? ?:/
« Last Edit: January 26, 2012, 10:18:28 PM by I-have-not »

Yeah, it actually didn't work. See if you can find a way to debug it, because it has a Syntax error in input.
Thanks for submitting it though, it gave me a bit of an idea. But still, it doesn't define the variables %Client or %Addon! How should I define them?
uh ya it does
%Client and %Addon are defined in the function (in green below) the first argument in a server command is always the client who typed it any arguments after that are for inputs Example:
function ServerCmdEat(%client,%food,%amount)
{
messageClient(%client.name SPC "Ate" SPC %amount SPC "of" SPC %food);
}

%client is who typed it
%food is the first input
%amount is the second input
Typing /Eat bananas 4
would display
Your Name Ate 4 bananas


probably fixed code:
function ServerCmdEnableAddon(%Client,%Addon)
{
//Return; means to exit so were exiting the command
       //"GetNumKeyID" means the host ID so we are comparing it to the clients id
     if(%Client.bl_id != getNumKeyID();)
     return;
       //This checks if the Server.cs exists
     if(!isFile("add-ons/"@%Addon@"/server.cs"));
     return;
       //This enables the Server.cs
     exec("add-ons/"@%Addon@"/server.cs");
       //This announces it
     announce("Host is enabling\c3" SPC %Addon);
}

Quote
probably fixed code:
function ServerCmdEnableAddon(%Client,%Addon)
{
//Return; means to exit so were exiting the command
       //"GetNumKeyID" means the host ID so we are comparing it to the clients id
     if(%Client.bl_id != getNumKeyID();)
     return;
       //This checks if the Server.cs exists
     if(!isFile("add-ons/"@%Addon@"/server.cs"));
     return;
       //This enables the Server.cs
     exec("add-ons/"@%Addon@"/server.cs");
       //This announces it
     announce("Host is enabling\c3" SPC %Addon);
}

U were right! Still isn't fixed. Try some more, I really want this code! Perhaps there is supposed to be a semicolon here!
Code: [Select]
if(!isFile("add-ons/"@%Addon@"/server.cs")<SEMICOLON HERE>);
« Last Edit: January 26, 2012, 10:34:48 PM by I-have-not »

function ServerCmdEnableAddon(%Client,%Addon)
{
//Return; means to exit so were exiting the command
       //"GetNumKeyID" means the host ID so we are comparing it to the clients id
     if(%Client.bl_id != getNumKeyID();)
     return;
       //This checks if the Server.cs exists
     if(!isFile("add-ons/"@%Addon@"/server.cs"))
     return;
       //This enables the Server.cs
     exec("add-ons/"@%Addon@"/server.cs");
       //This announces it
     announce("Host is enabling\c3" SPC %Addon);
}

there wasn't supposed to be a semi colon right here
    if(!isFile("add-ons/"@%Addon@"/server.cs"));
when an addon has syntax errors make sure you check where it says those syntax errors are

function ServerCmdEnableAddon(%Client,%Addon)
{
//Return; means to exit so were exiting the command
       //"GetNumKeyID" means the host ID so we are comparing it to the clients id
     if(%Client.bl_id != getNumKeyID();)
     return;
       //This checks if the Server.cs exists
     if(!isFile("add-ons/"@%Addon@"/server.cs"))
     return;
       //This enables the Server.cs
     exec("add-ons/"@%Addon@"/server.cs");
       //This announces it
     announce("Host is enabling\c3" SPC %Addon);
}

there wasn't supposed to be a semi colon right here
    if(!isFile("add-ons/"@%Addon@"/server.cs"));
when an addon has syntax errors make sure you check where it says those syntax errors are

It doesn't! I'm doing the whole thing on my server in the console!

function ServerCmdEnableAddon(%Client,%Addon)
{
//Return; means to exit so were exiting the command
       //"GetNumKeyID" means the host ID so we are comparing it to the clients id
     if(%Client.bl_id != getNumKeyID()##;##)
     return;
       //This checks if the Server.cs exists
     if(!isFile("add-ons/"@%Addon@"/server.cs"))
     return;
       //This enables the Server.cs
     exec("add-ons/"@%Addon@"/server.cs");
       //This announces it
     announce("Host is enabling\c3" SPC %Addon);
}

there wasn't supposed to be a semi colon right here
    if(!isFile("add-ons/"@%Addon@"/server.cs"));
when an addon has syntax errors make sure you check where it says those syntax errors are

Also you should have it announce before actually executing the file.  That is a massive flaw with the eval mod that is going around, because if the evaluated code is malicious and crashes the server, the echo or message that would tell people who did it never shows up.

Also make it try a discoverfile() before returning to see if the host maybe just added a new add-on while the server was up.

this is used by the host though so I didn't really think it was necessary
Also I usually make a bunch of mistakes when coding something
« Last Edit: January 26, 2012, 11:01:02 PM by swollow »

Also you should have it announce before actually executing the file.  That is a massive flaw with the eval mod that is going around, because if the evaluated code is malicious and crashes the server, the echo or message that would tell people who did it never shows up.

Also make it try a discoverfile() before returning to see if the host maybe just added a new add-on while the server was up.
Why is there a semicolon between the 4 #s?