Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Spar Script Awarding Dead player (https://forums.graalonline.com/forums/showthread.php?t=134259284)

sssssssssss 05-23-2010 10:55 PM

Spar Script Awarding Dead player
 
This spar script im doing works completely, until you get to where it keeps track of the streak for the player that wins. It does set a number each time someone dies and the spar is over, but it awards the player that lost/dies with the streak and puts not just 1 win up per spar, but as many of a # that is in the level instead. So if there are 4 people in the level, and someone loses a spar, it says they have won 4 spars, per that one spar. Dunno why, i know im missing something stupid.

PHP Code:

//have to change player.level.name to the spar arena level name
function onCreated(){
//serverr.sparring.remove("sssssssssss");
}
function 
onActionServerSide() {
  if (
params[0] == "addtospar") {
    
serverr.sparline.add(params[1]);
  }
  if (
params[0] == "remfromspar") {
    
serverr.sparline.remove(params[1]);
  }
  if (
params[0] == "getSparrers") {
    if (
serverr.sparring.size() <= 1) {
      if (
serverr.sparline.size() > 0) {
        if (
player.account == serverr.sparline[0]) {
          
serverr.sparring.add(serverr.sparline[0]);
          
serverr.sparline.remove(serverr.sparline[0]);
          
serverr.sparring.remove("");
          
setlevel2(player.level.name,28,50);
          
triggerClient("gui", name, NULL);
        }
      }
    }
  }
  if (
params[0] == "startSpar") {
    if (
serverr.sparring.size() == 2) {
     for (
pl:players) {
       
pl.hearts=20;
       
pl.addWeapon("*SwordOnly");
       if (
params[2]==1) {
         
putbomb(1,25,49);
         
triggerClient("gui", name, "sparStarted");
       }
     }
    }
  }
  if (
params[0] == "endSpar") {
    if (
serverr.sparring.size() == 2) {
     for (
pl:players) {
       
pl.hearts=20;
       
pl.removeWeapon("*SwordOnly");
       
triggerClient("gui", name, NULL);
     }
    }
  }
  if (
params[0] == "leaveSpar") {
    if (
serverr.sparring.size() <= 2) {
      
player.hearts=20;
      
player.removeWeapon("*SwordOnly");
      
serverr.sparring.remove(params[1]);
      
setlevel2(player.level.name,23,60);
      
triggerClient("gui", name, "leaveSpar");
    }
  }
  if (
params[0] == "playerDie") {
   for (
pl:players) {
     
pl.hearts=20;
     
pl.removeWeapon("*SwordOnly");
     if (
params[2]==1) {
       
setlevel2(player.level.name,23,60);
       
serverr.sparring.remove(params[1]);
       
triggerClient("gui", name, "sparEnded");
     }
   }
  }
  if (
params[0] == "addStreak") {
  
player.chat="addStreakBegin";
    
//for (pl:players) {
      //if (params[1] == pl.account) {
      
player.chat=params[1];
        if (
serverr.win_streak_acc == params[1]) {
          
serverr.win_streak_num+=1;
          
player.chat="addStreak1";
          
triggerClient("gui", name, NULL);
        } else {
          
serverr.win_streak_acc = params[1];
          
serverr.win_streak_num = 1;
          
player.chat="addStreak2";
          
triggerClient("gui", name, NULL);
        }
      
//}
    //}
  
}
}
//#CLIENTSIDE
function onActionClientSide() {
  if (
params[0] == "sparStarted") {
    for (
pl:players) {
      if (
InSpar(pl)) {
        
this.sparring = true;
      }
    }
  }
  if (
params[0] == "sparEnded") {
    for (
pl:players) {
      
this.sparring = false;
      
this.inspar = false;
      if (
pl.account != this.dead && InSpar(pl)) {
       
player.chat="sparEnded2";
        
temp.good = player.account;
        
triggerServer("gui", name, "addStreak",temp.good);
      }
    }
  }
  if (
params[0] == "leaveSpar") {
    
this.inspar=false;
  }
  
setTimer(0.05);
}
function 
onCreated() {
  
setTimer(0.05);
  
this.sparlevelarray = {
  
"testtourny2.nw","testtourny.nw"
  
};
  
//x1,x2,y1,y2 for the level where spar arena is
  
this.sparxyarray = {
  {
16,34,41,58},{0,0,0,0}
  };
  
this.sparring=false;
  
this.inspar=false;
}

function 
onPlayerChats() {
  if (
player.chat=="join spar") {
    if (!(
player.account in serverr.sparline)) {
      if (!(
player.account in serverr.sparring)) {
        
player.chat="Added to spar line!";
        
triggerServer("gui", name, "addtospar", player.account);
      } else 
player.chat="You are already in a spar!";
    } else 
player.chat="You are already in the spar line!";
  }
  if (
player.chat=="cancel spar") {
    if (
player.account in serverr.sparline) {
      if (!(
player.account in serverr.sparring)) {
       
player.chat="Removed from spar line!";
       
triggerServer("gui", name, "remfromspar", player.account);
      } else 
player.chat="You are already in a spar!";
    } else 
player.chat="You are not in the spar line!";
  }
  if (
player.chat=="start") {
    if (
this.inspar) {
      if (
serverr.sparring.size() == 2) {
        for (
pl:players) {
          if (
pl.account !=player.account && InSpar(pl)) {
            if (
pl.chat=="start") {
              
triggerServer("gui", name, "startSpar",player.account,this.inspar);
            }
          }
        }
      }
    }
  }
  if (
player.chat=="end spar") {
    if (
this.inspar) {
      if (
serverr.sparring.size() == 2) {
        for (
pl:players) {
          if (
pl.account != player.account && InSpar(pl)) {
            if (
pl.chat=="end spar") {
              
this.sparring=false;
              
player.chat="Spar Stopped!";
              
triggerServer("gui", name, "endSpar");
            }
          }
        }
      }
    }
  }
  if (
player.chat=="leave spar") {
   for (
pl:players) {
    if (
this.inspar) {
      if (
serverr.sparring.size() <= 2) {
        if (
this.sparring != true) {
          if (
InSpar(pl)) {
            
triggerServer("gui", name, "leaveSpar", player.account);
          }
        }
      }
    }
   }
  }              
}
function 
onTimeout() {
  if (
serverr.sparring.size() <= 1) {
    if (
serverr.sparline.size() > 0) {
      
triggerServer("gui", name, "getSparrers");
    }
  }
  if (
player.level.name in this.sparlevelarray) {
    if (
player.x in |this.sparxyarray[0][0],this.sparxyarray[0][1]| && player.y in |this.sparxyarray[0][2],this.sparxyarray[0][3]|) {
      
this.inspar=true;
    } else 
this.inspar=false;
  }
setTimer(0.05);
}
function 
onPlayerDies() {
  if (
player.hearts == 0) {
    
this.dead=player.account;
    
triggerServer("gui", name, "playerDie", player.account, this.inspar);
  }
}
function 
InSpar(pl) {
  if (
pl.x in |this.sparxyarray[0][0],this.sparxyarray[0][1]| && pl.y in |this.sparxyarray[0][2],this.sparxyarray[0][3]|) {
    
this.inspar=true;
    return 
true;
  } else {
    
this.inspar=false;
    return 
false;
  }
} 


WhiteDragon 05-24-2010 02:04 AM

Just a suggestion: if you create a new piece of code directly testing the problem, it will be a lot clearer to you, as well as a lot easier for someone to help. There is too much going on in that code and it looks a lot of work to find a bug.

Cubical 05-24-2010 02:41 AM

Why are you storing your information in serverr.sparline when level.sparline or even this.sparline would be just as effective. The only reason I can think of is that you want to be able to edit people out of the line through RC or from another level which is unnecessary.

fowlplay4 05-24-2010 03:19 AM

Well the script may work for now, but a level NPC joined to a spar would be more effective and easier to manage considering it could easily be done with server-side events.

onPlayerChats()
onPlayerLogin(acct)
onPlayerLogout(acct)
onPlayerKilled(victim, killer)
onPlayerLeaves()

Apply some logic, in the form of if statements and you got yourself a solid spar script.

Just something to think about.

sssssssssss 05-24-2010 04:14 AM

I wanted it serverr.foobar vars so people can join the line from anywhere and be warped in on their turn. So unless using a dbnpc is more effecient, i dont really see another way to do that. And for debug and help purposes on here, just start on the function onPlayerDies under clientside and follow where it leads.

Deeek 05-24-2010 04:56 AM

I was looking this over and noticed something:
PHP Code:

if (params[0] == "sparEnded") { 
    for (
pl:players) { 
      
this.sparring = false; 
      
this.inspar = false; 
      if (
pl.account != this.dead && InSpar(pl)) { 
       
player.chat="sparEnded2"; 
        
temp.good = player.account; 
        
triggerServer("gui", name, "addStreak",temp.good); 
      } 
    } 
  } 

-Looks as if temp.good is being carried over, but isn't being used in serverside?
PHP Code:

if (params[0] == "addStreak") { 
  
player.chat="addStreakBegin"; 
    
//for (pl:players) { 
      //if (params[1] == pl.account) { 
      
player.chat=params[1]; 
        if (
serverr.win_streak_acc == params[1]) { 
          
serverr.win_streak_num+=1; 
          
player.chat="addStreak1"; 
          
triggerClient("gui", name, NULL); 
        } else { 
          
serverr.win_streak_acc = params[1]; 
          
serverr.win_streak_num = 1; 
          
player.chat="addStreak2"; 
          
triggerClient("gui", name, NULL); 
        } 
      
//} 
    //} 
  
} 
} 

