Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   Triggering a function (https://forums.graalonline.com/forums/showthread.php?t=80606)

Imperialistic 07-19-2008 06:28 PM

Triggering a function
 
This is my first script that actually operates triggeraction.. I'm getting good at GS2 so step back stefan/skyld lmao!


PHP Code:

function onActionServerside(){
  if(
params[0] == "kick"){ 
  if (
player.account == "Imperialistic"){
  
temp.tokens player.chat.tokenize();
  
with(findplayer(temp.tokens[1]).setlevel2("graalcitybank_inside_01.nw",30,30));
  }
 }
}

//#CLIENTSIDE
function onPlayerChats(){
if (
player.chat.starts("/kick")){
triggerserver("gui",this.name,"kick");
}



cbk1994 07-19-2008 07:36 PM

You should style your code better, or at least make it consistent.

Here's how you should have styled it, following what you've already done.

PHP Code:

function onActionServerside(){
  if (
params[0] == "kick"){
    if (
player.account == "Imperialistic"){ 
      
temp.tokens player.chat.tokenize(); 
      
findplayer(temp.tokens[1]).setlevel2("graalcitybank_inside_01.nw",30,30); 
    }
  } 

//#CLIENTSIDE
function onPlayerChats(){ 
  if (
player.chat.starts("/kick")){ 
    
triggerserver("gui",this.name,"kick"); 
  } 


You were doing
PHP Code:

with(findplayer(temp.tokens[1]).setlevel2("graalcitybank_inside_01.nw",30,30)); 

This can be shortened to
PHP Code:

findPlayer(temp.tokens[1]).setlevel2("graalcitybank_inside_01.nw",30,30); 

This is because findPlayer( pl ) becomes that player.

Also, it's a good idea to use findPlayerByCommunityName( pl ) instead. Otherwise, you'll have to use the Graal####### names to kick people.

When you sent the trigger, you didn't send any params and instead tokenized the chat on the serverside part of the script. With a script like this, it's better to tokenize the player's chat and send what you need serverside, in case the players chat changes.

PHP Code:

//#CLIENTSIDE
function onPlayerChats()
{
  if ( 
player.chat.starts"/kick" ) )
  {
    
temp.tokens player.chat.tokenize();
    
triggerserver"gui"name"kick"tokens[1] );
  }


(just put that in whatever formatting you normally use)

A few things that don't really make any difference, but can be changed:
- You don't need the temp. prefix in front of a variable if you've already defined this; see how I used that in the above example with temp.tokens.
- When sending the trigger, you don't need to use this.name. You can just use name
- You can give the 'params' names at the start of a function. Here's an example:
PHP Code:

function onActionServerSidecmdpl )
{
  echo( 
"I received command" SPC cmd SPC "for" SPC pl "." );
  
  if ( 
cmd == "kick" )
  {
    
findPlayerByCommunityNamepl ).setlevel2"graalcitybank)_inside_01.nw"3030 );
  }


If you don't know what echo() does, it just puts that text in RC chat.

Hope this helps you a bit, like I said, ignore my styling and use whatever you prefer. If I were to rewrite your script using what I said, it would look like this:

PHP Code:

function onActionServerSidecmdpl )
{
  if ( 
cmd == "kick" )
  {
    
findPlayerByCommunityNamepl ).setlevel2"graalcitybank_inside_01.nw"3030 );
  }
}
//#CLIENTSIDE
function onPlayerChats()
{
  if ( 
player.chat.starts"/kick" ) )
  {
    
temp.tokens player.chat.tokenize();
    
triggerserver"gui"name"kick"tokens[1] );
  }



[email protected] 07-19-2008 08:22 PM

I'd do this, personally. However, atleast you're understanding params! Great :):)
PHP Code:

function onActionServerSide(temp.optiontemp.player) {
  if (
player.account != "Imperialistic") return false;
  switch(
option) {
    case 
"kick"findPlayer(player).setlevel2("graal.nw"3030); break;
    case 
"summon"findPlayer(player).setlevel2(player.level.nameplayer.xplayer.y); break;
  } 


//#CLIENTSIDE 
function onPlayerChats() { 
  for (
temp.i: ({"kick""summon"})) {
    if (!
player.chat.starts("/" i)) continue;
    
triggerserver("weapon"this.nameiplayer.chat.substring(i.length() + 1),trim());
    break;
  }


I made a similar code along time ago, please excuse the structure though!
http://forums.graalonline.com/forums...ad.php?t=73761

Imperialistic 07-19-2008 09:25 PM

Thanks guys, I'm just starting to understand GS2, the way you guys script is another level for me, But I will study it..

Thanks


All times are GMT +2. The time now is 02:01 AM.

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