Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 05-22-2009, 09:23 PM
Struggler Struggler is offline
Zone Repulser =D
Struggler's Avatar
Join Date: May 2006
Posts: 54
Struggler is an unknown quantity at this point
Automatic Promotions?

When I use my clan GUI, when I promote someone, it automatically promotes them over and over to the max rank! x.x Can someone tell me how to fix this?
BTW: its the if(params[0] == "demote") and the if(params[0] == "promote") where im stuck...

PHP Code:
function onActionServerside(){
  if(
clientr.clan != NULL){
  if(
params[0] == "clantag"){
    if (
clientr.clan != NULL){
    if (
player.guild != clientr.clan){
    
player.nick #n@" -"@clientr.position@"- ";
    
player.guild clientr.clan;
    }else{
    
player.chat "Clan tag already on!";
    }
    }else{
    
player.chat "You're not in a clan!";
    }
  }
  if(
params[0] == "add"){
    
temp.pl findplayerbycommunityname(params[1]);
    if (
pl != NULL){
      if (
pl.clientr.clan == NULL){
        if (
clientr.position == "Leader"||clientr.position == "Ancient Warrior"){
        
pl.addweapon("Public/Struggler/ClanTag");
        
pl.chat "You have been added to clan: "@clientr.clan;
        
pl.clientr.clan.add(clientr.clan);
        
pl.clientr.position.add("Recruit");
        
pl.clientr.clan clientr.clan;
        
pl.clientr.position "Recruit";
        
player.chat "Added "@pl@" to your clan: "@clientr.clan;
        }else{
        
player.chat "You don't have enough rights to perform this action!";
        }
      }else{
        
player.chat "Player already in a clan!";
      }
    }else{
      
player.chat "Player not found.";
    }
  }
   if(
params[0] == "remove"){
    
temp.pl findplayerbycommunityname(params[1]);
    if (
pl != NULL){
      if (
pl.clientr.clan != NULL){
        if (
clientr.position == "Leader"||clientr.position == "Ancient Warrior"){
        
pl.removeweapon("Public/Struggler/ClanTag");
        
pl.chat "You have been removed from clan: "@clientr.clan;
        
pl.clientr.clan NULL;
        
pl.clientr.position NULL;
        
player.chat "Removed "@pl@" from your clan: "@clientr.clan;
        }
      }else{
        
player.chat "Player not in a clan!";
      }
    }else{
      
player.chat "Player not found.";
    }
  }
  if(
params[0] == "leave"){
    
player.removeweapon("Public/Struggler/ClanTag");
    
player.chat "Left Clan: "@clientr.clan;
    
sleep(0.1);
    
player.clientr.clan NULL;
    
player.clientr.position NULL;
    
player.removeweapon(this.name);
  }
  if(
params[0] == "update"){
    
player.nick #n@" -"@clientr.position@"- ";
    
sleep(0.1);
    
player.guild clientr.clan;
  }
  if(
params[0] == "promote"){
  
temp.pl findplayerbycommunityname(player.chat);
  if (
pl.clientr.clan == clientr.clan){
    if (
pl != NULL){
      if (
clientr.position == "Leader"||clientr.position == "Ancient Warrior"){
        if (
pl.clientr.position == "Recruit"){
           
pl.clientr.position "Warrior";
           
pl.chat "Rank increased to: Warrior (by "@player.account@")";
           
player.chat "Changed "@pl@"'s Position to Warrior.";
           
sleep(1);
         }
         if (
pl.clientr.position == "Warrior"){
           
pl.clientr.position "Gladiator";
           
pl.chat "Rank increased to: Gladiator (by "@player.account@")";
           
player.chat "Changed "@pl@"'s Position to Gladiator.";
           
sleep(1);
         }
         if (
pl.clientr.position == "Gladiator"){
           
pl.clientr.position "Legendary Gladiator";
           
pl.chat "Rank increased to: Legendary Gladiator (by "@player.account@")";
           
player.chat "Changed "@pl@"'s Position to Legendary Gladiator.";
           
sleep(1);
         }
         if (
pl.clientr.position == "Legendary Gladiator"){
           
pl.clientr.position "Champion";
           
pl.chat "Rank increased to: Champion (by "@player.account@")";
           
player.chat "Changed "@pl@"'s Position to Champion.";
           
sleep(1);
         }
         if (
pl.clientr.position == "Champion"){
           
pl.clientr.position "Ancient Warrior";
           
pl.chat "Rank increased to: Ancient Warrior (by "@player.account@")";
           
player.chat "Changed "@pl@"'s Position to Ancient Warrior.";
           
sleep(1);
         }
         if (
pl.clientr.position == "Ancient Warrior"){
          
player.chat "Cannot promote that player any higher!";
         }
         if (
pl.clientr.position == "Leader"){
          
player.chat "You dont have the rights to change that player's rank!";
         }
      }else{
      
player.chat "You dont have rights to promote/demote.";
      }
    }else{
    
player.chat "Player not found.";
    }
    }else{
    
player.chat "Player not in your clan!";
    }
  }
  if(
params[0] == "demote"){
  
temp.pl findplayerbycommunityname(player.chat);
  if (
pl.clientr.clan == clientr.clan){
    if (
pl != NULL){
      if (
clientr.position == "Leader"||clientr.position == "Ancient Warrior"){
        if (
pl.clientr.position == "Recruit"){
           
player.chat "Cannot demote that player, try the remove tool!";
           
sleep(1);
         }
         if (
pl.clientr.position == "Warrior"){
           
pl.clientr.position "Recruit";
           
pl.chat "Rank decreased to: Recruit (by "@player.account@")";
           
player.chat "Changed "@pl@"'s Position to Recruit.";
           
sleep(1);
         }
         if (
pl.clientr.position == "Gladiator"){
           
pl.clientr.position "Warrior";
           
pl.chat "Rank decreased to: Warrior (by "@player.account@")";
           
player.chat "Changed "@pl@"'s Position to Warrior.";
           
sleep(1);
         }
         if (
pl.clientr.position == "Legendary Gladiator"){
           
pl.clientr.position "Gladiator";
           
pl.chat "Rank decreased to: Gladiator (by "@player.account@")";
           
player.chat "Changed "@pl@"'s Position to Gladiator.";
           
sleep(1);
         }
         if (
pl.clientr.position == "Champion"){
           
pl.clientr.position "Legendary Warrior";
           
pl.chat "Rank decreased to: Legendary Warrior (by "@player.account@")";
           
player.chat "Changed "@pl@"'s Position to Legendary Warrior.";
           
sleep(1);
         }
         if (
pl.clientr.position == "Ancient Warrior"){
           
pl.clientr.position "Champion";
           
pl.chat "Rank decreased to: Champion (by "@player.account@")";
           
player.chat "Changed "@pl@"'s Position to Champion.";
           
sleep(1);
         }
         if (
pl.clientr.position == "Leader"){
          
player.chat "You dont have the rights to change that player's rank!";
         }
      }else{
      
player.chat "You dont have rights to promote/demote.";
      }
    }else{
    
player.chat "Player not found.";
    }
  }else{
  
player.chat "Player not in your clan!";
  }
  }
  }else{
  
player.chat "Unable to perform this action due to: Not in a clan!";
  }
}
//#CLIENTSIDE
function onWeaponFired() {
  
clan_Window1.show();
  
player.chat "Clan Options Opened.";
  new 
GuiWindowCtrl("clan_Window1") {
    
profile GuiBlueWindowProfile;
    
clientrelative true;
    
clientextent "320,213";

    
canmove true;
    
canresize false;
    
closequery false;
    
destroyonhide false;
    
text "Clan Options";
    
400;
    
264;

    new 
GuiButtonCtrl("clantag") {
      
profile GuiBlueButtonProfile;
      
text "Clan Tag";
      
width 80;
      
12;
      
14;
    }
    new 
GuiButtonCtrl("addmember") {
      
profile GuiBlueButtonProfile;
      
text "Add Member";
      
width 80;
      
13;
      
52;
    }
    new 
GuiTextEditCtrl("memberline1") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 205;
      
101;
      
56;
    }
    new 
GuiButtonCtrl("removemember") {
      
profile GuiBlueButtonProfile;
      
text "Remove Member";
      
width 93;
      
13;
      
90;
    }
    new 
GuiTextEditCtrl("memberline2") {
      
profile GuiBlueTextEditProfile;
      
height 20;
      
width 189;
      
114;
      
97;
    }
    new 
GuiButtonCtrl("leaveclan") {
      
profile GuiBlueButtonProfile;
      
text "Leave Clan";
      
width 80;
      
14;
      
128;
    }
    new 
GuiButtonCtrl("updateclantag") {
      
profile GuiBlueButtonProfile;
      
text "Update Clan Tag";
      
width 101;
      
14;
      
167;
    }
    new 
GuiButtonCtrl("promote") {
      
profile GuiBlueButtonProfile;
      
text "Promote";
      
width 101;
      
140;
      
128;
      
hint "Say the name of the player being promoted and hit this button.";
    }
    new 
GuiButtonCtrl("demote") {
      
profile GuiBlueButtonProfile;
      
text "Demote";
      
width 101;
      
140;
      
167;
      
hint "Say the name of the player being demoted, and hit this button.";
    }
    new 
GuiButtonCtrl("news") {
      
profile GuiBlueButtonProfile;
      
text "Clan News";
      
width 80;
      
219;
      
14;
    }
  }
}

