Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Question on Server... again ... (https://forums.graalonline.com/forums/showthread.php?t=87558)

sssssssssss 08-22-2009 05:28 PM

Question on Server... again ...
 
PHP Code:

function onCreated() {
  
this.setshape(13232);
}

function 
onActionSetMatchServer(match,vplayer,splayer){
if (
temp.match == "1"){
  
serverr.sdematch1 = {temp.vplayertemp.splayer};
}
if (
temp.match == "2"){
  
serverr.sdematch2 = {temp.vplayertemp.splayer};
}
if (
temp.match == "3"){
  
serverr.sdematch3 = {temp.vplayertemp.splayer};
}
if (
temp.match == "4"){
  
serverr.sdematch4 = {temp.vplayertemp.splayer};
}
if (
temp.match == "5"){
  
serverr.sdematch5 = {temp.vplayertemp.splayer};
}
if (
temp.match == "6"){
  
serverr.sdematch6 = {temp.vplayertemp.splayer};
}
if (
temp.match == "7"){
  
serverr.sdematch7 = {temp.vplayertemp.splayer};
}
if (
temp.match == "8"){
  
serverr.sdematch8 = {temp.vplayertemp.splayer};
}
if (
temp.match == "9"){
  
serverr.sdematch9 = {temp.vplayertemp.splayer};
}
if (
temp.match == "10"){
  
serverr.sdematch10 = {temp.vplayertemp.splayer};
}
}
//#CLIENTSIDE
function onCreated() {
  
this.setshape(13232);
}

function 
onPlayerChats(){
  if (!(
player.account in {"sssssssssss""Decus_Arillias"})) return;
  if (
player.chat.starts("setmatch")) {
    
temp.match player.chat.tokenize()[1];
    
temp.vplayer player.chat.tokenize()[2];
    
temp.splayer player.chat.tokenize()[3];
    
triggeraction(this.0.5this.0.5"SetMatchServer"temp.matchtemp.vplayer,temp.splayer);
  }


ok, now what I'm trying to do, obviously, is set 10 matches. There has got to be a better way to do this than have 10 different server flags isnt there?

I know I could go reading 10 in the array, and I think to pull it out i'd need a for(), but I tried. I've been out of this for 4 years. Sorry guys.

Gambet 08-22-2009 06:01 PM

Yes, you can use a loop instead:

PHP Code:

function onActionSetMatchServer(matchvplayersplayer) {
  for (
temp.0temp.<= 10temp.i++) {
    if (
match == imakevar("serverr.sdematch" i) = {vplayersplayer};
  }


Please note that when defining names for parameters you do not use the temp. prefix to read their values.

sssssssssss 08-22-2009 06:10 PM

Should have known. Forgot to do the if match is i. xD
Like I said, been to long, thanks gambet.

screen_name 08-22-2009 07:21 PM

Quote:

Originally Posted by Gambet (Post 1517571)
Yes, you can use a loop instead:

PHP Code:

function onActionSetMatchServer(matchvplayersplayer) {
  for (
temp.0temp.<= 10temp.i++) {
    if (
match == imakevar("serverr.sdematch" i) = {vplayersplayer};
  }


Please note that when defining names for parameters you do not use the temp. prefix to read their values.

Now, I've seen this in other scripts as well. Just a few questions;
1. Can you explain why the temp. is not required or that just the way it is and I better accept it?
2. Also, does it only apply to temp.variables?
3. Are there any exceptions to this rule? I've noticed that you can use pc[0....10] or whatever to access variables created with temp.pc = player.chat.tokenize();

Gambet 08-22-2009 07:27 PM

Quote:

Originally Posted by screen_name (Post 1517601)
Now, I've seen this in other scripts as well. Just a few questions;
1. Can you explain why the temp. is not required or that just the way it is and I better accept it?
2. Also, does it only apply to temp.variables?
3. Are there any exceptions to this rule? I've noticed that you can use pc[0....10] or whatever to access variables created with temp.pc = player.chat.tokenize();

I meant parameter names with what I stated but it's also true with temp. vars.

If I do this:

PHP Code:

function myFunction(foobar) {


I could read the values of foo and bar by just using the words foo and bar without any prefixes (i.e player.chat = foo SPC bar; or so).

Now, with regards to temporary variables, you only need to use the temp. prefix when first defining them and then all other instances after that you don't need to. It's similar to the whole parameter naming I mentioned above where at first you just need to tell the engine that you're defining a temporary variable for the function, once you have defined it, you no longer need to use a prefix to access it.

So:

PHP Code:

function myFunction() {
  
temp.fooBar "apples";
  
player.chat fooBar;


Of course, you could still use the temp. prefix if you would like but it isn't necessary:

PHP Code:

function myFunction() {
  
temp.fooBar "apples";
  
player.chat temp.fooBar;


^Would work the same.


This doesn't work with this. vars., since this. vars can be accessed throughout the entire script whereas temp. vars are restricted to the function they are created in.

Switch 08-22-2009 07:34 PM

Quote:

Originally Posted by screen_name (Post 1517601)
Now, I've seen this in other scripts as well. Just a few questions;
1. Can you explain why the temp. is not required or that just the way it is and I better accept it?
2. Also, does it only apply to temp.variables?
3. Are there any exceptions to this rule? I've noticed that you can use pc[0....10] or whatever to access variables created with temp.pc = player.chat.tokenize();

1) For for() loops, yes.

2) If you mean using a for() loop, no, but in most cases you'll want to unless you plan to loop through an array of things, find something specific, and use the data somewhere else.

3) player.chat.tokenize() separates the player's chat at every space (" ") and put it in an array (tokenize() can also separate at other points by using a string inside the ()). Using that in temp.pc just makes it so you can access that data using temp.pc (needed when defining it) or pc (any time after defining it) and can only be called inside the function it was defined in.
Array sizes start at 0 for the first param and end at the number 1 less than the last param (in normal counting). Params are accessed using [#]. As an example:
PHP Code:

function onCreated() {
  
temp.array = { 1,2,};
  if (array[
0] == 1)
    echo(
"first param at [0]");
  if (array[
1] == 2)
    echo(
"second param at [1]");
  if (array[
2] == 3)
    echo(
"third param at [2]");



screen_name 08-22-2009 07:46 PM

I knew how to access function parameters using said defined names. I think I took what you said the wrong way, but thanks for your clarifications. One more question though;

What should I expect this to output?
This? [foo] FOOED [temp.foo] foostring [bar] BARRED [temp.bar] barstring

|| This? [foo] foostring [temp.foo] foostring [bar] barstring [temp.bar] barstring
PHP Code:

function onFooMyBar(foo,bar) {
  
temp.foo "foostring";
  
temp.bar "barstring";
  
player.chat "[foo]" SPC foo SPC "[temp.foo]" SPC temp.foo SPC "[bar]" SPC bar SPC "[temp.bar]" SPC temp.bar;
}

function 
onCreated() {
  
onFooMyBar("FOOED","BARRED");


EDIT to Switch: I know how to access functions and use tokenize; I'm just curious as to how temp. works. I'm glad you told me it's scope is the function it's used in.

EDIT to s^11: Sorry to jack your thread

Pelikano 08-22-2009 08:30 PM

Quote:

Originally Posted by Switch (Post 1517607)
PHP Code:

function onCreated() {
  
temp.array = { 1,2,};
  if (array[
0] == 1)
    echo(
"first param at [0]");
  if (array[
1] == 2)
    echo(
"second param at [1]");
  if (array[
2] == 3)
    echo(
"third param at [2]");



There's a way better way of doing this... by looping:

PHP Code:

temp.array = {1,2,3};
for (
temp.params : array) {
  
// blabla



Switch 08-22-2009 09:05 PM

Quote:

Originally Posted by Pelikano (Post 1517623)
There's a way better way of doing this... by looping:

PHP Code:

temp.array = {1,2,3};
for (
temp.params : array) {
  
// blabla



I was trying to show how arrays and params worked, not how looping works.

Pelikano 08-22-2009 10:37 PM

Quote:

Originally Posted by Switch (Post 1517650)
I was trying to show how arrays and params worked, not how looping works.

I was showing how looping arrays works... oO?

sssssssssss 08-24-2009 06:29 PM

Ok. The forum I started was for this script.

PHP Code:

function onCreated() {
  
this.setshape(13232);
}

function 
onActionSetMatchServer(matchvplayersplayer) {
  for (
temp.0temp.<= 10temp.i++) {
    if (
match == imakevar("serverr.sdematch" i) = {vplayersplayer};
  }
}
function 
onActionWarpMatchServer() {
  
setlevel2("testtourny2.nw",30,30);
}
function 
onActionWarpMatchOutServer() {
  
setlevel2("testtourny.nw",1,1);
}

//#CLIENTSIDE
function onCreated() {
  
this.setshape(13232);
  if (
player.dies){
    if (
player.account == serverr.sdematch1[0] || player.account == serverr.sdematch1[1]){
      
triggeraction(this.0.5this.0.5"WarpMatchOutServer","");
    }
  }
}
function 
onPlayerTouchsMe()
  {
  
say2("Match1: " serverr.sdematch1[0] @ " vs. " serverr.sdematch1[1] @ "
  Match2: " 
serverr.sdematch2[0] @ " vs. " serverr.sdematch2[1] @ "
    Match3: " 
serverr.sdematch3[0] @ " vs. " serverr.sdematch3[1] @ "
      Match4: " 
serverr.sdematch4[0] @ " vs. " serverr.sdematch4[1] @ "
        Match5: " 
serverr.sdematch5[0] @ " vs. " serverr.sdematch5[1] @ "
          Match6: " 
serverr.sdematch6[0] @ " vs. " serverr.sdematch6[1] @ "
            Match7: " 
serverr.sdematch7[0] @ " vs. " serverr.sdematch7[1] @ "
              Match8: " 
serverr.sdematch8[0] @ " vs. " serverr.sdematch8[1] @ "
                Match9: " 
serverr.sdematch9[0] @ " vs. " serverr.sdematch9[1] @ "
                  Match10: " 
serverr.sdematch10[0] @ " vs. " serverr.sdematch10[1] @"");
}

function 
onPlayerChats(){
  if (
player.account in serverr.sdeaccess)
    {
    if (
player.chat.starts("setmatch")) {
      
temp.match player.chat.tokenize()[1];
      
temp.vplayer player.chat.tokenize()[2];
      
temp.splayer player.chat.tokenize()[3];
      
triggeraction(this.0.5this.0.5"SetMatchServer"temp.matchtemp.vplayer,temp.splayer);
    }
    if (
player.chat.starts("startmatches")){
      for (
temp.0temp.<= 10temp.i++) {
        if (
== 1){
          if (
!= ""){
            if (
player.account == serverr.sdematch1[0] || player.account == serverr.sdematch1[1]){
              
triggeraction(this.0.5this.0.5"WarpMatchServer","");
            }
          }
        }
      }
    }
  }


Now I'm lost, again. Im trying to set it where you can say "startmatches", and it will go through all the set matches, warping the people in for the first one, warp them out when they die, which will cause the 2nd set of matches to start, and warp them in, ect so on and so on.
Im just lost. Don't know where to go next, at all. help :(

sssssssssss 08-26-2009 07:51 AM

probably not supposed to do this but all. bump

Mark Sir Link 08-26-2009 08:22 AM

Among other things, player.dies is not a variable I am aware of existing. There is a GS1 event called playerdies.

If you plan on using that, it should be in a timeout rather than created so it gets checked more than once.

Your serverside warping functions don't have a player to warp. I believe it is currently warping the NPC itself to another level if it's even being hit.

Take other peoples suggestions from before and create something to clean up the say2, creating a string with a loop.

"if (player.account == serverr.sdematch1[0] " is particularly confusing because you'll only ever warp that particular player in element of the array rather than all the match strings.

zokemon 08-26-2009 09:04 AM

NPC Code:
function onActionSetMatchServer(match, vplayer, splayer) {
for (temp.i = 0; temp.i <= 10; temp.i++) {
if (match == i) makevar("serverr.sdematch" @ i) = {vplayer, splayer};
}
}


Why not this instead:
NPC Code:
function onActionSetMatchServer(match, vplayer, splayer) {
makevar("serverr.sdematch" @ match) = {vplayer, splayer};
}



Don't make a loop if you don't have to ;)

This looks even sexier:

NPC Code:
function onActionSetMatchServer(i, v, s) serverr.(@"sdematch" @ i) = {v, s};



serverr. and server. are the devil though.

Skyld 08-26-2009 01:20 PM

Quote:

Originally Posted by zokemon (Post 1518605)
This looks even sexier:

NPC Code:
function onActionSetMatchServer(i, v, s) serverr.(@"sdematch" @ i) = {v, s};


Get off my forum :(


All times are GMT +2. The time now is 02:47 PM.

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