Need help to improve my code

Ask for scripts here

Moderators: Murderator+, Murderator

Post Reply
r4z13l
Posts: 4
Joined: 2005-08-08 19:24:44

Need help to improve my code

Post by r4z13l »

So, I've made a script for the boring prison system of the shard where I play.

The system is simple, go ask to the NPC what to mine (4 differents types) and go by the use of gates to the mineral, mine it and come back to give it to the NPC.

I had to do it 2000 time, very boring, so I've scripted that :

Code: Select all

sub main()
	var minerai=0
	var x=5309,y=1178 #premiere piece de travail
while not uo.dead()

	while x<>5304 or y<>1173 #devant Rudy
		uo.press(38)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	wait(100)
	uo.deletejournal()
	uo.say("Rudy oui")
	wait(100)
	uo.say("Rudy oui")
	repeat
		wait(100)
	until uo.injournal("chercher un minerai de charbon") or uo.injournal("chercher un minerai de cuivre") or uo.injournal("chercher un minerai de fer") or uo.injournal("chercher un minerai de roche")
	if uo.injournal("chercher un minerai de roche") then
		minerai=1
		uo.print("roches")
		uo.print(str(minerai))
	endif
	if uo.injournal("chercher un minerai de fer") then
		minerai=2
		uo.print("fer")
		uo.print(str(minerai))
	endif
	if uo.injournal("chercher un minerai de cuivre") then
		minerai=3
		uo.print("cuivre")
		uo.print(str(minerai))
	endif
	if uo.injournal("chercher un minerai de charbon") then
		minerai=4
		uo.print("charbon")
		uo.print(str(minerai))
	endif
	
	while x<>5309 or y<>1168 #sortie premiere piece
		uo.press(39)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend

	wait(150)
	while x<>5303 or y<>1168 #debut deuxieme piece
		uo.press(37)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	while x<>5303 or y<>1163 #sortie deuxieme piece
		uo.press(33)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	while x<>5300 or y<>1163
		uo.press(36)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	wait(100)

if (minerai==1) then
	while x<>5299 or y<>1162 #prend le chemin vers les roches
		uo.press(38)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	wait(150)
	while x<>5287 or y<>1166 #arrivee dans la piece des roches
		uo.press(36)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	while x<>5290 or y<>1164
		uo.press(39)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	while x<>5285 or y<>1160 #arrive a cote des roches
		uo.press(38)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	uo.usetype(0x0e85)
	wait(100)
	uo.lclick(375,254)
	while x<>5290 or y<>1166
		uo.press(40)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
endif

if (minerai==2) then
	while x<>5299 or y<>1162 #prend le chemin vers le fer
		uo.press(38)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	while x<>5294 or y<>1162
		uo.press(36)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	wait(150)
	while x<>5277 or y<>1176 #arrivee dans la piece du fer
		uo.press(37)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	while x<>5280 or y<>1174
		uo.press(39)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	while x<>5275 or y<>1170 #arrive a cote du fer
		uo.press(38)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	uo.usetype(0x0e85)
	wait(100)
	uo.lclick(375,255)
	while x<>5280 or y<>1176
		uo.press(40)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
endif

if (minerai==3) then
	while x<>5298 or y<>1161 #prend le chemin vers le cuivre
		uo.press(38)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	while x<>5277 or y<>1166
		uo.press(37)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	wait(150)
	while x<>5280 or y<>1164 #arrivee dans la piece du cuivre
		uo.press(39)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	while x<>5275 or y<>1160 #arrive a cote du cuivre
		uo.press(38)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	uo.usetype(0x0e85)
	wait(100)
	uo.lclick(375,255)
	while x<>5280 or y<>1166
		uo.press(40)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
endif

if (minerai==4) then
	while x<>5300 or y<>1168 #prend le chemin vers le charbon
		uo.press(40)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	wait(150)
	while x<>5287 or y<>1176 #arrivee dans la piece du charbon
		uo.press(37)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	while x<>5290 or y<>1174
		uo.press(39)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	while x<>5285 or y<>1170 #arrive a cote du charbon
		uo.press(38)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	uo.usetype(0x0e85)
	wait(100)
	uo.lclick(375,255)
	while x<>5290 or y<>1176
		uo.press(40)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
endif

	wait(150)
	while x<>5292 or y<>1186 #sortie de n'import quelle piece
		uo.press(37)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	while x<>5309 or y<>1178 #retoure a la case depart
		uo.press(39)
		wait(100)
		x=uo.getx("self")
		y=uo.gety("self")
	wend
	wait(150)

wend
end sub
But there are two problems :
First, I can't use my computer while the script is running due to uo.lclick(), do you know a way to tell the player to clic just in front of him ?
Second, sometimes, the player seems to have trouble for stoping at the right coordinate (x, y) and it makes him run in front of the wall (not very useful).

Thanks You !!!

PS : it's my first script so please, be gentle
Post Reply