Left click warp "weapon"

Hey all,

I’m just starting to do some scripting, reading my way through npcprogramming document and such. I had an idea to make a weapon which can be turned on and off, and when on, your left click would change your x and y coord to the mouse’s. Basically a mouse warp NPC.

This is what I have so far:

if (created) {
toweapons MouseWarp;
this.warp = 0;
if (weaponfired && this.warp == 0) {
this.warp = 1;
setplayerprop #c,Left click to warp!;
else if (this.warp == 1){
this.warp = 0;
setplayerprop #c,Warp is turned off!;

if (leftmousebutton && this.warp == 1){ //either the flag is broken or I don’t know how to use it is my conclusion
playerx = mousex; // should I be using mousescreenx and mousescreeny instead?
playery = mousey;

I can turn it on and off, but it doesn’t let me warp :cry:

leftmousebutton is not an event, it’s a flag(it returns true or false).

if (mousedown && leftmousebutton) {}

Thanks a lot :slight_smile:

As for mousescreenx and mousescreeny, those are for GUI Co-ords, using that to warp you would easily send you to some co-ord like 450,320

try using something like this

if(weaponfired){ if(this.on==0){ this.on=1; timeout=0.05; } else if(this.on==1){ this.on=0; timeout=0; } } if(timeout){ if(leftmousebutton){ playerx=mousex; playery=mousey; } timeout=.05; }

not to sure were i got that from but it warps the player around when you fire it, and turns off when you fire it again

Why use a timeout at all?

not sure, i didnt script it,
i just found it lyeing about on the internet.

R.I.P. Graal.net snippets page.

i know ): thats were i went to learn what i was able to before it closed

Thanks for the replies, any help is welcome :slight_smile:

the timeout is used to have a loop going that keeps triggering the script to look at “if (leftmousebutton)” as its not an event.

just if you still care.

Ya I know about events and such… but there are simpler events to use instead of a constant timeout.

You generally want to avoid timeouts as they increase CPU usage. A very poorly designed script with a timeout of 0.05 can start lagging the client. So, as Shiny said, use events if you can.

i tried doing something like this with other players but it did not work…