Author Topic: commandToServer and commandToClient  (Read 1360 times)

Hey, I was wondering how I'd make a server-sided hotkey for activating servercmds. I've actually seen it before, on Gamefandan's Monster RPG. It'd work like this:
/bind alarm cast speed
So, alarm is the emote key that they're binding it to. After typing this, whenever they press the alarm key it would be like they typed in "/cast speed". Anyone know how to do this?
« Last Edit: August 03, 2015, 06:19:17 PM by Johnny Blockhead »

would it be per player or for the whole server?

if it's for the whole server, it sounds like you could just make the command override the old command with eval or something
if it's for a single player, it'd probably need to override it and parent it depending on who calls it

you could package up servercmdalarm (or any other servercmd actually, the brick controls are /really/ good for this) and just have it do whatever you want

No, that's not what I meant. I know how to make the emotes keybinds, I just want it to be able to a servercmd that each individual player selects for themselves. So, when you press the alarm key it does /cast speed, but when I do it, it does /cast fireball for example.

On second thought, I should just have presets where you just specify what spell you want to cast. I was just lazy and was trying to avoid copy/pasting my code to other parts of the script. But maybe I can use commandtoserver? I dunno, I've never really used it before. I shouldn't have created this topic, sorry.


Edit: So, if I wanted to make a client use the servercmd cast, would it look like this?
commandToClient(%client, 'commandToServer', "Cast", "Speed");
« Last Edit: August 03, 2015, 06:19:55 PM by Johnny Blockhead »

No you can just use serverCmdCast(%client, "Speed");
There is no clientCmdCommandToServer.

if you had a list of commands you wanted to override, you should make a package with all of the functions in it, which then check for if the person calling it overrides it or not, and then parent it or call the new command
may have issues of binding alarm to sit and sit to alarm

Thanks guys! It worked. I never figured out that you can do
serverCmdCast(%client, "Speed");
I'm just curious about one thing. I want to make a system where you drop your items when you die (not actual weapons, more like your gold and wood) and it would use a model that I made. It's pretty much exactly like cash that drops when you die in CityRPG. I know that I'd package an onDeath function, but how'd I make a model pop out of them, and when someone walks over it they absorb it into their inventory (%client.BPGold++).

You should look at CityRPG's code then to learn then.

Creating the object, yeah you could parent onDeath and change the value.
Code: [Select]
%cash = new Item()
{
datablock = castuffem;
canPickup = false;
value = %amount;
};
When you walk over the item, where it says CityRPG data that's where it adds to the player's data. So that's where you'd put %client.BPGold++ or whatever you wanted to add.
Code: [Select]
function Armor::onCollision(%this, %obj, %col, %thing, %other)
{
if(%col.getDatablock().getName() $= "Castuffem")
{
if(isObject(%obj.client))
{
if(isObject(%col))
{
if(%obj.client.minigame)
%col.minigame = %obj.client.minigame;

CityRPGData.getData(%obj.client.bl_id).valueMoney += %col.value;
messageClient(%obj.client, '', "\c6You have picked up \c3$" @ %col.value SPC "\c6off the ground.");

%obj.client.SetInfo();
%col.canPickup = false;
%col.delete();
}
else
{
%col.delete();
MissionCleanup.remove(%col);
}
}
}

if(isObject(%col))
parent::onCollision(%this, %obj, %col, %thing, %other);
}
When the item is added to the world this makes a schedule to delete it after a while if nobody picks it up.
Code: [Select]
function Castuffem::onAdd(%this, %item, %b, %c, %d, %e, %f, %g)
{
parent::onAdd(%this, %item, %b, %c, %d, %e, %f, %g);
schedule($CityRPG::pref::moneyDieTime, 0, "eval", "if(isObject(" @ %item.getID() @ ")) { " @ %item.getID() @ ".delete(); }");
}
And this creates the Castuffem datablock (It just uses the default brick selector model but recolors it.
Code: [Select]
datablock ItemData(castuffem)
{
category = "Weapon";
className = "Weapon";

shapeFile = "base/data/shapes/brickWeapon.dts";
mass = 1;
density = 0.2;
elasticity = 0.2;
friction = 0.6;
emap = true;

doColorShift = true;
colorShiftColor = "0 0.6 0 1";
image = cashImage;
candrop = true;
canPickup = false;
};

datablock ShapeBaseImageData(cashImage)
{
shapeFile = "base/data/shapes/brickWeapon.dts";
emap = true;

doColorShift = true;
colorShiftColor = castuffem.colorShiftColor;
canPickup = false;
};

Thanks for all the help! I wanted to look into a CityRPG's code, but I didn't have one on this computer (away from home).