function 
clantag.onAction() {
  
triggerserver("gui",this.name,"clantag");
}

function 
addmember.onAction() {
  
triggerserver("gui",this.name,"add",memberline1.text);
}

function 
removemember.onAction() {
  
triggerserver("gui",this.name,"remove",memberline2.text);
}

function 
leaveclan.onAction() {
  
triggerserver("gui",this.name,"leave");
}

function 
updateclantag.onAction() {
  
triggerserver("gui",this.name,"update",player.nick);
}

function 
news.onAction() {
  
player.chat "Work in Progress, check again later.";
}

function 
promote.onAction() {
  
triggerserver("gui",this.name,"promote",player.chat);
}

function 
demote.onAction() {
  
triggerserver("gui",this.name,"demote",player.chat);


Last edited by Struggler; 05-22-2009 at 09:41 PM..
Reply With Quote
  #2  
Old 05-22-2009, 09:43 PM
Gambet Gambet is offline
Registered User
Join Date: Oct 2003
Posts: 2,712
Gambet is on a distinguished road
You need to use else if instead of just if because you are using a sleep after promotion (which I don't really see why), and then since you don't have else if, the compiler reads the next line of code which tells the system to repromote the player again and it will continue this process all the way until there are no more ranks. Also, you should get rid of the sleeps.
Reply With Quote
  #3  
Old 05-22-2009, 10:29 PM
zokemon zokemon is offline
That one guy...
zokemon's Avatar
Join Date: Mar 2001
Location: Sonoma County, California
Posts: 2,925
zokemon is a jewel in the roughzokemon is a jewel in the rough
Send a message via ICQ to zokemon Send a message via AIM to zokemon Send a message via MSN to zokemon Send a message via Yahoo to zokemon
Say the player's position is "Recruit". When the code gets to this line:
NPC Code:
        if (pl.clientr.position == "Recruit"){ 


the result prove true so it continues inside the conditional block and sets the player's position to warrior, your chat tells you it has become warrior and then the script sleeps for a second.

After that is done it comes upon this line:
NPC Code:
         if (pl.clientr.position == "Warrior"){ 


Because you just set pl.clientr.position to Warrior, it is of course, true so the statements inside the conditional block are also read.

You are wondering, why does it read this line too? Well, why wouldn't it? You haven't put anything into the code to stop it from continuing with the following statements.

One solution is to make all the if statements into else if except for the top one (the Recruit one). The else if means that the statement will only be read if the conditional statement before was not true. If it was true, all the following else if statements will be ignored.

Another solution is to use a switch block like:

NPC Code:
switch (pl.clientr.position) {
case "Recruit":
//set the positon to the new one
//and set your chat
break;
case "Warrior":
//set the positon to the new one
//and set your chat
break;
}



Important thing to remember with switchs is that the break; statement causes you to escape the entire switch once the stuff before it has been carried out. The code will automatically skip to which ever case that the variable in the switch is equal to. If you don't have the break before the next case, the code will do the cases after the one it skipped to even if they aren't true.

And yes, you really don't need those sleeps, though I'm assuming you just had them to figure out the problem with the code.
__________________
Do it with a DON!
Reply With Quote
  #4  
Old 05-23-2009, 07:08 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Please see this for your GUIs.

Also, I know it's personal preference, but it really would be nice on our (mine, at least) eyes if you would add line breaks every now and then.

Your code is also hard to follow in some places because you do not consistently indent.

PHP Code:
function onCreated() {
  if (
condition) {
    if (! 
condition2()) {
      
hi();
    }
    
    
hi2();
  }

It's a lot easier to follow if you always indent when using braces.

At the very first few lines, you can do this:

PHP Code:
function onActionServerSide() {
  if (
clientr.clan == null) {
    return;
  } 
which will end the function, rather then adding a big check which just turns out to be confusing.

Around line 6, you're doing (and also near the 'update' command)

PHP Code:
player.nick #n@" -"@clientr.position@"- "; 
which should be (GS2):
PHP Code:
player.nick player.nick SPC "-" clientr.position "-"
or even
PHP Code:
player.nick format("%s -%s-"player.nickclientr.position); 
You can also name your parameters for easier recognition by yourself/others.

PHP Code:
function onActionServerSide(cmd) {
  if (
cmd == "test") { // as opposed to params[0] == "test"
    // code
  
}

Instead of doing

PHP Code:
        pl.clientr.clan.add(clientr.clan);
        
pl.clientr.position.add("Recruit"); 
you should use multi-dimensional arrays to avoid some kind of synchronization error.

PHP Code:
clientr.clans.add({clan_nameposition}); // note that you'd have to update all your other code to reflect this 
You should remove the sleeps, they serve absolutely no purpose that I can see besides potentially messing up the script (sleeps tend to break things).

For promoting/demoting, it would be a lot simpler to do something like

PHP Code:
temp.ranks = {"Recruit""Warrior""Gladiator""Legendary Gladiator""Champion""Ancient Warrior"};
temp.plRank ranks.index(@ pl.clientr.position);

if (
plRank > - 1) {
  if (
plRank == ranks.size() - 1) {
    
// ancient warrior
    
player.chat "You cannot promote Ancient Warriors!";
  } else {
    
pl.clientr.position ranks[plRank 1];
    
pl.chat "Rank changed to" SPC pl.clientr.position SPC "by" SPC player.account "!";
    
player.chat "Changed" SPC pl.account "'s position to" SPC pl.clientr.position "!";
  }
} else {
  
player.chat "You cannot promote leaders!";

Demote would be something like

PHP Code:
temp.ranks = {"Recruit""Warrior""Gladiator""Legendary Gladiator""Champion""Ancient Warrior"};
temp.plRank ranks.index(@ pl.clientr.position);

if (
plRank > - 1) {
  if (
plRank == 0) {
    
player.chat "You cannot demote this player any further!";
  } else {
    
pl.clientr.position ranks[plRank 1];
    
pl.chat "Rank changed to" SPC pl.clientr.position SPC "by" SPC player.account "!";
    
player.chat "Changed" SPC pl.account "'s position to" SPC pl.clientr.position "!";
  }
} else {
  
player.chat "You cannot demote leaders!";

Also, make sure you don't do this

PHP Code:
player.chat "Changed" SPC pl "'s rank"
because 'pl' is a player object. In GS2, when you attempt to print an object, it outputs 'object.name', which happens to be the players account name. Instead you should do something like

PHP Code:
pl.chat "Changed " pl.account "'s rank"
__________________
Reply With Quote
Reply


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 12:46 PM.


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