Author Topic: *Solved* How to use a servercmd as a Client on a Dedicated Server?  (Read 814 times)

So I have a simple script that works in single player but when I upload it to my server I can no longer access it?
Code: [Select]
function servercmdLaunch(%client,%target)
{
%target=findClientByName(%target).player;
    if(!isObject(%target))
        return;
    else if (!%client.isAdmin)
return;
else
{
//do stuff
}
}
How do I make this so that when I type /launch mickers it runs?

Another quick question: how do I make my add-on auto-execute? I tried adding "exec("Add-Ons/myaddon/server.cs");" to the bottom but I believe that just crashed it.

Thanks.
« Last Edit: October 23, 2013, 05:17:51 PM by Mickers »

As of right now, it wont do anything and looks pretty bad (tbh).

It should run though.
Try this:
function serverCmdLaunch(%client, %target){
   %player = findcientbyname(%target).player;
   if(!isObject(%player) || !%client.isAdmin)
      return;
   %player.setVelocity("0 0 100");
}

You had a small typo (client not cient) but it appears to be working now.

What was I doing wrong?

Thanks!

Although it should still work, you don't need to use else if you are returning. Return essentially just stops reading the function, so if %target isn't an object, then it will be returned, and the rest of the function wont be ran.

As to how to make a script auto-execute; simply put it into a folder or zip file named Script_NAME, change Script to a more suitable name, however only certain types are recognized, and change Name to whatever you want it called. Try to keep it unique so other add-ons don't overwrite it. Then name the file server.cs, or client.cs if its a client sided piece of code, and Blockland will automatically execute it when the server starts (assuming its enabled), or when you start up Blockland (for client.cs).

The reason it crashed when you added the exec at the end is because it executed itself, which then executed itself, which then executed itself, etc, causing an infinite loop.

hange Script to a more suitable name, however only certain types are recognized,
category can be anything for mods that don't fall under special groups like gamemodes, prints, etc.

otherwise it's literally just to make it nice and neat