Author Topic: Noob-Lottery  (Read 1565 times)

0 Members and 1 Guest are viewing this topic.

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Noob-Lottery
« on: March 19, 2008, 05:53:30 pm »
Hello,

I'm working on my first script. I have some programming-skills, but not in pascal.
What i'm trying to build is a script that starts a random function, everytime someone says 'noob' or a similar irritating word. The random-function will decide whether the person is muted for a certain amount of time, or even banned. I have two problems.

First is the random-function. I know it's not completely random, but that doesn't matter in this case. I use the following code:
Code: [Select]
Rnumber := Random(100);
if (Rnumber < 50) then WriteConsole (0,IDToName(ID) + ' won nothing, too bad! Better luck next time!',$EE81FAA1);
if (Rnumber >= 50) and (Rnumber < 80) then WonTempMute(ID, THIRD_MUTE);
if (Rnumber >= 80) and (Rnumber < 95) then WonTempMute(ID, SECOND_MUTE);
if (Rnumber >= 95) and (Rnumber < 99) then WonTempMute(ID, FIRST_MUTE);
if (Rnumber = 99) then WonTempBan(ID);
If i run this, i get an 'Invalid number of parameters' error on the first if-condition. If i replace the random with an integer, the error is gone. What am i doing wrong? Acording to the Delphi basics site this should work.

A second problem is the extraction of the words out of the text that players write. On the Delphi basics site i found the function AnsiContainStr and AnsiCountainText. When i try to compile the script, soldatserver gives me an 'unknown identifier' error on this function. I'd say that means that the compiler doesn't recognize the function. Or could it be that the compiler wont convert String to AnsiString out of itself. Meaning i just input AnsiContainText(String, String), where it actually should be AnsiContainText(AnsiString, String), acording to the examples.

While i'm at it, i have a third thing that i could not find. For the words i'm making a const array of arrays of strings. Each array contains a word, plus its exeptions (example: (nab, nable, cannab, nabout)). I want to keep this rather simple so the arrays are static. This means that some of the slots in the arrays will be empty. How can i make a condition that finds out if these slots are empty (example: if (BannedWords[i,j] = nill) then...). Will 'nill' work? Is there another way?

Thanks for your time,
JFK
Come join: EliteCTF
Listen to: My Music

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: Noob-Lottery
« Reply #1 on: March 19, 2008, 06:50:01 pm »
1) Random(min, max);
2) Try this?
3) Just check if its empty?

Offline rhide

  • Major
  • *
  • Posts: 60
  • Coffee-addict
    • Vrastar-Hai soldat clan
Re: Noob-Lottery
« Reply #2 on: March 19, 2008, 07:38:53 pm »
Code: [Select]
Rnumber := Random(100);
if (Rnumber < 50) then WriteConsole (0,IDToName(ID) + ' won nothing, too bad! Better luck next time!',$EE81FAA1);
if (Rnumber >= 50) and (Rnumber < 80) then WonTempMute(ID, THIRD_MUTE);
if (Rnumber >= 80) and (Rnumber < 95) then WonTempMute(ID, SECOND_MUTE);
if (Rnumber >= 95) and (Rnumber < 99) then WonTempMute(ID, FIRST_MUTE);
if (Rnumber = 99) then WonTempBan(ID);

I just wanted to say that that code might just not work as you expect... If the randomnumber is 99 both the last and the second last line will execute. You cannot just change your if-clauses it to 'else if' either, because then execution will stop if Rnumber >=95 (wich is the case when Rnumber=99). Also make sure you call randomize before calling the random function
Warning! Division by zero seriously injures yourself and the people in your surroundings.

Proud member of Vrastar-Hai:
http://www.guldheden.com/~erga050/vrastar-hai

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Noob-Lottery
« Reply #3 on: March 20, 2008, 05:14:15 am »
1) Random(min, max);
2) Try this?
3) Just check if its empty?

1.Thanks! :D
2.Thanks! although it is case-sensitive.. which it too bad, but it'll have to do. At least the script compiles now.
3.I get that, but what is the syntax for empty? is it 'nill', 'emtpy' or just ''?

Edit: I totally read over the RegExpMatch function on enesce's help server. hehe, this would solve the ContainsString problem :p If i get it to work...

Code: [Select]
Rnumber := Random(100);
if (Rnumber < 50) then WriteConsole (0,IDToName(ID) + ' won nothing, too bad! Better luck next time!',$EE81FAA1);
if (Rnumber >= 50) and (Rnumber < 80) then WonTempMute(ID, THIRD_MUTE);
if (Rnumber >= 80) and (Rnumber < 95) then WonTempMute(ID, SECOND_MUTE);
if (Rnumber >= 95) and (Rnumber < 99) then WonTempMute(ID, FIRST_MUTE);
if (Rnumber = 99) then WonTempBan(ID);

I just wanted to say that that code might just not work as you expect... If the randomnumber is 99 both the last and the second last line will execute. You cannot just change your if-clauses it to 'else if' either, because then execution will stop if Rnumber >=95 (wich is the case when Rnumber=99). Also make sure you call randomize before calling the random function

This code is kinda faulty, i admit. I already replaced it for
Code: [Select]
if ((Rnumber=>95) and (Rnumber <99)) then WontTempMute(ID, FIRST_MUTE);

the extra brackets make sure the condition is as one, so the number has to be higher/equal then 95 AND lower than 99 for the condition to become true.
« Last Edit: March 20, 2008, 06:35:25 am by JFK »
Come join: EliteCTF
Listen to: My Music

Offline Boblekonvolutt

  • Soldier
  • **
  • Posts: 222
  • "YOU are a CAR."
Re: Noob-Lottery
« Reply #4 on: March 20, 2008, 01:40:49 pm »
lowercase('o.O') returns 'o.o'

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Noob-Lottery
« Reply #5 on: March 21, 2008, 11:33:59 am »
lowercase('o.O') returns 'o.o'

Thanks again, even though i use the regexp now, this makes things again a bit easier.

I have a new small problem. For some reason i can seem to make a const array, like this:
Code: [Select]
const
WORDS : Array[1..5]  of string = ('hello', 'why', 'wont', 'this', 'work');
The Free Pascal compiler doesn't complain about it, but soldat refuses to compile it (Error is ('=') expected). For now i use a variable array and i fill it during the ActivateServer event. That works, but i don't consider it to be 'best practice' programming. Any way to make a constant array?
Come join: EliteCTF
Listen to: My Music

Offline danmer

  • Camper
  • ***
  • Posts: 466
  • crabhead
Re: Noob-Lottery
« Reply #6 on: March 21, 2008, 05:15:19 pm »
Any way to make a constant array?
none that i (or anyone i asked) know of

Offline chutem

  • Veteran
  • *****
  • Posts: 1119
Re: Noob-Lottery
« Reply #7 on: March 24, 2008, 04:09:05 am »
You probably can make an array of const, but as you have shown, defining them in the const bit doesn't work, and you can't change them in the executing bit of the script, so it wuld be useless, just make a list.
1NK3FbdNtH6jNH4dc1fzuvd4ruVdMQABvs