PDA

View Full Version : cool summon


04-03-2008, 02:53 PM
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


function onActionServerside(temp.command, temp.account) {
if (command == "summon") findPlayer(account).setlevel2(player.level.name, player.x, player.y);
}

//#CLIENTSIDE
function onPlayerChats() {
if (player.chat.starts("/summon")) {
temp.chat = player.chat.substring(7).trim();
for (temp.i: allplayers)
if (i.account.starts(chat) || i.nick.starts(chat)) {
i = i.account;
break;
}
}

triggerserver("weapon", this.name, "summon", i);
}
}

cbk1994
04-03-2008, 05: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()'.


public function findName( i )
{
this.look = { "account", "communityname", "nick", "id" };

for ( temp.a : allplayers )
{
for ( temp.n : this.look )
{
if ( makevar( "temp.a." @ temp.n ) == i )
{
return temp.a.account;
}
}
}

for ( temp.a : allplayers )
{
for ( temp.n : this.look )
{
if ( makevar( "temp.a." @ temp.n ).starts( i ) )
{
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:


if ( true )
{
banana();
}

instead of this:

if ( true ) banana();


Makes it easier to read.

Chompy
04-03-2008, 10:41 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()'.


public function findName( i )
{
this.look = { "account", "communityname", "nick", "id" };

for ( temp.a : allplayers )
{
for ( temp.n : this.look )
{
if ( makevar( "temp.a." @ temp.n ) == i )
{
return temp.a.account;
}
}
}

for ( temp.a : allplayers )
{
for ( temp.n : this.look )
{
if ( makevar( "temp.a." @ temp.n ).starts( i ) )
{
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

...
for(temp.i : players) {
if (i.account.pos(chat) > -1 || i.nick.pos(chat) > -1 || i.communityname.pos(chat) > -1) {
i = 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


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


if ( true )
{
banana();
}

instead of this:

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, 10:45 PM
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

...
for(temp.i : players) {
if (i.account.pos(chat) > -1 || i.nick.pos(chat) > -1 || i.communityname.pos(chat) > -1) {
i = 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-04-2008, 12:59 AM
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:


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.




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, 06: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, 12:00 PM
I call {} curly braces. It's sort of redundant, though, now that I look at it...

Switch
04-05-2008, 04:27 AM
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, 05:12 AM
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, 05:37 AM
Darlene/snowblower

:o