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(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:
PHP Code:
// 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).