Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   for allplayers (https://forums.graalonline.com/forums/showthread.php?t=134264622)

pig132 09-24-2011 07:57 AM

for allplayers
 
Alright, so I have made a little mass message GUI and I have a quick question.

Since it is being sent to everyone, does "for (temp.pl: allplayers)" get all of the players on the server or just local players in the same level?

Also, here is the code im using. How can I improve it?

Thanks :D

PHP Code:

function onActionServerSide() {
  switch (
params[0]) {
    case 
"send":
      for (
temp.plallplayers) {
        
findplayer(temp.pl).sendPM(client.massmessage);
        
player.chat "Successfully sent a mass message to " temp.pl "!";
      }
    break;
  }
}

//#CLIENTSIDE
function onPlayerChats() {
  if (
player.chat.starts("+mass")) {
    
CreateGUI();
  }
}

function 
CreateGUI() {
  new 
GuiWindowCtrl("mass_window") {
    
profile GuiBlueWindowProfile;
    
    
screenwidth 2.5;
    
screenheight 2.5;
    
width 200;
    
height 200;
    
text "Mass Message";
    
    
destroyonhide true;
    
canminimize canresize canmaximize false;
  
  new 
GuiScrollCtrl("mass_scroller") {
    
profile GuiBlueScrollProfile;
    
    
10;
    
30;
    
width 180;
    
height 130;
    
hscrollbar "alwaysOff";
    
vscrollbar "alwaysOff";
    
  new 
GuiMLTextEditCtrl("mass_text") {
    
profile GuiBlueMLTextEditProfile;
    
    
0;
    
0;
    
width 180;
    
height 130;
  }
  }
  
  new 
GuiButtonCtrl("mass_send") {
    
profile GuiBlueButtonProfile;
    
    
75;
    
165;
    
    
width 50;
    
height 25;
    
text "Send";
  }
  }
// main
}

function 
mass_send.onAction() {
  
client.massmessage mass_text.text;
  
triggerserver("gui"this.name"send");
  
mass_text.text "";



Edit:

Also, in this part of the code:
PHP Code:

findplayer(temp.pl).sendPM(client.massmessage); 

How can I add a line break between a specific sting of text and then the actual message?

Thank you

TSAdmin 09-24-2011 10:56 AM

"allplayers" references all the players on a server. "players" references all the players in a level the script is being run from.

I'll leave any code tweaking suggestions to fowlplay4 who will undoubtedly end up reading this thread.

Crow 09-24-2011 12:37 PM

allplayers is full of player objects, not their account names. You're using them like accounts right now though. My suggestions packed into code:

PHP Code:

function onActionServerSide(cmdarg) {
  switch (
cmd) {
    case 
"send":
      for (
temp.plallplayers) {
        if (
pl.level.name == nil)
          continue;

        
pl.sendPM(arg);
      }
    break;
  }


I'm also assuming here that you're sending the message as an argument with the trigger instead of storing it in a client.var. I removed the chat notification because it'd be useless anyway since you'd only see the last one. I also added a check to see if the player level doesn't exist which usually means that the player is an RC instance; stuff gets pretty annoying when all RCs are getting messages constantly.

I didn't touch the clientside part, but word of advice: don't recreate the GUI objects all the time. Create them once and then hide/show them.

fowlplay4 09-24-2011 09:24 PM

Crow's spot on from fixing your existing code.

Using (npcserver) PM's for mass messages suck and if everyone can do it, it'll just become a nuisance to the point people are ignoring the (npcserver).

There might be a function to open a mass message window but this also works:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
openMassPM();
}

function 
openMassPM() {
  if (
graalversion >= 5.324) {
    (@
"-Playerlist_v6").openPMWindow(allplayersfalse);
  } else {
    (@
"-Playerlist").openPMWindow(allplayersfalse);
  }



pig132 09-25-2011 05:11 AM

Thank you for the advice guys :)

fowlplay4 09-25-2011 05:16 AM

It basically means:

1. Create the GUI when the weapon is created.
2. Set the visibility of the GUI to false

Then when you want to display the GUI just call show() or make it visible.

I.e:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  new 
GuiWindowCtrl("Example") {
    
0;
    
width screenwidth;
    
height screenheight;
    
visible false;
  }
  
this.scheduleevent(5"DisplayGUI""");
}

function 
onDisplayGUI() {
  
Example.show(); // Same as: Example.visible = true;


**** this stupid security **** I couldn't even post on time out without it throwing an error.


All times are GMT +2. The time now is 03:02 AM.

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