Sorry, but can someone explain the reasoning behind this? (if there is one) :D

sssssssssss 05-24-2010 08:12 AM

temp.good is params[1] serverside, so it is being used. The problem for my code relies in the way that temp.good is being set I think (but it could be the serverside part and how params[1] is used just not sure), its just not setting to the winner of the spar, and the loser instead. Does anyone see why that is happening?

Hiro 05-24-2010 09:16 AM

Quote:

Originally Posted by sssssssssss (Post 1578227)
I wanted it serverr.foobar vars so people can join the line from anywhere and be warped in on their turn. So unless using a dbnpc is more effecient, i dont really see another way to do that. And for debug and help purposes on here, just start on the function onPlayerDies under clientside and follow where it leads.

best idea ever am i right? (8

sssssssssss 05-24-2010 08:46 PM

Ok, so tried changing some things, this is what I got. Completely disregarded trying to send the winner, since the winner is still left in serverr.sparring[0] until they leave the spar area, it can add it that way. Now it adds to the correct one, but simply adds two wins instead of one on each win, still dont see why either.

PHP Code:

Taken out b/c lazy pplz stealz codez. 

The rest of the code is the same,

fowlplay4 05-24-2010 09:02 PM

While player.chat does work when you're debugging your best bet in this scenario would be to use echos, preferably at the top like so:

PHP Code:

function onActionServerSide() {
  echo(
this.name @ "triggered by: " @ player.account);
  echo(
"Params: " @ params);
  
// other code follows
} 

There's probably an error in your logic thats causing multiple triggers to occur, or the wrong one.

Hint: Your problem lies in your server-side players for loop.

sssssssssss 05-25-2010 05:17 PM

Lol, i do suppose there is no reason to search players for one being dead after its done in a function. xD Thanks for the help.

sssssssssss 05-25-2010 08:35 PM

Ok, so I learned a valuable lesson here in logic. You cant have a weapon, and expect 2 different players to effect each others values on their player and weapon. Needed to use serverr.foobars to set it while the spar was going on, so it could be true/false, and people could leave the spar appropriately. :)

thanks to everyones help.


All times are GMT +2. The time now is 10:29 AM.

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