Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Problem with guilds (https://forums.graalonline.com/forums/showthread.php?t=134263762)

Trakan 07-05-2011 06:39 PM

Problem with guilds
 
Ok , my script does not work , here is :

PHP Code:

// Scripted by *Trakan
//#CLIENTSIDE
function onWeaponFired() {
say2 Ecrit /tag pour mettre le #btag de ta nation!;
}
public function 
destroy() : void {
  
temp.stack = getCallStack();
  
temp.npc = stack[stack.size()-2].scriptcallobject.name;

  echo(
"[NPC Error]: '"@ npc @"' tried to delete '"@ this.name @"'");
}
function 
onActionServerSide(cmd, tag) {
  switch (
cmd) {
    case 
"tagOn": {
      if (
tag == null) {
        break;
      }

      
player.guild = tag;
      break;
    }
  }
}
//#CLIENTSIDE
function onPlayerChats() {
  switch (
player.chat) {
    case 
"/tag": {
      
triggerserver("gui", clientr.towntagrank, name, "tagOn", clientr.towntag);
      break;
    }
  }
} 

If i say /tag , nothing...
Thank you for your future help :)

0PiX0 07-05-2011 06:53 PM

You have two //#CLIENTSIDE lines.
You are using gs1 in the onWeaponFired part.

Remove this..
Quote:

Originally Posted by Trakan (Post 1657472)
PHP Code:

//#CLIENTSIDE
function onWeaponFired() {
  
say2 Ecrit /tag pour mettre le #btag de ta nation!;
} 



Trakan 07-05-2011 07:03 PM

Thanks , it work but
PHP Code:

triggerserver("gui", clientr.towntagrank, name, "tagOn", clientr.towntag); 

clientr.towntagrank does not work, it is not displayed to the player's name.

0PiX0 07-05-2011 07:54 PM

Quote:

Originally Posted by Trakan (Post 1657478)
Thanks , it work but
PHP Code:

triggerserver("gui", clientr.towntagrank, name, "tagOn", clientr.towntag); 

clientr.towntagrank does not work, it is not displayed to the player's name.

Looks out of syntax.
triggerserver(type, name, params)

Also it's unneccessary to send clientr. prefixed vars to the server, since it can read clientr. vars there.

Try
PHP Code:

triggerserver("gui", this.name, "tagOn"); 

Then, in your onActionServerSide function... something like this.
PHP Code:

function onActionServerSide(cmd) { 
  switch (
cmd) { 
    case 
"tagOn": { 
      
player.guild = clientr.towntag; 
      break; 
    } 
  } 
} 


Trakan 07-05-2011 08:05 PM

But i can't add prefix to name?

Mark Sir Link 07-05-2011 08:57 PM

Quote:

Originally Posted by Trakan (Post 1657487)
But i can't add prefix to name?

name refers to the name of the object you are triggering, in this case, the weapon's name, i.e., this.name

Trakan 07-05-2011 09:07 PM

Oh i ses , but how to add prefix on a name?

fowlplay4 07-05-2011 11:15 PM

Ah I get it now... You want to set a rank prefix in front of the player's name. I.e:

King, fowlplay4 (Guild)

Here's a function that would do that:

PHP Code:

function setGuildTag(guild_name, rank) {
  
player.guild = guild_name;
  if (!
player.nick.starts((rank @ ", "))) {
    
player.nick = format("%s, %s", rank, player.nick);
  }
} 

Usage:

PHP Code:

function onActionServerSide(cmd) {  
  switch (
cmd) {  
    case 
"tagOn": {  
      
setGuildTag(clientr.towntag, clientr.towntagrank);
      break;  
    }  
  }  
}

function 
setGuildTag(guild_name, rank) {
  
player.guild = guild_name;
  if (!
player.nick.starts((rank @ ", "))) {
    
player.nick = format("%s, %s", rank, player.nick);
  }
}

/* your other code */ 


Trakan 07-06-2011 01:03 AM

My flags are clientr.towntag for the Town (ex : vaxxo) and clientr.towntagrank for the player rank.
I replace guild_tag by clientr.towntag ?
What's the final script if the player say /tag , i'm confused :s

fowlplay4 07-06-2011 01:40 AM

Quote:

Originally Posted by Trakan (Post 1657519)
My flags are clientr.towntag for the Town (ex : vaxxo) and clientr.towntagrank for the player rank.
I replace guild_tag by clientr.towntag ?
What's the final script if the player say /tag , i'm confused :s

Those are just function parameters. In my usage example it passes the value of your clientr flags to the function.

You may benefit from reading my scripting guide, particularly the section on functions.
fowlplay4's scripting guide: functions

I've pretty much given you the solution to your problem in my last post, you just need to piece it together now.

Trakan 07-06-2011 11:14 AM

Thanks it work !
(and good wiki ;))

Trakan 07-06-2011 01:19 PM

New problem , i make a tool for king of a town , my flags does not work , if i say /add , it's say it work ! but i not got xen tag !
PHP Code:

// Scripté par Trakan :D
//#CLIENTSIDE
//Pour Xenos
if (clientr.towntag == Xen) {
 if (
clientr.towntagrank == Guerrier) {
function 
onPlayerChats() {
  switch (
player.chat) {
    case 
"/add": {
    
player.chat = "Work!";
    } else {
    
player.chat = "not work !";
    }
   }
  }
 }
} 

And else {
does not work :(

cbk1994 07-06-2011 02:34 PM

First, you never want functions to be inside any if-blocks*. The checks you did for the towntag and the townrank should be inside the function.

PHP Code:

// Scripté par Trakan :D 
//#CLIENTSIDE 
//Pour Xenos 
function onPlayerChats() {
  if (
clientr.towntag == Xen) { 
    if (
clientr.towntagrank == Guerrier) { 
      switch (
player.chat) { 
        case 
"/add": { 
          
player.chat = "Work!"; 
        } else { 
          
player.chat = "not work !"; 
        } 
      } 
    }
  }
} 

The next problem is that strings need to be inside quotations:

PHP Code:

  if (clientr.towntag == "Xen") { 
    if (
clientr.towntagrank == "Guerrier") { 

You're using the switch statement wrong. I'm going to recommend that you avoid it entirely until you have a better understanding of GScript (in this case I would advise not using it anyway). You can use a standard if statement like this:

PHP Code:

// Scripté par Trakan :D 
//#CLIENTSIDE 
//Pour Xenos 
function onPlayerChats() {
  if (
clientr.towntag == "Xen") { 
    if (
clientr.towntagrank == "Guerrier") { 
      if (
player.chat == "/add") {
        
player.chat = "Work!"; 
      } else { 
        
player.chat = "not work !"; 
      } 
    }
  }
} 

The problem now is that even though the code is correct, it's logically not right. If the player has towntag of "Xen" and towntagrank of "Guerrier" and says anything except "/add", it will make them say "not work !".

Instead, you want to change it so it checks if the player is saying "/add" before checking their tag and tagrank. I'm also combining the rank and tag check into one statement:

PHP Code:

// Scripté par Trakan :D 
//#CLIENTSIDE 
//Pour Xenos 
function onPlayerChats() {
  if (
player.chat == "/add") {
    if (
clientr.towntag == "Xen" && clientr.towntagrank == "Guerrier") {  
      
player.chat = "Work!"; 
    } else { 
      
player.chat = "not work !"; 
    }
  }
} 

If anything I said doesn't make sense, I'll be happy to explain it further.

* This doesn't apply to anonymous functions, but don't worry about them yet.


All times are GMT +2. The time now is 09:14 PM.

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