PDA

View Full Version : Player Dragging


Tigairius
03-25-2009, 08:12 AM
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:

// NPC made by Tig
function onActionServerside(command, acct) {
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.p: players) {
if (mousex in |temp.p.x - 1, temp.p.x + 3| && mousey in |temp.p.y, temp.p.y + 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(obj, mod, mx, my) {
player.attr[28] = "\"" @ mousex SPC mousey @ "\"";
}

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

Here is Weapon2:

// NPC made by Tig
function onStartDrag(control) {
triggerclient("gui", name, "startDrag", control.account);
}
//#CLIENTSIDE
function onCreated() {
}

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

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

if (temp.pos != NULL) {
if (player.x + player.y != temp.pos[0] + temp.pos[1]) {
temp.dist = {temp.pos[0] - player.x, temp.pos[1] - player.y};
temp.mx = dist[0] / (speed * 16);
temp.my = dist[1] / (speed * 16);
player.x += mx;
player.y += 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).

xXziroXx
03-25-2009, 08:18 AM
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 :frown:

Tigairius
03-25-2009, 08:20 AM
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 :frown:

Lol, as for anything else! It is a good example for other scripts and uses though. :D

Crono
03-25-2009, 03:16 PM
This is why I can't take up scripting, so much technical logic stuff. :(

Admins
03-25-2009, 06:40 PM
Sounds nice, might use it for a weapon on Zone :D

MiniOne
03-26-2009, 07:14 AM
Sounds nice, might use it for a weapon on Zone :D

What do you have in mind?

cyan3
03-26-2009, 09:46 AM
What do you have in mind?

A gravity gun would be fun to use :)

Gothika
03-26-2009, 10:47 AM
A gravity gun would be fun to use :)

If it was adapted to pick up objects instead. Barrels, mines ect.

MiniOne
03-26-2009, 10:53 AM
A gravity gun would be fun to use :)

Depending on how it's tested, and if its not Overpowered then yes it could :D

Deas_Voice
03-26-2009, 05:20 PM
Sounds nice, might use it for a weapon on Zone :D

i hope you don't mean that ETs are going to have dragging a player as a "weapon".

irock1
09-08-2011, 02:50 PM
Hi the script worked but how can I setani drag.gani?

Gunderak
09-08-2011, 07:16 PM
By doing this at this part of the script in the being dragged weaponfunction onTimeout() {
temp.speed = 0.4;
temp.c = findplayer(client.controller);
disabledefmovement();
//This is what your after
setani("INSERT BEING DRAGGED ANI HERE EXCLUDING .gani", "");

furry_mougle
09-08-2011, 11:31 PM
why did he settimer(0)? isn't the minimum 0.05? why even time at all?

DustyPorViva
09-08-2011, 11:32 PM
why did he settimer(0)? isn't the minimum 0.05? why even time at all?

Probably to try to cancel the timeout.