Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-25-2009, 08:12 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Player Dragging

Now you can smoothly drag players with your mouse!

It's been a while since I posted anything in the code gallery and I've been wanting to script this for a while now, so I decided to do it tonight while I was free.

What it does:
You click & drag on a player and it will smoothly drag the player behind your mouse.

It decides the position of the player being dragged and then calculates the best way to smoothly move the player to the mouse position. This way we don't have to use multiple 'triggerserver' updates in a timeout and it's not all jumpy.

How to Install:
This is a two-part script. Before you pass it up and say "oh god, I'm not installing multiple things," just read, it's really easy to set up.

You will have two weapons, our "control weapon," which is given to staff members who need the tool to drag players, and the "player weapon," which is added to the players being dragged.

We'll use Weapon1 as our example of the "control weapon." Use Weapon1 for the staff members, who can use it to drag players.

Weapon 1:
PHP Code:
// NPC made by Tig
function onActionServerside(commandacct) {
  switch (
command) {
    case 
"StartDrag":
      
with (findplayer(acct)) {
        
player.addWeapon("Weapon2");
        
client.controller playero.account;
        
findWeapon("Weapon2").trigger("StartDrag"playero);
      }
      
player.attr[20] = acct;
    break;
  }
}

//#CLIENTSIDE
function onCreated() {
  
this.catchEvent(GraalControl"onMouseDragged""onMouseDragged");
}

function 
onMouseDown() {
  for (
temp.pplayers) {
    if (
mousex in |temp.p.1temp.p.3| && mousey in |temp.p.ytemp.p.2|) {
      
this.trigger("StartDrag"temp.p);
      break;
    }
  }
}

function 
onStartDrag(pl) {
  
triggerserver("gui"name"startDrag"pl.account);
}

function 
onMouseUp() {
  
player.attr[28] = player.attr[20] = "";
}

function 
onMouseDragged(objmodmxmy) {
  
player.attr[28] = "\"" mousex SPC mousey "\"";

Now, make sure you replace Weapon2 with the name of your "player weapon."

Here is Weapon2:
PHP Code:
// NPC made by Tig
function onStartDrag(control) {
  
triggerclient("gui"name"startDrag"control.account);
}
//#CLIENTSIDE
function onCreated() {
}

function 
onActionClientside(commandacct) {
  switch (
command) {
    case 
"startDrag":
      
onTimeout();
    break;
  }
}

function 
onTimeout() {
  
temp.speed 0.5;
  
temp.findplayer(client.controller);
  if (
temp.c.attr[20] == player.account) {
    
temp.pos = (temp.c.attr[28].substring(1temp.c.attr[28].length() -2)).tokenize();
  }else {
    
client.controller "";
    
setTimer(0);
    return;
  }

  if (
temp.pos != NULL) {
    if (
player.player.!= temp.pos[0] + temp.pos[1]) {
      
temp.dist = {temp.pos[0] - player.xtemp.pos[1] - player.y};
      
temp.mx dist[0] / (speed 16);
      
temp.my dist[1] / (speed 16);
      
player.+= mx;
      
player.+= my;
    }
  }
  
setTimer(0.05);

Weapon2 will be given to the player that is being dragged. This retrieves data from the dragger and moves the player to the dragger's mouse position.

A lot of servers use this kind of tool for ETs, so have fun but in moderation!

If you're lazy or still don't understand, I've zipped it up for you. All you have to do is drop these two files into your "weapons/" folder on RC and then restart the NPC-Server.

After you've done that, add the weapon to yourself (it's called MouseC).
Attached Files
File Type: zip MouseDragger.zip (1.2 KB, 711 views)
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”

Last edited by Tigairius; 03-25-2009 at 08:30 AM..
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 06:25 AM.


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