Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Freezing a player serverside. (https://forums.graalonline.com/forums/showthread.php?t=134257935)

Engine 02-09-2010 05:48 AM

Freezing a player serverside.
 
Is there any possible way to freeze a player serverside? I have tried pl.freezeplayer(time); and pl.disabledefmovement(); neither of them seem to work. Is there any other way to do it? If so can you explain to me the process of doing so.

cbk1994 02-09-2010 05:51 AM

Both of those commands are clientside. And no, there is no way to freeze the player directly from serverside. I've always found it beneficial to create a system weapon to handle things like this:

PHP Code:

//#CLIENTSIDE
function onActionClientSide(cmdtime) {
  if (
cmd == "freezePlayer") {
    
freezePlayer(time);
  }


For example, if that was named System/Freeze, you would do this serverside:

PHP Code:

player.triggerClient("gui""System/Freeze""freezePlayer"SECONDS); 

If you're familiar with player classes, it's also very convenient to setup something like player.freeze() on both serverside and clientside for uniformity.

Engine 02-09-2010 05:55 AM

I thought I couldn't trigger clientside after I triggered serverside?

EDIT: Could you also show me an example of how it would look in a class so i would be able to do player.freeze('time'); It doesn't need to be the freeze example it could be any easy example like player.apset('blahblah'); even though there is already a command for that it's the only thing i could think up off the top of my head haha.

cbk1994 02-09-2010 06:07 AM

Quote:

Originally Posted by Engine (Post 1555014)
I thought I couldn't trigger clientside after I triggered serverside?

Nope. You can trigger either way back and forth as much as you want. You can create an infinite loop if you want:

PHP Code:

function onActionServerSide(cmd) {
  if (
cmd == "ping") {
    
triggerClient("gui"this.name"ping");
  }
}

//#CLIENTSIDE
function onCreated() {
  
triggerServer("gui"this.name"ping"); // start the loop
}

function 
onActionClientSide(cmd) {
  if (
cmd == "ping") {
    
this.counter ++;
    
player.chat "Pings: " this.counter;
    
triggerServer("gui"this.name"ping");
  }


Though obviously you wouldn't want to do something like that in practical scripting :p

You can also trigger weapons of other players.

PHP Code:

function onActionServerSide(cmdtargetmsg) {
  if (
cmd == "tell") {
    
temp.pl findPlayerByCommunityName(target);
    
    if (
pl == null) {
      return 
player.chat "(player not found)";
    }
    
    
pl.triggerClient("gui"this.name"tell"player.communitynamemsg);
  }
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("tell")) { // format is: tell account "message here"
    
temp.tokens player.chat.tokenize();
    
    
temp.acc tokens[1];
    
temp.msg tokens[2];
    
    
triggerServer("gui"this.name"tell"accmsg);
  }
}

function 
onActionClientSide(cmdsendermsg) {
  if (
cmd == "tell") {
    
player.chat sender ": " msg;
  }


To use this you would say: tell cbk1994 "Hi there ugly!"

That would trigger serverside, try to find a player with the community name 'cbk1994', and if found, trigger clientside on the same weapon for that player. Once it receives the trigger clientside, it would set my chat to 'Engine: Hi there ugly!'.

This is a bit of a silly example since you can set players' chat serverside, but it could be used, for example, if you have some kind of GUI window displaying the message.

Engine 02-09-2010 06:11 AM

Quote:

Originally Posted by cbk1994 (Post 1555017)
Nope. You can trigger either way back and forth as much as you want. You can create an infinite loop if you want:

PHP Code:

function onActionServerSide(cmd) {
  if (
cmd == "ping") {
    
triggerClient("gui"this.name"ping");
  }
}

//#CLIENTSIDE
function onCreated() {
  
triggerServer("gui"this.name"ping"); // start the loop
}

function 
onActionClientSide(cmd) {
  if (
cmd == "ping") {
    
this.counter ++;
    
player.chat "Pings: " this.counter;
    
triggerServer("gui"this.name"ping");
  }


Though obviously you wouldn't want to do something like that in practical scripting :p

You can also trigger weapons of other players.

PHP Code:

function onActionServerSide(cmdtargetmsg) {
  if (
cmd == "tell") {
    
temp.pl findPlayerByCommunityName(target);
    
    if (
pl == null) {
      return 
player.chat "(player not found)";
    }
    
    
pl.triggerClient("gui"this.name"tell"player.communitynamemsg);
  }
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("tell")) { // format is: tell account "message here"
    
temp.tokens player.chat.tokenize();
    
    
temp.acc tokens[1];
    
temp.msg tokens[2];
    
    
triggerServer("gui"this.name"tell"accmsg);
  }
}

function 
onActionClientSide(cmdsendermsg) {
  if (
cmd == "tell") {
    
player.chat sender ": " msg;
  }


To use this you would say: tell cbk1994 "Hi there ugly!"

That would trigger serverside, try to find a player with the community name 'cbk1994', and if found, trigger clientside on the same weapon for that player. Once it receives the trigger clientside, it would set my chat to 'Engine: Hi there ugly!'.

This is a bit of a silly example since you can set players' chat serverside, but it could be used, for example, if you have some kind of GUI window displaying the message.

Oh, that's cool. I feel like I have been held back because I thought triggering serverside was a one way road. haha thanks.

adam 02-20-2010 03:53 AM

Oh, how long have we been able to trigger so easily back and forth?

cbk1994 02-20-2010 04:01 AM

Quote:

Originally Posted by adam (Post 1557347)
Oh, how long have we been able to trigger so easily back and forth?

Since the introduction of the NPC-server. 'triggerserver' and 'triggerclient' were introduced with Gscript2 for simplification, though.

adam 02-20-2010 04:16 AM

Yeah, I got to work with the npc server some before my "long vacation" if you will. Maybe it's because I was younger, but it seemed way complicated to do it with gs1 and make it look easy.

NPC Code:
    triggerServer("gui", this.name, "tell", acc, msg); 



I have been looking at this line, am I to understand "gui" refers to Weapons/Gui npc's and 'this.name' is the name of the current weapon/gui npc and that's why it triggers the 'onActionServerside' from the current weapon?

I suppose it may be obvious, but hey i'm here to get this stuff down, and I want to know exactly why i am typing something if I have to include it.

cbk1994 02-20-2010 04:40 AM

Quote:

Originally Posted by adam (Post 1557353)
Yeah, I got to work with the npc server some before my "long vacation" if you will. Maybe it's because I was younger, but it seemed way complicated to do it with gs1 and make it look easy.

NPC Code:
    triggerServer("gui", this.name, "tell", acc, msg); 



I have been looking at this line, am I to understand "gui" refers to Weapons/Gui npc's and 'this.name' is the name of the current weapon/gui npc and that's why it triggers the 'onActionServerside' from the current weapon?

I suppose it may be obvious, but hey i'm here to get this stuff down, and I want to know exactly why i am typing something if I have to include it.

Yeah, that's correct. The parameters are:

triggerServer(type, script, param1, [...]);

'type' can be 'gui' or 'weapon' (Weapon/GUI scripts; personal preference which to use) or 'npc' (DB npc).

'script' is the name of the script. You can always use 'this.name' if triggering the same script. This is preferable since it makes it easy to change script names without a lot of refactoring.


With GS1 it was something like

PHP Code:

triggeraction 00serverside#N, param1; 

if I recall.

Gambet 02-27-2010 08:19 PM

Quote:

Originally Posted by cbk1994 (Post 1555013)
And no, there is no way to freeze the player directly from serverside.

And why can't you just do this?

PHP Code:

function onCreated() {
  
findPlayerByCommunityName("AccountNameHere").freezeplayer2();



cbk1994 02-27-2010 10:29 PM

Quote:

Originally Posted by Gambet (Post 1559418)
And why can't you just do this?

PHP Code:

function onCreated() {
  
findPlayerByCommunityName("AccountNameHere").freezeplayer2();



Aha, I thought freezeplayer2 was only clientside. My bad.

Imperialistic 07-27-2012 03:17 AM

Quote:

Originally Posted by cbk1994 (Post 1555017)
PHP Code:

function onActionServerSide(cmdtargetmsg) {
  if (
cmd == "tell") {
    
temp.pl findPlayerByCommunityName(target);
    
    if (
pl == null) {
      return 
player.chat "(player not found)";
    }
    
    
pl.triggerClient("gui"this.name"tell"player.communitynamemsg);
  }
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("tell")) { // format is: tell account "message here"
    
temp.tokens player.chat.tokenize();
    
    
temp.acc tokens[1];
    
temp.msg tokens[2];
    
    
triggerServer("gui"this.name"tell"accmsg);
  }
}

function 
onActionClientSide(cmdsendermsg) {
  if (
cmd == "tell") {
    
player.chat sender ": " msg;
  }


To use this you would say: tell cbk1994 "Hi there ugly!"

Instead of creating a new thread I'm just going to bump this, sowwwy.

I have been trying to sharpen my scripting skills lately and I ran into a problem with this.. The script works fine and everything but I don't understand why we have to put the quotation marks around the "message" or else it wont register. I believe there is another way to read the player chat but I'm unsure of it.

cbk1994 07-27-2012 04:38 AM

Quote:

Originally Posted by Imperialistic (Post 1700206)
Instead of creating a new thread I'm just going to bump this, sowwwy.

I have been trying to sharpen my scripting skills lately and I ran into a problem with this.. The script works fine and everything but I don't understand why we have to put the quotation marks around the "message" or else it wont register. I believe there is another way to read the player chat but I'm unsure of it.

Because it's using tokenize, which splits a string at a delimiter (a space if you don't specify one).

PHP Code:

temp.array = "/tell cbk1994 hello there".tokenize();
// array is {"/tell", "cbk1994", "hello", "there"} 

tokenize won't escape at delimiters inside quotation marks, so by placing the message inside quotes it doesn't get split at spaces and the entire message is contained in tokens[2]. Otherwise, only the first word of the message is contained in that index of the array.

The alternative is to use string.substring(startIndex, length) which simply takes part of a string:

PHP Code:

"abcd".substring(1// bcd
"abcd".substring(01// a
"abcd".substring(03// abc
"abcd".substring(11// b 

If I'm using a simple command with one parameter, say "/echo [message]", then we can easily use substring:

PHP Code:

if (player.chat.starts("/echo ")) {
  
temp.msg player.chat.substring(6);


By chopping off the first 6 characters ("/echo "), we're left with only the message.

However, this doesn't work as well for commands with multiple parameters. For the command "/tell [account] [message]", the number of characters to chop off the front of the player's chat to get the message depends on how long the account is, which varies. We can use tokenize to split at spaces, take the length of the second token (the account), and use that to determine the number of characters to chop off to get the message:

PHP Code:

if (player.chat.starts("/tell ")) {
  
temp.tokens player.chat.tokenize();
  
  
temp.acc temp.tokens[1];
  
temp.msg player.chat.substring(temp.acc.length() + 1); // "/tell " + account length + space after account


The problem with doing this for commands that take multiple parameters is that all parameters except the long one must have a fixed number of spaces (words).

In other words, using the script above, I couldn't say "/tell Fidel Castro hi there!". Even though "Fidel Castro" is an actual account, there is no way for the command to know that because it has a space (some accounts contain spaces). It will try to send the message "Castro hi there!" to account "Fidel".

Using tokenize we can just use:
Quote:

/tell "Fidel Castro" "hi there!"
It's possible to craft some creative solutions to this problem, but in practice there's usually a better way to implement these kind of commands (typing in another player's account is pretty annoying).

Imperialistic 07-27-2012 04:50 AM

Ahh! Wow. I totally had the wrong idea on tokens, but now I fully understand them. Thanks, rep+ .

fowlplay4 07-27-2012 06:31 AM

Quote:

Originally Posted by cbk1994 (Post 1700214)
splits a string at a delimiter (a space if you don't specify one).

It delimits by space and reads it like an array when you don't specify a parameter. Here's a case where I explicitly had to specify a space as the delimiter.

I.e.

PHP Code:

function onCreated() {
  
temp."blah, blah, blah";
  for (
temp.atemp.s.tokenize()) echo(temp.a);
  echo(
" ");
  for (
temp.atemp.s.tokenize(" ")) echo(temp.a);


PHP Code:

The script of NPC JerretNPC has been updated by fowlplay4
blah
blah
blah

blah
,
blah,
blah 



All times are GMT +2. The time now is 04:53 AM.

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