Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-19-2008, 06:28 PM
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
Smile 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");
}

__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
  #2  
Old 07-19-2008, 07:36 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
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] );
  }

__________________
Reply With Quote
  #3  
Old 07-19-2008, 08:22 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
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
Reply With Quote
  #4  
Old 07-19-2008, 09:25 PM
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
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
__________________
" It's been swell, but the swelling's gone down. "
Reply With Quote
Reply


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 10:55 PM.


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