Jump to content

Script Optimising :S


damnet007

Recommended Posts

I'm trying to optimize this script/find another, more efficient way of doing this:

- A person's item data is stored in an ini file, eg rpg.ini :

[name]

item1=amount

item2=amount

...

- All the items are classified into different categories, in another ini, eg. things.ini:

[food]

item=1

item2=1

item3=1

...

[drinks]

item1=1

item2=1

...

The script checks all of the user's items and if an item from rpg.ini is in the food section of things.ini, it adds them to the list of food items they have. I made this a little while ago and it seems to work perfectly on my PC, but not on the PC where I run scripts. Any ideas how this could be done? My script's below:

alias showfood {
 var %b = 0,%d = 0,%c,%e,%f,%g,%h
 while (%b <= $ini(rpg.ini,$mta.name($1,$2),0)) {
   if ($readini(rpg.ini,$mta.name($1,$2),$ini(rpg.ini,$mta.name($1,$2),%b)) > 0) && ($readini(things.ini,food,$ini(rpg.ini,$mta.name($1,$2),%b)) == 1) {
     if (!%c) %c = $ini(rpg.ini,$mta.name($1,$2),%b) $+ ( $+ $readini(rpg.ini,$mta.name($1,$2),$ini(rpg.ini,$mta.name($1,$2),%b)) $+ )
     elseif (%c) {
       %c = %c $+ $chr(46) $ini(rpg.ini,$mta.name($1,$2),%b) $+ ( $+ $readini(rpg.ini,$mta.name($1,$2),$ini(rpg.ini,$mta.name($1,$2),%b)) $+ )
       %d = %d + 1
       if %d > 5 {
         %h = $gettok(%c,24-29,46)
         %g = $gettok(%c,18-23,46)
         %f = $gettok(%c,12-17,46)
         %e = $gettok(%c,6-11,46)
         %c = $gettok(%c,1-5,46)
       }

     }
   }
   !inc %b
 }
 mta.msg $1 $2 $mta.name($1,$2) $+ : $iif(%c,%c,No Food)
 if (%e) mta.msg $1 $2 Food: %e
 if (%f) mta.msg $1 $2 Food: %f
 if (%g) mta.msg $1 $2 Food: %g
 if (%h) mta.msg $1 $2 Food: %h
}

The reason I have %e - %h is because there are loads of different food items a person can have, and mta has that text limit :P

thanx

Link to comment

if u just have %d = %d + 1

u said var %d = 0, so after adding + 1, %d then becomes '0 + 1', then u add another + 1, so %d becomes '0 + 1 + 1' and so on,

u need to use: %d = $calc(%d + 1)

or !inc %d

i dont quite understand really what ur trying to do here,

im guessing u can only hold different 5 items, but an unlimited amount of each?

i have a similar thing in one of my rpg scripts, but i added all items in 1 list, i have around 400 items.

if u tell me what u want, maybe i can suggest an easier way to do what ur trying to do.

Link to comment

i've made an 1337 function for stuff like that, mta.longsay :) it will protect you from broken messages in mta

on *:SIGNAL:mta.command:{
 if ($3 == !food) showfood $1-
}
alias showfood {
 var %a = 0,%b,%c
 if (!$ini(rpg.ini,$mta.name($1,$2),1)) mta.say $1 $mta.name($1,$2) has no food.
 else {
   while (%a <= $ini(rpg.ini,$mta.name($1,$2),0)) {
     %b = $ini(rpg.ini,$mta.name($1,$2),%a)
     if ($readini(rpg.ini,$mta.name($1,$2),%b) > 0) {
       if ($readini(things.ini,food,%b) == 1) {
         %c = $iif(%c,%c $+ $chr(44),$+(%b,$chr(40),$readini(rpg.ini,$mta.name($1,$2),%b),$chr(41)),$+(%b,$chr(40),$readini(rpg.ini,$mta.name($1,$2),%b),$chr(41)))
       }
     }
     !inc %a
   }
   mta.longsay $1 $mta.name($1,$2) $+ 's food: $iif(%c,$v1,None)
 }
} 
alias mta.longsay {
 var %a = 1,%b
 while (%a <= $numtok($3-,32)) {
   if ($calc($len(%b) + $len($gettok($3-,%a,32))) <= 115) %b = $iif(%b,%b $gettok($3-,%a,32),$gettok($3-,%a,32))
   else {
     mta.say $1 %b
     %b = $null
   }
   !inc %a
 }
 mta.say $1 %b
}

