Author Topic: Stuck on scripting  (Read 3398 times)

I try so hard but I cannot figure anything out. I can't do anything except copy and paste crap from other things to make a syntax filled stuff.cs

All tutorials I could find taught me how to make scripts, but not how to USE things.

What the forget do Args do.

What is this?
Code: [Select]
if(!%client.isAdmin || !%client.isSuperAdmin)Does this mean

If they are admin or super admin?

What about this?
Code: [Select]
messageClient(%Client,'',"\c6Self Delete is \c0OFF\c6.");Why is there multiple "

What does "," do?

What does %client do

All tutorials given to me didn't explain what they did, they just said.

Copypaste this. You now know how to script.

Can someone help me out, tell me something I should attempt making at a start? I really wish I could advance farther but I couldn't figure much more out,

%client.isAdmin
    Returns 1(or true) if the client is a admin OR super

Fixed code:
if(!%client.isAdmin)



The %client
In a script you'll see a %client
%client returns a GameConnection
a GameConnection is a connection to the game, and you have lost THE GAME.

messageClient(%Client, '', "\c6Self Delete is \c0OFF\c6.");
Commas seperate parameters, or arguments.



This is what separates modelers and scripters.
« Last Edit: October 19, 2009, 09:08:37 PM by Kalphiter »

%client.isAdmin
    Returns 1(or true) if the client is a admin OR super

Fixed code:
if(!%client.isAdmin)

It doesnt "return true if their an admin"; it "returns" (See: below) its value, no matter what it is.

The %client
In a script you'll see a %client
%client returns a GameConnection
a GameConnection is a connection to the game

Same as above, %client doesn't "return a GameConnection". %client is a local variable, named client and deemed local with the % sign. Variables are used to represent a value; most of the time, people assign a GameConnection object ID to a variable named client, but sometimes also cl, c, etc. I could name the variable grapefruit and it wouldn't change it.

What is this?
Code: [Select]
if(!%client.isAdmin || !%client.isSuperAdmin)Does this mean

If they are admin or super admin?
It means "If they aren't an admin or super admin." An exclamation mark inverts it.

Code: [Select]
messageClient(%Client,'',"\c6Self Delete is \c0OFF\c6.");Why is there multiple "
Spaced out:
Code: [Select]
messageClient(     %Client     ,     ''     ,     "\c6Self Delete is \c0OFF\c6."     );The second arguement is two ' marks, which is basically a placeholder that keeps it from giving a syntax error. The second set of quote marks is a string.

What does "," do?
Separates arguements.

What does %client do
%client is a variable, typically used in server commands to signify the person who sent the command to the server.

[/quote]

and you have lost THE GAME.

This is what separates modelers and scripters.

Crap.

I LOST THE GAME

heed, this was my exact problem. This is where you need to learn the concepts, I actually started doing stuff in c++, then I looked at torquescript one day and went, oh...


Now I just look at it to figure it out. Learn about the syntax of programming languages (like C) similar to torquescript, reading random wikis or if you really want to, a book.

*Hint, when the RTB wiki opens you may find info. *

To know what arguments are, you have to know this:

Functions/Returns to know that -
Program Flow-
Variables

So start with variables. It really helped me to start from the basics of basics.
« Last Edit: October 20, 2009, 01:37:06 AM by Zenthos »

I recommend you take a computer science class and some algebra would help too.


Code: [Select]
messageClient(%Client,'',"\c6Self Delete is \c0OFF\c6.");Why is there multiple "

