Author Topic: Help a starter scripter  (Read 1012 times)

Code: [Select]
function servercmdtavernpot(%client,%empty)
{
if(%empty$=””)
{
 %rand=getrandom(1,10);
 if(%rand==1)
 {
  %client.prefix=”handicapped”;
 }
 if(%rand==2)
 {
  %client.prefix=”Cozy”;
 }
 if(%rand==3)
 {
  %client.prefix=”Sleeping”;
 }
 if(%rand==4)
 {
  %client.prefix=”Traveling”;
 }
 if(%rand==5)
 {
  %client.prefix=”Wandering”;
 }
 if(%rand==6)
 {
  %client.prefix=”Lovely”;
 }
 if(%rand==7)
 {
  %client.prefix=”Curious”;
 }
 if(%rand==8)
 {
  %client.prefix=”Sleepy”;
 }
 if(%rand==9)
 {
  %client.prefix=”Harmless”;
 }
 if(%rand==10)
 {
  %client.prefix=”Dangerous”;
 }
 %rand2=getrandom(1,10);
 if(%rand2==1)
 {
  %client.suffix=”Pillow”;
 }
 if(%rand2==2)
 {
  %client.suffix=”Bed”;
 }
 if(%rand2==3)
 {
  %client.suffix=”Blanket”;
 }
 if(%rand2==4)
 {
  %client.suffix=”Donkey”;
 }
 if(%rand2==5)
 {
  %client.suffix=”Shoe”;
 }
 if(%rand2==6)
 {
  %client.suffix=”Owl”;
 }
 if(%rand2==7)
 {
  %client.suffix=”Monstrosoty”;
 }
 if(%rand2==8)
 {
  %client.suffix=”Traveler”;
 }
 if(%rand2==9)
 {
  %client.suffix=”Willow”;
 }
 if(%rand2==10)
 {
  %client.suffix=”Dream”;
 }
 
 messageall("admin","<color:FFFFFF>"@%client.prefix@" <color:FFFF00>"@%client.suffix@" <color:FF00FF>might be a good name!");
}
else
{
 messageclient(%client,’’,”Invalid”);
}
}
Above is server.cs and below is description.txt
Code: [Select]
Title: Tavern name generator
Author: Kyttike
Does what it name says.
Help is appreciated

Its packed in a Script_Tavernpot.zip
Console says syntax error on 1st line.

PS. My first script evar

%client.clanSuffix

if(%empty $= "")

I may sound noobish but wut.

What are you even doing with %empty? I see no purpose for it.

Also, instead of using an assload of ifs, consider using a switch statement

Code: [Select]
switch(%rand)
{
    case 1:
        //do stuff if %rand == 1
    case 2:
        //do stuff if %rand == 2
    case 3:
        //do stuff if %rand == 3
    default:
        //do stuff if one of the above cases is not true
}

It's a lot less typing and looks neater.
Also try indenting more, it makes it easier to read.

Ill try to make something with that, thanks :) but i'd still like to get the script working.
Any ideas why it doesnt work?


Post the error?
Incase you don't understand just start blockland server then close go to your blockland folder contains addons folder and open console.txt and find your script and then post the error report.

Lol, or you can use an array

%this[0]="randomname";
%this[1]="randomname2";
%this[2]="randomname3";
%maxArray=2;

etc

then

%client.suffix/prefix=%this[getRandom(0,%maxArray)];

Quote from: code
function servercmdTavernPot(%client) {
   switch(getrandom(1,10)) {
      case 1:
         %client.prefix=”handicapped”;
      case 2:
         %client.prefix=”Cozy”;
      case 3:
         %client.prefix=”Sleeping”;
      case 4:
         %client.prefix=”Traveling”;
      case 5:
         %client.prefix=”Wandering”;
      case 6:
         %client.prefix=”Lovely”;
      case 7:
         %client.prefix=”Curious”;
      case 8:
         %client.prefix=”Sleepy”;
      case 9:
         %client.prefix=”Harmless”;
      case 10:
         %client.prefix=”Dangerous”;
   }
   switch(getrandom(1,10)) {
      case 1:
         %client.suffix=”Pillow”;
      case 2:
         %client.suffix=”Bed”;
      case 3:
         %client.suffix=”Blanket”;
      case 4:
         %client.suffix=”Donkey”;
      case 5:
         %client.suffix=”Shoe”;
      case 6:
         %client.suffix=”Owl”;
      case 7:
         %client.suffix=”Monstrosoty”;
      case 8:
         %client.suffix=”Traveler”;
      case 9:
         %client.suffix=”Willow”;
      case 10:
         %client.suffix=”Dream”;
   }
   messageAll(%client,"<color:FFFFFF>" @ %client.prefix @ " <color:FFFF00>" @ %client.name @ "<color:FFFFFF>" @ %client.suffix @ " <color:FF00FF>might be a good name!");
}

What I came up with before reading the last message. I could make one his way, but don't feel like putting both in one message. (Don't know which he'd prefer.)

Edit: His method:
Quote from: code
$RandCT::PreN = 0;
$RandCT::Pre[$RandCT::PreN++] = "handicapped";
$RandCT::Pre[$RandCT::PreN++] = "Cozy";
$RandCT::Pre[$RandCT::PreN++] = "Sleeping";
$RandCT::Pre[$RandCT::PreN++] = "Traveling";
$RandCT::Pre[$RandCT::PreN++] = "Wandering";
$RandCT::Pre[$RandCT::PreN++] = "Lovely";
$RandCT::Pre[$RandCT::PreN++] = "Curious";
$RandCT::Pre[$RandCT::PreN++] = "Sleepy";
$RandCT::Pre[$RandCT::PreN++] = "Harmless";
$RandCT::Pre[$RandCT::PreN++] = "Dangerous";
$RandCT::SufN = 0;
$RandCT::Suf[$RandCT::SufN++] = "Pillow";
$RandCT::Suf[$RandCT::SufN++] = "Bed";
$RandCT::Suf[$RandCT::SufN++] = "Blanket";
$RandCT::Suf[$RandCT::SufN++] = "Donkey";
$RandCT::Suf[$RandCT::SufN++] = "Shoe";
$RandCT::Suf[$RandCT::SufN++] = "Owl";
$RandCT::Suf[$RandCT::SufN++] = "Monstrosoty";
$RandCT::Suf[$RandCT::SufN++] = "Traveler";
$RandCT::Suf[$RandCT::SufN++] = "Willow";
$RandCT::Suf[$RandCT::SufN++] = "Dream";

function servercmdTavernPot(%client) {
   messageAll(%client, "<color:FFFFFF>" @ (%client.prefix = $RandCT::Pre[getRandom($RandCT::PreN)]) @ " <color:FFFF00>" @ %client.name @ "<color:FFFFFF>" @ (%client.suffix = $RandCT::Suf[getRandom($RandCT::SufN)]) @ " <color:FF00FF>might be a good name!");
}

That should work. RandCT = Random Clantag. Pre = Prefix. Suf = Suffix. N = Num.
« Last Edit: August 20, 2010, 11:10:07 PM by MegaScientifical »

Just remember tha % is for client user and $ is saying to the server for it

Just remember tha % is for client user and $ is saying to the server for it
What?