Author Topic: First script help please  (Read 4011 times)

0 Members and 1 Guest are viewing this topic.

Offline Citrus82Topic starter

  • Jr. Member
  • **
  • Posts: 12
  • Activity:
    0%
  • Reputation Power: 1
  • Citrus82 has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
First script help please
« on: May 07, 2011, 08:11:55 AM »
0
Hi,

I just wrote my first script line for line by myself, and im having trouble with the first sub getting skipped. I'm not sure what the problem is, so i figured i would try to get some help here.

Im sure i did lots of things the hard way and ass backwards, but im still learning.

Btw, this script is meant to farm feathers from chickens, and when you get full drop them off at home.

EDIT: To be more clear the gosub setup book gets skipped when i start the script, it goes straight to gosub setup box.

Code: [Select]
;================================
;Kills chickens and loots feathers.
;By Slacker.
;================================
;set %box AYBUPMD   ;set your drop box id here.
set %kill AG    ; monster's id to kill, in this case chicken.
Set %cut HNF   ;Item that cuts the corpse like a dagger.
Set %body YFM  ; Id of bodies on ground, dont touch this.
set %loot VLK   ;Id of items to loot off bodie.
;Set %Rbook WSMIMMD   ;set your rune book id here.
;================================
gosub setup book
gosub setup box
gosub stablecheck
goto Main loop
;================================
Main loop:
gosub Find
gosub Kill
gosub Findncut
gosub Open Dead
gosub Loot
gosub Unload
goto Main loop
;================================
Sub Find
finditem  %kill G_10
if #findkind = -1
{
Gosub Find
}
Return

Sub Kill
Set #ltargetid #FINDID
event macro 15 17
target 3s
event macro 22 0
wait 3s
return

sub Findncut
finditem %cut C_ , #BACKPACKID
Set #LOBJECTID #FINDID
event macro 17 0
wait 1s
finditem YFM G_10
move #FINDX #FINDY
wait
Set #ltargetid #FINDID
event macro 22
Return

Sub Open Dead
FINDITEM %body G_
set #LobjectID #FINDID
event macro 17 0
set %deadbody #CONTID
Return

Sub Loot
wait 1s
finditem %loot C_
if #findkind <> -1
{
    exevent drag #FINDID #FINDSTACK
    wait 15
    exevent dropc #BACKPACKID
    wait 15
    ignoreitem #findid
}
finditem %items C_
if #findkind <> -1
{
 goto loot
}
ignoreitem %deadbody
Return

Sub Unload
set %weight #MAXWEIGHT - 25
if #WEIGHT > %weight
{
wait 1s
finditem %Rbook C_ , #BACKPACKID
set #LobjectID #findID
event macro 17 0
wait 8
set %xclick #contposx + 135
set %yclick #contposy + 192
click %xclick %yclick
wait 8
set %xclick #contposx + 136
set %yclick #contposy + 144
click %xclick %yclick
wait 4s
Drop:
finditem %loot C_ #BACKPACKID
exevent drag #FINDID #FINDSTACK
wait 15
exevent dropc %box
wait 15
finditem %loot C_ #BACKPACKID
if #findkind <> -1
{
goto Drop
}
wait 2s
finditem %Rbook C_ , #BACKPACKID
set #LobjectID #findID
event macro 17 0
wait 8
set %xclick #contposx + 135
set %yclick #contposy + 192
click %xclick %yclick
wait 8
set %xclick #contposx + 295
set %yclick #contposy + 144
click %xclick %yclick
wait 4s
move 1294 1768
}
Return

Sub setup book
event SysMessage pls Target your rune book fool!!!
event SysMessage pls Target your rune book fool!!!
event SysMessage pls Target your rune book fool!!!
event SysMessage pls Target your rune book fool!!!
set #lTargetID X
set #targCurs 1
wait 2
Bookid:
if #lTargetID = X
{
goto Bookid
}
set %Rbook #LTARGETID
finditem %Rbook C_ , #BACKPACKID
set #LobjectID #findID
event macro 17 0
wait 8
set %xclick #contposx + 135
set %yclick #contposy + 192
click %xclick %yclick
wait 8
set %xclick #contposx + 136
set %yclick #contposy + 144
click %xclick %yclick
wait 1s
set %boxcheck #CHARPOSX
return

Sub setup box
event SysMessage Now target your box hoe!!!
event SysMessage Now target your box hoe!!!
event SysMessage Now target your box hoe!!!
event SysMessage Now target your box hoe!!!
set #lTargetID X
set #targCurs 1
wait 2
boxid:
if #lTargetID = X
{
goto boxid
}
set %box #LTARGETID
return

Sub stablecheck
finditem %Rbook C_ , #BACKPACKID
set #LobjectID #findID
event macro 17 0
wait 8
set %xclick #contposx + 135
set %yclick #contposy + 192
click %xclick %yclick
wait 8
set %xclick #contposx + 295
set %yclick #contposy + 144
click %xclick %yclick
wait 4s
set %stallcheck #CHARPOSX
wait 1s
move 1294 1768
return
« Last Edit: May 07, 2011, 08:29:05 AM by Citrus82 »

Offline 12TimesOver

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +565
  • Referrals: 2
    • View Profile
Re: First script help please
« Reply #1 on: May 07, 2011, 08:44:09 AM »
0
Kudos to you for working at it on your own!

