Jump to content
Sign in to follow this  
LineageIIC3Freak

Random

Recommended Posts

LineageIIC3Freak

Hi, i've recently stumbled across using .ini files and I thought about using it for a chat bot for this mmorpg game Shimlar. There is only one problem... I do not know how to use Random() to randomly read keys in a section. I know i can have it read all the keys but i wouldnt need that. I need to know how to use Random() or anything else that will read a random key inside a section. If somone could help I would really appreciate the assistance. Thank You.


[quote]I don't like to think, Therefore I ChEaT[/quote]

Share this post


Link to post
Share on other sites
Knight

$Ini = "file.ini"
$Section = "Section1"

;Put messages into array $Messages
Dim $Messages[5]
$Messages[0] = IniRead($Ini, $Section, "Key1", "NotFound")
$Messages[1] = IniRead($Ini, $Section, "Key2", "NotFound")
$Messages[2] = IniRead($Ini, $Section, "Key3", "NotFound")
$Messages[3] = IniRead($Ini, $Section, "Key4", "NotFound")
$Messages[4] = IniRead($Ini, $Section, "Key5", "NotFound")

;Run Notepad for testing purposes.
Run("notepad.exe")
WinActivate("Untitled -  Notepad")
WinWaitActive("Untitled - Notepad")

;Send random message by randomizing location in array.
Send($Messages[Random(0, 4, 1)])


;Send 25 more random messages for testing purposes.
Send("{ENTER}");Skip to next line

For $i = 1 to 25
    Send($Messages[Random(0, 4, 1)])
    Send("{ENTER}");Skip to next line
Next

file.ini

[Section1]
Key1=Message 1
Key2=Message 2
Key3=Message 3
Key4=Message 4
Key5=Message 5
Edited by Knight

Share this post


Link to post
Share on other sites
ACalcutt

i think this would work...

$Ini = "file.ini"
$Section = "Section1"
$numberofmessages = IniReadSection ($Ini, $Section)

$msg = IniRead($Ini, $Section, Random(1, $numberofmessages[0][0], 1), "NotFound")
msgbox(0, "random message", "$msg")

ini

[Section1]
1=msg1
2=msg2
3=msg3
etc...
Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Share this post


Link to post
Share on other sites
ACalcutt

or something using the array i used to get the number of keys(from IniReadSection)

$Ini = "file.ini"
$Section = "Section1"
$messages = IniReadSection ($Ini, $Section)

While 1
    $randomnumber = Random(1, $messages[0][0], 1); random number with $messages[0][0] as the top number (amount of keys under section1)
    $buttonpressed = msgbox(1, $messages[$randomnumber][0], $messages[$randomnumber][1])
    If $buttonpressed = 2 Then ExitLoop
WEnd

with this

$messages[$randomnumber][0] is the value before the "=" sign

$messages[$randomnumber][1] is the value after the "=" sign

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×