Scripting School
Would you like to react to this message? Create an account in a few clicks or log in to continue.

New to scripting? We want you!

Official Ventrilo: Host:Apollo.MaxFrag.net Port:3840
TestBed needs our help! Please donate a few dollars to keep it running here!
Have you mastered a specific part of GS2? Create a guide and help others!

You are not connected. Please login or register

Assignment 1 - Kavan

4 posters

Go down  Message [Page 1 of 1]

1Assignment 1 - Kavan Empty Assignment 1 - Kavan Wed May 04, 2011 12:45 pm

Kavan



Code:
//#CLIENTSIDE
function onCreated(){
 setimg("block.png");
 setshape(1,32,32);
 this.insults = {"you smell!","you're ugly!","take a bath!"};
}

function onPlayerTouchsMe(){
 temp.randint = int(random(0,this.insults.size());
 this.chat = player.nick@", "@this.insults[randint];
 sleep(3);
 this.chat = "";
}

Just thought I'd clear the text after someone touches the object, because I think permanent chat looks yucky. Rolling Eyes

2Assignment 1 - Kavan Empty Re: Assignment 1 - Kavan Wed May 04, 2011 6:01 pm

David K?



Kavan wrote:
Code:
//#CLIENTSIDE
function onCreated(){
 setimg("block.png");
 setshape(1,32,32);
 this.insults = {"you smell!","you're ugly!","take a bath!"};
}

function onPlayerTouchsMe(){
 temp.randint = int(random(0,this.insults.size());
 this.chat = player.nick@", "@this.insults[randint];
 sleep(3);
 this.chat = "";
}

Just thought I'd clear the text after someone touches the object, because I think permanent chat looks yucky. Rolling Eyes


Nice... :O
temp.randint = int(random(0,this.insults.size());
If anyone else looks at this, this line is good for others because they would never have to change this line, it depends on the array size.. I think I did it the poor way D:

Anyway, I think you know what you are doing so the following is for anyone else interested.

this.chat = player.nick@", "@this.insults[randint];
Also, I recently learned that SPC does exactly the same as @" "@ does

"for those who don't know, @ separates two things, variable @ variable, string @ variable,

// <- one line comment

/*
Block of comment
*/

After you declare a temp, in the function you no longer have to put temp. behind it. But it does make it easier to understand keeping temp.

Ex.
temp.age = 22; // My age variable.

this.chat = "message here"@temp.age
or
this.chat = "message here"@" "@temp.age
//this now has a space between them.

You could do also do "message here" SPC temp.age
which also has a space between them.



P.S. I still miss PHP on the Graal Forums... :'[

3Assignment 1 - Kavan Empty Re: Assignment 1 - Kavan Wed May 04, 2011 6:50 pm

ZeusCondero


Admin

thanks for using the random line and explaining it in a bit David, I was just about to ask about that!

And David, if this succeeds and these forums get popular, i will be more than happy to pay for an official forum WITH PHP. So by the end of this summer, if people continue to use this, i'll get an offical paid forum.

4Assignment 1 - Kavan Empty Re: Assignment 1 - Kavan Wed May 04, 2011 9:20 pm

David K?



ZeusCondero wrote:thanks for using the random line and explaining it in a bit David, I was just about to ask about that!

And David, if this succeeds and these forums get popular, i will be more than happy to pay for an official forum WITH PHP. So by the end of this summer, if people continue to use this, i'll get an offical paid forum.

Yeah.. D: I used

Code:
function onPlayerTouchesMe(){
  if (player.account != "Devil_Lord2"){
    temp.thingieChat = int(random(1,5.99));
    this.chat = this.awesomeThingieChat[thingieChat];
  }
  else {
    this.chat = this.awesomeThingieChat[6];
  }
}

But I could have done:
"Actually the random should have been 0 starting.. "

Code:

function onPlayerTouchesMe(){
  if (player.account != "Devil_Lord2"){
    temp.thingieChat = int(random(0,this.awesomeThingieChat.size()-.1));
    this.chat = this.awesomeThingieChat[thingieChat];
  }
  else {
    this.chat = this.awesomeThingieChat[this.awesomeThingieChat.size()];
  }
}

If I did this, I'd never have to change the numbers inside the int(random( or the chat numbers..

of course it may be better to replace this.awesomeThingieChat with this.randChat or something.. x.x; I could even make it temp.randChat and only use randChat afterwards assuming its in the same function/statement.

It might be helpful to either comment on peoples post for things that may help others, or to explain our own scripts after we post if we'd like?

Rather then everyone else posting on it, if it works, others wont explain pieces, it tells they understand, and it explains to others what to do. The whole thread would be less cluttered as well with questions or comments. Surprised

Easier to find the information as well..





As for the second half, that is up to you, usually these type of things last for a few months unless the person is really really dedicated.. Not only to keeping care of the forum, but keeping people coming..

Will the PHP be the same as Graal Forums where it is colorful and can scroll? ... I think it can scroll lol I forgot..

5Assignment 1 - Kavan Empty Re: Assignment 1 - Kavan Wed May 04, 2011 11:04 pm

ZeusCondero


Admin

David K? wrote:
ZeusCondero wrote:thanks for using the random line and explaining it in a bit David, I was just about to ask about that!

And David, if this succeeds and these forums get popular, i will be more than happy to pay for an official forum WITH PHP. So by the end of this summer, if people continue to use this, i'll get an offical paid forum.

Yeah.. D: I used

Code:
function onPlayerTouchesMe(){
  if (player.account != "Devil_Lord2"){
    temp.thingieChat = int(random(1,5.99));
    this.chat = this.awesomeThingieChat[thingieChat];
  }
  else {
    this.chat = this.awesomeThingieChat[6];
  }
}

But I could have done:
"Actually the random should have been 0 starting.. "

Code:

function onPlayerTouchesMe(){
  if (player.account != "Devil_Lord2"){
    temp.thingieChat = int(random(0,this.awesomeThingieChat.size()-.1));
    this.chat = this.awesomeThingieChat[thingieChat];
  }
  else {
    this.chat = this.awesomeThingieChat[this.awesomeThingieChat.size()];
  }
}

If I did this, I'd never have to change the numbers inside the int(random( or the chat numbers..

of course it may be better to replace this.awesomeThingieChat with this.randChat or something.. x.x; I could even make it temp.randChat and only use randChat afterwards assuming its in the same function/statement.

It might be helpful to either comment on peoples post for things that may help others, or to explain our own scripts after we post if we'd like?

Rather then everyone else posting on it, if it works, others wont explain pieces, it tells they understand, and it explains to others what to do. The whole thread would be less cluttered as well with questions or comments. Surprised

Easier to find the information as well..





As for the second half, that is up to you, usually these type of things last for a few months unless the person is really really dedicated.. Not only to keeping care of the forum, but keeping people coming..

Will the PHP be the same as Graal Forums where it is colorful and can scroll? ... I think it can scroll lol I forgot..

If I do get a more formal forum, i'd make sure i got one on the same system as Graal's so yeah it would have php. And I agree about people explaining line by line. But people should still be allowed to comment for further clarification. For your next code, if you understand it well you could do it like so:

Only activates the script when it is touched by a player
Code:

function onPlayerTouchesMe(){
Set the script to only work for specific accounts:
Code:
if (player.account != "Devil_Lord2"){

6Assignment 1 - Kavan Empty Re: Assignment 1 - Kavan Thu May 05, 2011 1:54 am

ZeusCondero


Admin

Yo David when are we suppose to put ! in front the "?

Also what does int() exactly do?

7Assignment 1 - Kavan Empty Re: Assignment 1 - Kavan Thu May 05, 2011 10:40 am

Deas



ZeusCondero wrote:Yo David when are we suppose to put ! in front the "?

Also what does int() exactly do?

"if (condition != condition2)" is "if (condition is not equal to condition2)"


int() does what it says, int the input- so if you input a string, it will return -1 (i think), if u input 1.54323, it will output 1.5

8Assignment 1 - Kavan Empty Re: Assignment 1 - Kavan Thu May 05, 2011 10:55 pm

David K?



int(1.5) would be 1... where int always rounds down.
int(1.999999) = 1

I always do .99 because it has a 99% chance to be 1
rather then a .01 % chance to be 2.

Going to test it now.. I'm sure about the rounding down part.
int means integer..


Think about it this way..
random(0,10) can be 0.000000000 through 10.000000000


int( something ) turns it into an integer 1 2 3 4.. no decimals.

int(random(0-10)) is 0 - 10 with 10 having a .000000001% chance of turning up.. "I just checked and all random is 9 places after the decimal.

Point is, that is why I do -.1 and should probably do -.01 for more accuracy it would be good to do -.000000001 >.> but there is no point lol

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum