Goal Compass

This compass uses polygons to point towards a set objective.

The destination is hardcoded at function changedestination() but it’d work with a little tweaking.

The direction the compass first points at a level that was pregenerated with numbers corresponding to its coordinates, then points at the coordinates inside that level.

Beware the low quality of the video, I didn’T want ot eat up my data for a single example vid.

Bootstrap starts the npcw, my server was designed to have a bootstrap every level so things like this compass get activated on login.

[CODE]
// NPC made by 2ndwolf
if (playerenters) {
if(!isweapon) toweapons compass;
hide;
}

if (bootstrap) {
showstats 1791;
start();
}

if(timeout){
if(this.hidemode=0){
//TODO Manage indexes
showimg 1000,hud_compass.png,32,screenheight-(48+32);
changeimgvis 1000,4;

this.Rdestination = {(this.objlvlCoords[0]-playerx+(this.Iobjlevelx-1)*64)-((this.Icurrlevelx-1)*64),
                     (this.objlvlCoords[1]-playery+(this.Iobjlevely-1)*64)-((this.Icurrlevely-1)*64)};

if(abs(this.Rdestination[0])>1||abs(this.Rdestination[1])>1){
  this.info = getangle(-this.Rdestination[0],-this.Rdestination[1]);
  this.pindir = this.info;
} else this.info += .2%6.28;


showpoly 1002,{32+48/2+(cos((this.info+1.57*3)%6.28)*5),
               screenheight-32-24-(sin((this.info+1.57*3)%6.28)*5),
               32+48/2-(cos(this.info)*22),                         //needle point
               screenheight-32-24+(sin(this.info)*22),               //needle point
               32+48/2+(cos((this.info-1.57*3)%6.28)*5),
               screenheight-32-24-(sin((this.info-1.57*3)%6.28)*5)  //right when north
               };

changeimgvis 1002,5;
changeimgcolors 1002,0,.7,.3,1;

showpoly 1003,{32+48/2+(cos((this.info+1.57*3)%6.28)*5),
               screenheight-32-24-(sin((this.info+1.57*3)%6.28)*5),
               32+48/2-(cos(this.info)*-22),                         //needle point
               screenheight-32-24+(sin(this.info)*-22),               //needle point
               32+48/2+(cos((this.info-1.57*3)%6.28)*5),
               screenheight-32-24-(sin((this.info-1.57*3)%6.28)*5)  //right when north
               };

changeimgvis 1003,5;
changeimgcolors 1003,0.7,0,0,1;


timeout = 0.05;

}
/* if(leftmousebutton&&
mousescreenx in |32,48+32|&&
mousescreeny in |screenheight-(32+48),screenheight-32|){
//TODO, show destination menu
}
*/
}

function changedestination(){
setstring client.Sobjectivelevel,wolf1__21-20.nw;
this.objlvlCoords = {32,60};
}

