Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-09-2010, 05:48 AM
Engine Engine is offline
Registered User
Join Date: Jan 2010
Posts: 70
Engine is on a distinguished road
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.
Reply With Quote
  #2  
Old 02-09-2010, 05:51 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #3  
Old 02-09-2010, 05:55 AM
Engine Engine is offline
Registered User
Join Date: Jan 2010
Posts: 70
Engine is on a distinguished road
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.
Reply With Quote
  #4  
Old 02-09-2010, 06:07 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Engine View Post
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

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.
__________________
Reply With Quote
  #5  
Old 02-09-2010, 06:11 AM
Engine Engine is offline
Registered User
Join Date: Jan 2010
Posts: 70
Engine is on a distinguished road
Quote:
Originally Posted by cbk1994 View Post
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

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.
Reply With Quote
  #6  
Old 02-20-2010, 03:53 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura about
Send a message via AIM to adam
Oh, how long have we been able to trigger so easily back and forth?
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly
Reply With Quote
  #7  
Old 02-20-2010, 04:01 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by adam View Post
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.
__________________
Reply With Quote
  #8  
Old 02-20-2010, 04:16 AM
adam adam is offline
http://wiki.graal.us/
adam's Avatar
Join Date: Nov 2001
Posts: 2,247
adam has a spectacular aura about
Send a message via AIM to adam
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.
__________________
Rogue Shadow (TCN)(NAT)(Global Development Team)

For development help, contact the patrons of the #graaldt irc channel below, I am usually there.
Click Here to Join IRC Chat Now! -- irc.freenode.net Channel: #graaldt
Quote:
<Dustyshouri> no, RogueShadow is always talking about scripts lol
<Dustyshouri> in fact, he pretty much brought Graal back as a topic single-handedly

Last edited by adam; 02-20-2010 at 04:33 AM..
Reply With Quote
  #9  
Old 02-20-2010, 04:40 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by adam View Post
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.
__________________
Reply With Quote
  #10  
Old 02-27-2010, 08:19 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
Quote:
Originally Posted by cbk1994 View Post
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();

Reply With Quote
  #11  
Old 02-27-2010, 10:29 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Gambet View Post
And why can't you just do this?

PHP Code:
function onCreated() {
  
findPlayerByCommunityName("AccountNameHere").freezeplayer2();

Aha, I thought freezeplayer2 was only clientside. My bad.
__________________
Reply With Quote
  #12  
Old 07-27-2012, 03:17 AM
Imperialistic Imperialistic is offline
graal player lord
Imperialistic's Avatar
Join Date: Apr 2007
Location: Florida
Posts: 1,094
Imperialistic is a jewel in the roughImperialistic is a jewel in the rough
Quote:
Originally Posted by cbk1994 View Post
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.
__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
  #13  
Old 07-27-2012, 04:38 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Imperialistic View Post
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).
__________________
Reply With Quote
  #14  
Old 07-27-2012, 04:50 AM
Imperialistic Imperialistic is offline
graal player lord
Imperialistic's Avatar
Join Date: Apr 2007
Location: Florida
Posts: 1,094
Imperialistic is a jewel in the roughImperialistic is a jewel in the rough
Ahh! Wow. I totally had the wrong idea on tokens, but now I fully understand them. Thanks, rep+ .
__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
  #15  
Old 07-27-2012, 06:31 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Quote:
Originally Posted by cbk1994 View Post
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 
__________________
Quote:
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 12:01 PM.


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