Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Code Gallery (https://forums.graalonline.com/forums/forumdisplay.php?f=179)
-   -   cool summon (https://forums.graalonline.com/forums/showthread.php?t=79294)

[email protected] 04-03-2008 01:53 PM

cool summon
 
summons people if you spell their name wrong!!!

account/nickname:- Sidney/feltcher, Darlene/snowblower, PFA/starfish

[/summon] Sid, felt - Summons Sidney
Dar, snow - Summons Darlene
PFA, star - Summons PFA

PHP Code:

function onActionServerside(temp.commandtemp.account) {
    if (
command == "summon"findPlayer(account).setlevel2(player.level.nameplayer.xplayer.y);
}

//#CLIENTSIDE
function onPlayerChats() {
    if (
player.chat.starts("/summon")) {
        
temp.chat player.chat.substring(7).trim();
        for (
temp.iallplayers
            if (
i.account.starts(chat) || i.nick.starts(chat)) {
                
i.account;
                break;
            }
        }
    
        
triggerserver("weapon"this.name"summon"i);
    }



cbk1994 04-03-2008 04:57 PM

You might consider using something like this that was posted by me. There is a whole thread about this in the code gallery, called 'Function findName()'.

PHP Code:

public function findName

  
this.look = { "account""communityname""nick""id" }; 
   
  for ( 
temp.allplayers 
  { 
    for ( 
temp.this.look 
    { 
      if ( 
makevar"temp.a." temp.) == 
      { 
        return 
temp.a.account
      } 
    } 
  } 
   
  for ( 
temp.allplayers 
  { 
    for ( 
temp.this.look 
    { 
      if ( 
makevar"temp.a." temp.).starts) ) 
      { 
        return 
temp.a.account
      } 
    } 
  } 
   
  return 
false


Which is basically a cleaner, reusable way of what you did.

And then please, use braces for each function so you do this:

PHP Code:

if ( true )
{
  
banana();


instead of this:
PHP Code:

if ( true banana(); 

Makes it easier to read.

Chompy 04-03-2008 09:41 PM

Quote:

Originally Posted by cbkbud (Post 1383944)
You might consider using something like this that was posted by me. There is a whole thread about this in the code gallery, called 'Function findName()'.

PHP Code:

public function findName

  
this.look = { "account""communityname""nick""id" }; 
   
  for ( 
temp.allplayers 
  { 
    for ( 
temp.this.look 
    { 
      if ( 
makevar"temp.a." temp.) == 
      { 
        return 
temp.a.account
      } 
    } 
  } 
   
  for ( 
temp.allplayers 
  { 
    for ( 
temp.this.look 
    { 
      if ( 
makevar"temp.a." temp.).starts) ) 
      { 
        return 
temp.a.account
      } 
    } 
  } 
   
  return 
false


Which is basically a cleaner, reusable way of what you did.

Actually, she was using a method for finding names that started with the parameter, yours check if it equals.

And Sidney, I would suggest using
PHP Code:

...
for(
temp.players) {
  if (
i.account.pos(chat) > -|| i.nick.pos(chat) > -1  || i.communityname.pos(chat) > -1) {
    
i.account;
    break;
  }
}
... 

or something like that, so if their nick/account/community contains the parameter, it will return their account, instead of just checking if their account/nick etc. starts with the parameter

Quote:

Originally Posted by cbkbud (Post 1383944)
And then please, use braces for each function so you do this:

PHP Code:

if ( true )
{
  
banana();


instead of this:
PHP Code:

if ( true banana(); 

Makes it easier to read.

You don't need them if there is a single line action after the if statement, it's all about personal preference.

And it isn't spelled 'braces', that something different :p

cbk1994 04-03-2008 09:45 PM

Quote:

Originally Posted by Chompy (Post 1383987)
Actually, she was using a method for finding names that started with the parameter, yours check if it equals.

And Sidney, I would suggest using
PHP Code:

...
for(
temp.players) {
  if (
i.account.pos(chat) > -|| i.nick.pos(chat) > -1  || i.communityname.pos(chat) > -1) {
    
i.account;
    break;
  }
}
... 

or something like that, so if their nick/account/community contains the parameter, it will return their account, instead of just checking if their account/nick etc. starts with the parameter



You don't need them if there is a single line action after the if statement, it's all about personal preference.

And it isn't spelled 'braces', that something different :p

No, they are braces.

Braces: { }
Brackets: [ ]

And I am checking if there is an exact match first, THEN if there is starting, not just exact ...

Chompy 04-03-2008 11:59 PM

Quote:

Originally Posted by cbkbud (Post 1383988)
No, they are braces.

Braces: { }
Brackets: [ ]

Hmm, actually I found out they are all brackets, but braces is a different name for {}'s..

( ) round brackets or parentheses
[ ] square brackets or box brackets
{ } curly brackets or braces
< > angle brackets or chevrons

braces is kind of a synonym for brackets
And, from the wiki:

Quote:

Originally Posted by Wikipedia
Therefore, when it is necessary to avoid any possibility of confusion, such as in computer programming, it may be best to use the term curly bracket rather than brace.


Quote:

Originally Posted by cbkbud (Post 1383988)
And I am checking if there is an exact match first, THEN if there is starting, not just exact ...

Dude, do you know how many loops there is in your script?
And you don't need 4 for loops to check obj.starts() and obj equals, could be done in 2 for loops, actually even in 1 for loop..

cbk1994 04-04-2008 05:21 AM

It was an example, I know it could be optimized better. It was just to show the type of thing you could do.

About the braces -- I've always heard {} were braces, () were parenthesis, and [] were brackets. Perhaps I've taken the wrong computer classes, or just not a large enough variety of them.

napo_p2p 04-04-2008 11:00 AM

I call {} curly braces. It's sort of redundant, though, now that I look at it...

Switch 04-05-2008 03:27 AM

Quote:

Originally Posted by cbkbud (Post 1384068)
About the braces -- I've always heard {} were braces, () were parenthesis, and [] were brackets. Perhaps I've taken the wrong computer classes, or just not a large enough variety of them.

No, you're right. That's what they're ACTUALLY called.

Chompy 04-05-2008 04:12 AM

Quote:

Originally Posted by Switch (Post 1384247)
No, you're right. That's what they're ACTUALLY called.

Read the wikipedia ^^ It's actually a (curly) bracket but has an other name for it, which is brace.

DustyPorViva 04-05-2008 04:37 AM

Quote:

Originally Posted by [email protected] (Post 1383917)
Darlene/snowblower

:o


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

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