function calculdestination(){
setstring this.Scurrlevel,#L;

this.Iobjlevelx = strtofloat(#e(7,2,#s(client.Sobjectivelevel)));
this.Iobjlevely = strtofloat(#e(10,2,#s(client.Sobjectivelevel)));

if(startswith(wolf,#L)){
this.Icurrlevelx = strtofloat(#e(7,2,#L));
this.Icurrlevely = strtofloat(#e(10,2,#L));
}
}

function start(){
this.Iplayersize = 1;

if(startswith(wolf,#L)){
this.hidemode = 0;
changedestination();
calculdestination();
} else {
this.hidemode = 1;
hideimg 1000;
hideimg 1002;
hideimg 1003;
}

timeout = 0.05;
}[/CODE]

[video=youtube;4cTSyk9amdA]https://www.youtube.com/watch?v=4cTSyk9amdA[/video]

Nice, pretty useful for quests.

Amazing

Cute script haha, making me tempted to start writing some GS1 again.

Cute because of the way it was scripted? Is it naive or something? I did take me a long time before figuring out how to work with getangle.

no it’s just tricxta strutting his stuff. the fact that you made it without writing a billion lines of gscript means it is good quality to me.

haha, no… it’s just a small yet neat concept is what I meant. My comment had nothing to do with your implementation although we can make this a competition if you like? I’ll rescript it and try make a smaller more efficient version.

Edit: I’m really bored today :frowning:

if (playerenters){
  showstats 1791;

  this.compassX = 100;//central location for compass placement
  this.compassY = screenheight - 100;//""
  this.radius = 24;//(48x48 img)
  this.needleWidth = this.radius / 4;

  showimg 300,compass_hud.png,this.compassX - this.radius,this.compassY - this.radius;
  changeimgvis 300,4;

  timeout = 0.05;
}

if ( timeout ) {
  this.playerC = {playerx,playery};
  this.targetC = {30,12};

  //work out the angle between the target and the player
  this.angle = getangle(this.targetC[1] - this.playerC[1],this.playerC[0] - this.targetC[0]);

  //calculate points of interest
  this.pois = {
    this.compassX + sin(this.angle) * this.radius, this.compassY + cos(this.angle) * this.radius,//needle head(north)
    this.compassX - sin(this.angle) * this.radius, this.compassY - cos(this.angle) * this.radius,//needle head(south)
    this.compassX + sin(this.angle + 90) * this.needleWidth, this.compassY + cos(this.angle + 90) * this.needleWidth,//needle side(1)
    this.compassX + sin(this.angle - 90) * this.needleWidth, this.compassY + cos(this.angle - 90) * this.needleWidth,//needle side(2)
  };

  //north triangle
  showpoly 301, { this.pois[0],this.pois[1],this.pois[4],this.pois[5],this.pois[6],this.pois[7] };
  changeimgcolors 301,1,0,0,1;//red'
  changeimgvis 301,5;

  //south triangle
  showpoly 302, { this.pois[2],this.pois[3],this.pois[4],this.pois[5],this.pois[6],this.pois[7] };
  changeimgcolors 302,0.5,0.5,0.5,1;//grey
  changeimgvis 302,5;

  timeout = 0.05;
}

Turned out to be roughly the same efficiency wise but ehh…

Competition!

Removing features you didn’t implement, blank lines, comments, newline brackets and put multiline commands on a single line; mine takes 15 and yours 21.

Timewise you won… yours took half an hour and mine took like 2 days.

2ndwolf

if (playerenters) { showstats 1791; timeout = 0.05;} if(timeout){ showimg 1000,hud_compass.png,32,screenheight-(48+32); changeimgvis 1000,4; this.Rdestination = {(30-playerx,(12-playery}; this.info = getangle(-this.Rdestination[0],-this.Rdestination[1]); showpoly 1002,{32+48/2+(cos((this.info+1.57*3)%6.28)*5),screenheight-32-24-(sin((this.info+1.57*3)%6.28)*5),32+48/2-(cos(this.info)*22),screenheight-32-24+(sin(this.info)*22),32+48/2+(cos((this.info-1.57*3)%6.28)*5),screenheight-32-24-(sin((this.info-1.57*3)%6.28)*5)}; changeimgvis 1002,5; changeimgcolors 1002,0,.7,.3,1; showpoly 1003,{32+48/2+(cos((this.info+1.57*3)%6.28)*5),screenheight-32-24-(sin((this.info+1.57*3)%6.28)*5),32+48/2-(cos(this.info)*-22),screenheight-32-24+(sin(this.info)*-22),32+48/2+(cos((this.info-1.57*3)%6.28)*5),screenheight-32-24-(sin((this.info-1.57*3)%6.28)*5)}; changeimgvis 1003,5; changeimgcolors 1003,0.7,0,0,1; timeout = 0.05;}

tricxta

if (playerenters){ showstats 1791; this.compassX = 100;//central location for compass placement this.compassY = screenheight - 100;//"" this.radius = 24;//(48x48 img) this.needleWidth = this.radius / 4; showimg 300,compass_hud.png,this.compassX - this.radius,this.compassY - this.radius; changeimgvis 300,4; timeout = 0.05;} if ( timeout ) { this.playerC = {playerx,playery}; this.targetC = {30,12}; this.angle = getangle(this.targetC[1] - this.playerC[1],this.playerC[0] - this.targetC[0]); this.pois = {this.compassX + sin(this.angle) * this.radius, this.compassY + cos(this.angle) * this.radius,this.compassX - sin(this.angle) * this.radius, this.compassY - cos(this.angle) * this.radius,this.compassX + sin(this.angle + 90) * this.needleWidth, this.compassY + cos(this.angle + 90) this.needleWidth,this.compassX + sin(this.angle - 90) * this.needleWidth, this.compassY + cos(this.angle - 90) * this.needleWidth,//needle side(2)}; showpoly 301, { this.pois[0],this.pois[1],this.pois[4],this.pois[5],this.pois[6],this.pois[7] }; changeimgcolors 301,1,0,0,1;//red' changeimgvis 301,5; showpoly 302, { this.pois[2],this.pois[3],this.pois[4],this.pois[5],this.pois[6],this.pois[7] }; changeimgcolors 302,0.5,0.5,0.5,1;//grey changeimgvis 302,5; timeout = 0.05;}

Both acted the same when I tested. I’m aware some lines I saved are variables.

Formatless code is never good!

You’re right… but I didn’t want either of us to win or loose because of style.

Lines of code != efficiency haha. I could’ve compacted my code down a lot like yours but it really sacrifices readability and ultimately maintainability which is something which is advantageous given graal’s npc script size limit but should only ever be done if you really need that much code.
Your code does a lot of the same calculations twice. This has been fun though. Would love to do it again or maybe even write features for your playerworld every now again. Nothing like a quest though, just mechanics.

While I get this was a (random) “competition”, tricxsta is very right. One thing you learn with programming is that readability and maintainability can often exceed the importance of efficiency. This is especially true if other people will be looking at your code. I’ve even had issues looking at my own code. I’ve had to redo a lot with my client project already because I started it out so long ago at a different experience level. Trying to figure out wtf code was doing was difficult at times.

I know guys. My idea of a competition was about code length…

I’m not a below average programmer because I don’t know these things; I’m plagued by the fact that experience has no effect on a programmer’s efficiency. I’ve been programming that frogger minigame and once again got stuck at the same thing as usual: accessing a stupid array correctly. It’s that I can’t keep the numbers in my head or something. Frustrating… had my screen been closer, I wouldn’t have one anymore.

Nobody was trying to insult you. Just offering random advice/wisdom. lol @ the screen comment

No offense taken, codr.

Maybe you could figure out how to make that one:

[COLOR=#A9A9A9]Darkness maze:
Player has to enter alleys that are completely dark.
Will have to steal a lantern at the port level.
The actual maze
A lighting script that would keep the maze challenging without lag and revealing as little as possible.

I have the idea of making it full of 16x16 black showimgs but as I already have one maze, maybe something different could be done with it. Basically, the player has to find an Inn going through the dark alleys of town. Reverse tower defense? Some other kind of minigame that didn’t cross my mind? Plain hacking and slashing? Some kind of puzzle? I haven’t figured out yet what to make of this one so it’s all yours. Only two constraints: it has to be set during night, the player leaves the port to find an Inn… oh and he’s most probably drunk after winning that beer chug contest.[/COLOR]

Hmm, the previous feels like a quest, right? Then:

Oh, or you could script an AI that would play tetris to compete with the player… the goal is to be the first to make X number of lines. In my mind, the AI is there when I think of the game but I was thinking of ditching it and replacing it with a time limit or something like that.

Edit:
Everything otherwise is either done, something I keep as a challenge to myself or tedious bug targeting…
I’m opening up the town levels to be played off of story mode, I have a couple ideas but most houses are devoid of any plan… so if you have something you feel like coding; one the the houses could host it.

[php]if (playerenters) {
showstats 1791;
timeout = .05;}
if(timeout){
showimg 1000,hud_compass.png,32,screenheight-(48+32);
changeimgvis 1000,4;
this.rd = {(30-playerx,(12-playery};
this.i = getangle(-this.rd[0],-this.rd[1]);
showpoly 1002,{32+48/2+(cos((this.i+1.57*3)%6.28)5),screenheight-32-24-(sin((this.i+1.573)%6.28)5),32+48/2-(cos(this.i)22),screenheight-32-24+(sin(this.i)22),32+48/2+(cos((this.i-1.573)%6.28)5),screenheight-32-24-(sin((this.i-1.573)%6.28)5)};
changeimgvis 1002,5;
changeimgcolors 1002,0,.7,.3,1;
showpoly 1003,{32+48/2+(cos((this.i+1.57
3)%6.28)5),screenheight-32-24-(sin((this.i+1.573)%6.28)5),32+48/2-(cos(this.i)-22),screenheight-32-24+(sin(this.i)
-22),32+48/2+(cos((this.i-1.57
3)%6.28)5),screenheight-32-24-(sin((this.i-1.573)%6.28)*5)};
changeimgvis 1003,5;
changeimgcolors 1003,0.7,0,0,1;
timeout = .05;} [/php]

length: 983 -> 915

nearly 10% more efficient!11!! I winnar!

this.rd = {(30-playerx,(12-playery[COLOR=#007700][FONT=&quot][SIZE=12px]};

There parenthesises are to be deleted.
Gratz anyway![/SIZE][/FONT][/COLOR]

That’s probably your fault. I literally copied your code, popped it into notepad and replaced
this.rdestination with this.rd and this.info with this.i

well and I trimmed the 0s from your timeouts.

The script wouldn’t run otherwise and mine does

edit;
Oh, you’re right… the competition version had the mistake.

Like maintainability even matters when it comes to gscripts. Context of the project matters when you decide how to implement.

Sent from my SM-N920R7 using Tapatalk