First thing is that you can't have spaces in your sub names.

Still looking it over but there's a start.

X
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline Dixie Wrecked

  • Full Member
  • ***
  • Posts: 124
  • Activity:
    0%
  • Reputation Power: 3
  • Dixie Wrecked has no influence.
  • Gender: Male
  • Respect: +61
  • Referrals: 1
    • View Profile
Re: First script help please
« Reply #2 on: May 07, 2011, 09:05:36 AM »
0
Still looking through the code as well, but I see a potential problem in your sub Find:

Code: [Select]
Sub Find
finditem  %kill G_10
if #findkind = -1
{
Gosub Find ; This is the line that could be a problem!
}
Return

Specifically, you don't want to call the sub from within itself, as this may eventually lead to a crash.  Instead, you may want to either try moving the character a short distance to find a new chicken, or simply wait until a chicken wanders within your search range.  Given that you've done all the coding on this yourself, I'll refrain from supplying any code in case you want to research it yourself, but am more than happy to help if you want (although there are many others who can help much more than I, but I still get by!).
"hmm, theres no examples and directions sticky in new member intros.  you have to admit script library would have been a good place to put it"
- karrde

Offline Citrus82Topic starter

  • Jr. Member
  • **
  • Posts: 12
  • Activity:
    0%
  • Reputation Power: 1
  • Citrus82 has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: First script help please
« Reply #3 on: May 07, 2011, 09:33:10 AM »
0
Thanks, i removed the spaces in the two subs and now it doesn't skip them.

I set the three top subs to set the rune book id, drop container id, and get the x coordinates of both my box and chicken recall spot. So i can compare the values after a recall, to see if i actually recalled. You may have spotted the un-used variables that i haven't used yet.

Anyways, instead of skipping the setup gosubs after it gets into the main loop, it goes through them again.

@Dixie Wrecked, thanks ill have to do some reading on that.


Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +757
  • Referrals: 1
    • View Profile
Re: First script help please
« Reply #4 on: May 07, 2011, 10:19:29 AM »
0
you cannot have spaces in any var name tag name goto names sub names   just use _   ie main_loop

Another thing your learning but if you can learn to aviod goto's you will be doing your self a big favour. instead of goto try this
Code: [Select]
set !ExitScript #false
repeat  ; main loop
  ; code
  ; gosub thissub
  ; gosub thatsub
  ; code etx
until !exitscript = #true
halt

As to why it repeated the setup over and over.. thats easy.. When easyuo gets to the last line in the file it goes back to the top in an infinite cirlce .. thats why i recommend a halt command like above... so easyuo didnt reconize your gotos becuase of the spaces thus continued to last line back to first line .. do setup etc.
« Last Edit: May 07, 2011, 10:21:15 AM by Endless Night »
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline Citrus82Topic starter

  • Jr. Member
  • **
  • Posts: 12
  • Activity:
    0%
  • Reputation Power: 1
  • Citrus82 has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: First script help please
« Reply #5 on: May 07, 2011, 11:01:30 AM »
0
Thanks  :)

Its working again, ill have to remember that for my future scripts.

Now if only i cant make/insert my recall check subs, and a world save checker without screwing it up.

Offline The Reaper

  • Jr. Member
  • **
  • Posts: 42
  • Activity:
    0%
  • Reputation Power: 1
  • The Reaper has no influence.
  • Respect: +29
  • Referrals: 1
    • View Profile
Re: First script help please
« Reply #6 on: May 07, 2011, 01:01:14 PM »
0
For world save I simply do this;

In the script setup code I contain this:
Code: [Select]
gosub TM_AdvJournalSync world 100
Then I call a sub within my main loop, as follows: (Please note that the wait is set to 30 seconds here, as some shards I play on have a rather long world save of 8-10 seconds. This script actually searches for the "about to save" message.)
Code: [Select]
sub world_save
gosub TM_AdvJournalScan world VALID_ADVANCE The_world_will_
if #result = #true
   {
   sound
   wait 300
   if %debug = 2
      {
      display ok You've sucessfully got TMs sub to work
      }
   }
return

Then, you must always include TM's subs in your script, those you can find on your own :P

Offline Citrus82Topic starter

  • Jr. Member
  • **
  • Posts: 12
  • Activity:
    0%
  • Reputation Power: 1
  • Citrus82 has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: First script help please
« Reply #7 on: May 07, 2011, 06:38:14 PM »
0
That sounds good but i was wondering, instead of having it wait for 30s, could you have it scanning for something like World_save_complete??

Offline The Reaper

  • Jr. Member
  • **
  • Posts: 42
  • Activity:
    0%
  • Reputation Power: 1
  • The Reaper has no influence.
  • Respect: +29
  • Referrals: 1
    • View Profile
Re: First script help please
« Reply #8 on: May 08, 2011, 04:26:18 AM »
0
You could do that, however then your adding more and more subs into the script, so there's a greater potential for it going wrong. Don't forget, your only losing 30 seconds out of every 30 mins to an hour, depending on how often the world saves are.

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +757
  • Referrals: 1
    • View Profile
Re: First script help please
« Reply #9 on: May 08, 2011, 05:24:13 AM »
0
« Last Edit: May 08, 2011, 05:26:20 AM by Endless Night »
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Tags: