mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Sep 2005
Posts: 53
C
Babel fish
OP Offline
Babel fish
C
Joined: Sep 2005
Posts: 53
I heard that using variables for your RPG script can get very messy. If you Set certain attacks and defense as a variable you can later use it for battle. But if you write it in text how can you use it later on?

And how can you add to a text. Like if on the first line of the text it says 12, how can you add +1,2... or whatever to that?

Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
You can always call up the information from your text (txt) file, put it into a variable, change it around, and then re-write the information to the text file again.

Basically there are two types of text files, txt & ini, each has it's own advantages & disadvantages depending on what you're wanting to put in the file and how you want it stored.

Likewise, there are two types of variables, global & local.

Global variables, when set, stay set until they are modified, or unset. Local variables, are automatically emptied when the end of the script (that they were set in) is reached.

Also please note that hash tables are an excellent way of storing information. Hash tables are, I believe, the fastest way of storing and accessing a lot of information.

Per your example, the following would work
Code:
var %a = $left($read(file.txt,t,1),1), %b = $right($read(file.txt,t,1),1), %c = $calc(%a + %b)
echo -a $read(file.txt,t,1) summed is %c
  


Please note that this is a very simple example, and if you'd like assistance in writing the code, I'll need more details.

One reason that people have a hard time with variables in an RPG script, is the fact that most people (and I'm guilty of doing this myself) don't use variable names that are easily identifiable for the information that they hold.

I suggest you read
/help $read
/help /write
/help $readini
/help /writeini
/help $ini
/help Hash tables

Joined: Sep 2005
Posts: 53
C
Babel fish
OP Offline
Babel fish
C
Joined: Sep 2005
Posts: 53
Where are Hash Tables stored?(I cant find any file) Can you play them for later use? This is what i have:
Code:
on Kanto:Text:!Starter *:#: {
  var %a = $2
  if (!$isfile($+(Pokemon_RPG\,$nick,.Party,.txt))) {
    if (%a == Squirtle) {
      hadd -smuN $nick Squirtle
      hadd -smuN $nick 5
      hadd -smuN $nick 24
      hadd -smuN $nick 14
      hadd -smuN $nick 16
      hadd -smuN $nick 13
      hadd -smuN $nick 14
   }
}

And another problem.
Code:
on Kanto:Text:!Stat 1:#: {
  play $chan $hget($nick)
}

This doesnt work... I want to show the person their stats but it doesnt work like that, and can you do something like this:
Code:
on Kanto:Text:!Stat 1:#: {
msg $chan $Read($+($Hget($nick,1)))
msg $chan $Read($+($Hget($nick,2)))
msg $chan $Read($+($Hget($nick,3)))
msg $chan $Read($+($Hget($nick,4)))
}

I have no idea how Hash Tables works but is it something like:
Pokemon
|_Squirtle_|
|_5_|
|_24_|
etc..
On the help file it says:
Code:
$hget(name/N, item)
Returns the data associated with an item in the specified hash table.

I still dont know what N means.
I want to make it so if I put $Hget(Pokemon/N?,Attack) - the number shows up.
I cant really put it into words but if you understand what im saying please help.

Last edited by CraZyHanD; 19/11/05 07:00 PM.
Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
You don't use $read() to get data from Hash Tables dude.

Just stick with .txt. smile

Code:
on Kanto:Text:!Starter *:#: {
  if ($isfile($+(Pokemon_RPG\,$nick,.Party,.txt))) {
    var %poke = write $+("Pokemon_RPG\,$nick,.Party,.txt")
    if (!$read($+(Pokemon_RPG\,$nick,.Party,.txt),w,*Pokemon:*)) {
      if ($2 == Squirtle) {
        write -c $gettok(%poke,2-,32)
        %poke Pokemon: $2
        %poke Character: $2
        %poke Level: 5
        %poke Attack: Some_Attack
        %poke Defence: Some_Defence
        %poke Speed: Some_Speed
      }
      elseif ($2 == Bulbasaur) {
        write -c $gettok(%poke,2-,32)
        %poke Pokemon: $2
        %poke Level: 5
        %poke Attack: Some_Attack
        %poke Defence: Some_Defence
        %poke Speed: Some_Speed
      }
      elseif ($2 == Charmander) {
        write -c $gettok(%poke,2-,32)
        %poke Pokemon: $2
        %poke Level: 5
        %poke Attack: Some_Attack
        %poke Defence: Some_Defence
        %poke Speed: Some_Speed
      }
      else { msg $nick $2 is not a starter pokemon! }
    }
    else { msg $nick You already chose $gettok($read($+(Pokemon_RPG\,$nick,.Party,.txt),w,*Pokemon:*),2,32) as your character. }
  }
  else { msg $nick You aren't playing right now. }
}


-Andy

Joined: Sep 2005
Posts: 53
C
Babel fish
OP Offline
Babel fish
C
Joined: Sep 2005
Posts: 53
Lol, that was my original plan. Umm what does this mean?
Code:
 [color:black] write [/color]  [color:red] -c $gettok(%poke,2-,32)
 [/color] 

And How can you make a script like this work?
Code:
on Kanto:Text:!Stat 1:#: {
  msg $chan Pokemon: $+($Read(Pokemon_RPG\,$nick,.Party,.txt,1))
}

Joined: Dec 2002
Posts: 3,547
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Oh you can delete those instances of that. It was for your original RPG that if they chose a character and decided to choose a different one it'd clear the file and write to it again. But since we've checked if they have chose a pokemon or not we don't need it.

By Stat 1 do you mean level or attack etc?

Code:
On *:Text:!Stat *:#: {
  var %file = $+(Pokemon_RPG\,$nick,.Party,.txt)
  if ($isfile(%file)) {
    msg $chan $read(%file,w,$+(*,$2,*))
  }
}


!Stat Pokemon
!Stat Level
!Stat Attack
!Stat Speed

Etc..

-Andy

Joined: Sep 2005
Posts: 53
C
Babel fish
OP Offline
Babel fish
C
Joined: Sep 2005
Posts: 53
Before you read what I wrote below, Can you Add numbers in certain lines in a text File. For example if a txt file had 14 on its second line can you put
Code:
write -c $Calc($read(file,2)+1)

Can this replace the 14 and 15 in its place?
If so.....
Im not going to Write " Attack : 14 ", instead im going to put just the numbers, so that when they level up i can add to their stats.
That is why I need to know how to use a $read in the middle of a msg.
Code:
on Kanto:Text:!Stat 1:#: {
  msg $chan Pokemon: $+($Read(Pokemon_RPG\,$nick,.Party,.txt,1))
}

And !Stat 1 is supposed to show the Stats of the pokemon on Slot 1 of your Group.

Last edited by CraZyHanD; 19/11/05 08:25 PM.
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
I dont mean this nastly, but i suggest you start with some simple type of game, and progress onto a RPG at a later time.
I believe your out of your depth on some of the things your hoping to achieve, based on the level of understanding you have of mirc scripting.

Im sure you can get better, but a large project straight off the mark is likely to bog down and not progress.
I look at some of the first things i ever did in mirc (and im a programmer by trade) and i think now WOW what crazy thing was i doing there!


Link Copied to Clipboard