Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Feedback: Single player minimap (https://forums.graalonline.com/forums/showthread.php?t=134266443)

Emera 05-15-2012 07:07 PM

Feedback: Single player minimap
 
1 Attachment(s)
I've been playing around with a lot of areas within GScript that I've never properly looked at before such as SQLite storage methods and more advanced uses for maths. This task was more to do with using maths for more than just placing GUI controls across the screen, and took some thinking on my part.

I've managed to script a simple minimap script that shows your player's position on the map. It works by taking how many levels your GMAP is made up of and finding how many tiles are in those levels added up. It then positions an image on the map image according to the player's location.

It works, I know that, but I'm just curious as to if there's a simpler way to go about doing this. I looked briefly at Dusty's minimap script after finishing this, and his approach is somewhat different to mine.

Any feedback, criticism and advice is welcome as long as it's constructive. Thank you.

(I had to use pastebin.graalcenter.org since incapsula wouldn't let me post the code)

Minimap code (pastebin.graalcenter.org)

cbk1994 05-15-2012 10:47 PM

Just on a readability note, you should make constants like this.mapimage and this.scale actually constants:

PHP Code:

//#CLIENTSIDE
const MAP_IMAGE = "delt_deltlite-mapimg.png";
const 
SCALE = 8;
const 
MAP_DIM = {11, 7};
const 
MARKER = "plisticononline.png";

function 
onCreated() {
  
SetPref();
  
DrawMap();
  
onTimeout();
}

// ... 

It makes it easier for whoever is reading your script to understand that you're just working with magic numbers that never change throughout the script.

You should probably also set profile.modal = false; on the mini map control (MapContainer) so it can't accidentally steal focus from the client.

And a 0.05 second timeout is almost certainly not necessary. Ideally you'd only calculate the position a couple times per second or less, and only when the player has moved.

Emera 05-19-2012 11:09 PM

Thanks for the feedback.

I'm now using constants to store the data instead of this. variables, the control no longer steals the focus from the GraalControl and I'm only checking for the player's position every second now.

Sorry for the slow reply.

BlueMelon 05-20-2012 04:45 PM

Good work! I see you're improving since you started scripting.

Emera 05-20-2012 05:27 PM

Quote:

Originally Posted by BlueMelon (Post 1695126)
Good work! I see you're improving since you started scripting.

heh, thanks BM


All times are GMT +2. The time now is 05:54 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.