Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 09-24-2011, 07:57 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
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

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

Last edited by pig132; 09-24-2011 at 08:07 AM..
Reply With Quote
  #2  
Old 09-24-2011, 10:56 AM
TSAdmin TSAdmin is offline
Forum Moderator
TSAdmin's Avatar
Join Date: Aug 2006
Location: Australia
Posts: 1,980
TSAdmin has much to be proud ofTSAdmin has much to be proud ofTSAdmin has much to be proud ofTSAdmin has much to be proud ofTSAdmin has much to be proud ofTSAdmin has much to be proud of
"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.
__________________
TSAdmin (Forum Moderator)
Welcome to the Official GraalOnline Forums! Where sharing an opinion may be seen as a declaration of war!
------------------------
· User Agreement · Code of Conduct · Forum Rules ·
· Graal Support · Administrative Contacts ·
Reply With Quote
  #3  
Old 09-24-2011, 12:37 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
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.
Reply With Quote
  #4  
Old 09-24-2011, 09:24 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
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);
  }

__________________
Quote:
Reply With Quote
  #5  
Old 09-25-2011, 05:11 AM
pig132 pig132 is offline
professional troll
Join Date: May 2006
Posts: 260
pig132 will become famous soon enough
Thank you for the advice guys
Reply With Quote
  #6  
Old 09-25-2011, 05:16 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
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.
__________________
Quote:
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 10:18 AM.


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