Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-23-2010, 10:55 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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"nameNULL);
        }
      }
    }
  }
  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"nameNULL);
     }
    }
  }
  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"nameNULL);
        } else {
          
serverr.win_streak_acc params[1];
          
serverr.win_streak_num 1;
          
player.chat="addStreak2";
          
triggerClient("gui"nameNULL);
        }
      
//}
    //}
  
}
}
//#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.accountthis.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;
  }

__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #2  
Old 05-24-2010, 02:04 AM
WhiteDragon WhiteDragon is offline
Banned
Join Date: Feb 2007
Posts: 1,002
WhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to beholdWhiteDragon is a splendid one to behold
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.
Reply With Quote
  #3  
Old 05-24-2010, 02:41 AM
Cubical Cubical is offline
Banned
Join Date: Feb 2007
Posts: 1,348
Cubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant futureCubical has a brilliant future
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.
Reply With Quote
  #4  
Old 05-24-2010, 03:19 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #5  
Old 05-24-2010, 04:14 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #6  
Old 05-24-2010, 04:56 AM
Deeek Deeek is offline
o_O
Deeek's Avatar
Join Date: Jul 2008
Location: Freeburg, Missouri
Posts: 167
Deeek will become famous soon enough
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"nameNULL); 
        } else { 
          
serverr.win_streak_acc params[1]; 
          
serverr.win_streak_num 1
          
player.chat="addStreak2"
          
triggerClient("gui"nameNULL); 
        } 
      
//} 
    //} 
  


Sorry, but can someone explain the reasoning behind this? (if there is one)
__________________
God grant me the serenity to accept the things I cannot change, the courage to change the things I can... and the wisdom to know the difference.
Reply With Quote
  #7  
Old 05-24-2010, 08:12 AM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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?
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #8  
Old 05-24-2010, 09:16 AM
Hiro Hiro is offline
\(^∀^)メ(≧∇≦)ノ
Hiro's Avatar
Join Date: Jan 2005
Posts: 1,965
Hiro has a spectacular aura aboutHiro has a spectacular aura about
Send a message via AIM to Hiro
Quote:
Originally Posted by sssssssssss View Post
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
Reply With Quote
  #9  
Old 05-24-2010, 08:46 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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,
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...



Last edited by sssssssssss; 05-25-2010 at 08:36 PM..
Reply With Quote
  #10  
Old 05-24-2010, 09:02 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
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.
__________________
Quote:
Reply With Quote
  #11  
Old 05-25-2010, 05:17 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
  #12  
Old 05-25-2010, 08:35 PM
sssssssssss sssssssssss is offline
Cyril Rain
sssssssssss's Avatar
Join Date: May 2003
Location: Texas, USA
Posts: 1,134
sssssssssss will become famous soon enough
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.
__________________
Cyril Rain
Creator and leader of SLX
Admin of Elysium
Elysium's Facebook Page: http://facebook.com/GraalOnlineElysium
Graal Forum Thread: http://forums.graalonline.com...
Graalians Thread: http://www.graalians.com...


Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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