Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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, 696 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
  #2  
Old 03-25-2009, 08:18 AM
xXziroXx xXziroXx is offline
Master of Puppets
xXziroXx's Avatar
Join Date: May 2004
Location: Sweden
Posts: 5,288
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Send a message via AIM to xXziroXx Send a message via MSN to xXziroXx
It's nice and all, but something tells me it'll mainly be used by people who loves abusing staff tools on their impopular UC servers
__________________

"A delayed game is eventually good, but a rushed game is forever bad." - Shigeru Miyamoto
Reply With Quote
  #3  
Old 03-25-2009, 08:20 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
Quote:
Originally Posted by xXziroXx View Post
It's nice and all, but something tells me it'll mainly be used by people who loves abusing staff tools on their impopular UC servers
Lol, as for anything else! It is a good example for other scripts and uses though.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #4  
Old 03-25-2009, 03:16 PM
Crono Crono is offline
:pluffy:
Join Date: Feb 2002
Location: Sweden
Posts: 20,000
Crono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond reputeCrono has a reputation beyond repute
This is why I can't take up scripting, so much technical logic stuff.
__________________
Reply With Quote
  #5  
Old 03-25-2009, 06:40 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Sounds nice, might use it for a weapon on Zone
Reply With Quote
  #6  
Old 03-26-2009, 07:14 AM
MiniOne MiniOne is offline
SomeOne
MiniOne's Avatar
Join Date: Dec 2006
Location: Australia
Posts: 1,145
MiniOne is on a distinguished road
Send a message via MSN to MiniOne
Quote:
Originally Posted by Stefan View Post
Sounds nice, might use it for a weapon on Zone
What do you have in mind?
__________________
Quote:
Originally Posted by Huwajux View Post
The pistols look like they have cancer, reduce the big buboe shaped thing's size.
Reply With Quote
  #7  
Old 03-26-2009, 09:46 AM
cyan3 cyan3 is offline
Registered User
cyan3's Avatar
Join Date: Nov 2005
Location: England
Posts: 2,919
cyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant futurecyan3 has a brilliant future
Quote:
Originally Posted by MiniOne View Post
What do you have in mind?
A gravity gun would be fun to use
Reply With Quote
  #8  
Old 03-26-2009, 10:47 AM
Gothika Gothika is offline
Global News Team
Gothika's Avatar
Join Date: Mar 2006
Location: Newcastle, England
Posts: 2,425
Gothika is a splendid one to beholdGothika is a splendid one to beholdGothika is a splendid one to beholdGothika is a splendid one to beholdGothika is a splendid one to behold
Quote:
Originally Posted by cyan3 View Post
A gravity gun would be fun to use
If it was adapted to pick up objects instead. Barrels, mines ect.
__________________


Reply With Quote
  #9  
Old 03-26-2009, 10:53 AM
MiniOne MiniOne is offline
SomeOne
MiniOne's Avatar
Join Date: Dec 2006
Location: Australia
Posts: 1,145
MiniOne is on a distinguished road
Send a message via MSN to MiniOne
Quote:
Originally Posted by cyan3 View Post
A gravity gun would be fun to use
Depending on how it's tested, and if its not Overpowered then yes it could
__________________
Quote:
Originally Posted by Huwajux View Post
The pistols look like they have cancer, reduce the big buboe shaped thing's size.
Reply With Quote
  #10  
Old 03-26-2009, 05:20 PM
Deas_Voice Deas_Voice is offline
Deas
Deas_Voice's Avatar
Join Date: Jun 2007
Location: Sweden
Posts: 2,264
Deas_Voice is a jewel in the roughDeas_Voice is a jewel in the rough
Send a message via AIM to Deas_Voice Send a message via MSN to Deas_Voice Send a message via Yahoo to Deas_Voice
Quote:
Originally Posted by Stefan View Post
Sounds nice, might use it for a weapon on Zone
i hope you don't mean that ETs are going to have dragging a player as a "weapon".
__________________
.
WTF is real life, and where do I Download it?
There is no Real Life, just AFK!
since 2003~
I Support~
ღAeonღ | ღTestbedღ | ღDelteriaღ

if you are going to rep me, don't be an idiot, leave your name!
I got nothing but love for you
Reply With Quote
  #11  
Old 09-08-2011, 01:50 PM
irock1 irock1 is offline
Registered User
Join Date: Aug 2011
Posts: 20
irock1 can only hope to improve
Hi the script worked but how can I setani drag.gani?
__________________
YOUR A
Reply With Quote
  #12  
Old 09-08-2011, 06:16 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
By doing this at this part of the script in the being dragged weapon
PHP Code:
function onTimeout() {
  
temp.speed 0.4;
  
temp.findplayer(client.controller);
  
disabledefmovement();
  
//This is what your after
  
setani("INSERT BEING DRAGGED ANI HERE EXCLUDING .gani"""); 
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #13  
Old 09-08-2011, 10:31 PM
furry_mougle furry_mougle is offline
big heart
furry_mougle's Avatar
Join Date: Aug 2011
Posts: 42
furry_mougle is an unknown quantity at this point
why did he settimer(0)? isn't the minimum 0.05? why even time at all?
__________________
Quote:
Originally Posted by ffcmike View Post
But make sure to change beer.png to Orange Juice.
pay bills to play graal
Reply With Quote
  #14  
Old 09-08-2011, 10:32 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
Quote:
Originally Posted by furry_mougle View Post
why did he settimer(0)? isn't the minimum 0.05? why even time at all?
Probably to try to cancel the timeout.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 01:29 PM.


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