What does "," do?
That's not a ","
It's two 's, then a comma.
the two 's is just an empty tag. In messageclient, that tag is usually used for specific things for the client to recognize.
Things like... 'handleYourDeath', 'msgClientJoin', and 'msgAdminForce'.
The args for Messageclient...
messageclient(GameConnection object (as in a reference to a client), messageType (leave blank for normal message), MessageString, messageargs...);
About messageargs, if you make messageString a tagged string, instead of a normal string ('stuff' instead of "stuff") you can use things like %1 in it. And if you're going to be sending that message often, it's best to make it tagged. If it's something short or not sent often, go ahead and make it normal.
How to use tagged strings in chat messages:
messageClient(%client (This is sometimes different), '' (remember this tag is left blank for a normal message), 'Hello %1. You currently have $%2. Your dog has the name %3.', %client.getPlayerName() (this just get's the client's netname if it's an internet server, lanname if it's a lan or single player server), %client.money, %client.dogsname);
Without all that extra info:
messageClient(%client, '', 'Hello %1. You currently have $%2. Your dog has the name %3.', %client.getPlayerName(), %client.money, %client.dogsname);

For a messageAll, you take out the first arg (the client), and leave the rest. However you cannot reference to something the client has.
messageAll('', 'Hello everyone. The ammount of pineapples on this server is: %1', $Server::Pineapplecount);

So what should I attempt making for my first script?



I decided to make a script where the host needs to say /addtrust in order to build. I tried getting somewhere but got lost with %name. I don't know how to add %name as the target.
Code: [Select]
function serverCmdAddTrust(%client, %name)
{
  if(%client.isAdmin || %client.isSuperAdmin)
{
   //WhatdoIputHere
}
  else
{
messageClient(%client, '', "\c6You must be an admin to use this command.");
}
}




package ServerVIPBuild
{
function serverCmdPlantBrick(%client)
{
if(!$Server::Dedicated && $ServerVIPBuild::Enabled)
{
%host = findLocalClient();
if(!%Hastrust ==1)
{
centerPrint(%client,%host.name@" does not trust you enough to build on their server",2,2);
return;
}
}
Parent::serverCmdPlantBrick(%client);
}
};
activatePackage(ServerVIPBuild);

I used script_Serverbuildtrust as a base for this.

Alright, I'm just going to point out all the mistakes, and help you with what to put there.

%hasTrust is a local variable, and is not declared anywhere in the function. Therefore it will not do anything.
If you did something like !$Pref::Server::HasTrust[%client.bl_id], that would work better.
Now in AddTrust, you have if(%client.isAdmin || %client.isSuperAdmin)
It WILL work, but the || %client.isSuperAdmin is not necissary. A super admin also has .isAdmin true.
And to get the trust to work, do something like this:
Replace: //WhatdoIputHere
with this:
%target = findClientByName(%name);
if(isObject(%target))
{
messageClient(%client, '', "\c6You can now build on this server.");
$Pref::Server::HasTrust[%client.bl_ID] = 1;
}
So that part should look like this:
Code: [Select]
if(%client.isAdmin)
{
%target = findClientByName(%name);
if(isObject(%target))
{
messageClient(%target, '', "\c6You can now build on this server.");
$Pref::Server::HasTrust[%target.bl_ID] = 1;
}
}
Fixed
Oh, and you can completely remove !$Server::Dedicated &&
and %host = findLocalClient(); as they are no longer neccissary.

You should also try to make a remove trust function.
« Last Edit: October 20, 2009, 08:58:15 PM by Chrono »

Code: [Select]
if(%client.isAdmin || %client.isSuperAdmin)
{
%target = findClientByName(%name);
if(isObject(%target))
{
messageClient(%client, '', "\c6You can now build on this server.");
$Pref::Server::HasTrust[%client.bl_ID] = 1;
}
}
Silly Chrono, you forgot to message %name and make $Pref::Sever::HasTrust[%name.bl_ID] = 1;
So basically it gives yourself building trust
Code: [Select]
if(%client.isAdmin || %client.isSuperAdmin)
{
%target = findClientByName(%name);
if(isObject(%target))
{
messageClient(%name, '', "\c6You can now build on this server.");
$Pref::Server::HasTrust[%name.bl_ID] = 1;
}
}
I believe that fixes that.