Link to comment

thanks for the script toady, but I had an error in the line assigning %c and the last mta.say line. I've done this and it seems to work although it won't show any food items which don't fit into the first mta.say line (if this makes sense):

alias showfood {
 var %a = 0,%b,%c
 if (!$ini(rpg.ini,$mta.name($1,$2),1)) mta.say $1 $mta.name($1,$2) has no food.
 else {
   while (%a <= $ini(rpg.ini,$mta.name($1,$2),0)) {
     %b = $ini(rpg.ini,$mta.name($1,$2),%a)
     if ($readini(rpg.ini,$mta.name($1,$2),%b) > 0) {
       if ($readini(things.ini,food,%b) == 1) {
         %c = $iif(%c,%c $+ $chr(44) $+(%b,$chr(40),$readini(rpg.ini,$mta.name($1,$2),%b),$chr(41)),$+(%b,$chr(40),$readini(rpg.ini,$mta.name($1,$2),%b),$chr(41)))
       }
     }
     !inc %a
   }
   mta.longsay $1 $mta.name($1,$2) $+ 's food: $iif(%c,$v1,None)
 }
}
alias mta.longsay {
 var %a = 1,%b
 while (%a <= $numtok($3-,32)) {
   if ($calc($len(%b) + $len($gettok($3-,%a,32))) <= 115) %b = $iif(%b,%b $gettok($3-,%a,32),$gettok($3-,%a,32))
   else {
     mta.say $1 %b
     %b = $null
   }
   !inc %a
 }
 if (%b) mta.say $1 %b
}

Link to comment
i dont quite understand really what ur trying to do here,

im guessing u can only hold different 5 items, but an unlimited amount of each?

i have a similar thing in one of my rpg scripts, but i added all items in 1 list, i have around 400 items.

if u tell me what u want, maybe i can suggest an easier way to do what ur trying to do.

Sorry, didn't see your post until now. Basically, you can hold an unlimited amount of items. These items are made by other users who own factories, etc. When a factory owner produces an item, they specify which category the item goes into. These item categories are stored in things.ini and everything has already been scripted.

The reason I posted here was because I needed a script to find all items owned by a person, which are in the 'food' category- all my scripting attempts worked fine on my pc but kept causing mtama to time out on the scripts host pc when someone typed !food - i think the script took up a lot of cpu usage when run, and that's why I posted here, to try and find a better way to do it.

Link to comment
i dont quite understand really what ur trying to do here,

im guessing u can only hold different 5 items, but an unlimited amount of each?

i have a similar thing in one of my rpg scripts, but i added all items in 1 list, i have around 400 items.

if u tell me what u want, maybe i can suggest an easier way to do what ur trying to do.

Sorry, didn't see your post until now. Basically, you can hold an unlimited amount of items. These items are made by other users who own factories, etc. When a factory owner produces an item, they specify which category the item goes into. These item categories are stored in things.ini and everything has already been scripted.

The reason I posted here was because I needed a script to find all items owned by a person, which are in the 'food' category- all my scripting attempts worked fine on my pc but kept causing mtama to time out on the scripts host pc when someone typed !food - i think the script took up a lot of cpu usage when run, and that's why I posted here, to try and find a better way to do it.

how much food do u have in ur ini?

i have a list of about 400 items in mine and it works fine.

hmm im not sure why u should have a problem either way.

so u add all players items indivudually? eg:

[Dave]

food=1

drink=3

money=437586

etc...

or are the items randomly added too?

theres a few ways u can do it, none of them are too hard.

might be better to chat on msn, im sure one way or another i can help u out.

add my email if u do get stuck.

[email protected]

im on quite a lot.

Link to comment
  • 2 weeks later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...