Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Custom Name System (https://forums.graalonline.com/forums/showthread.php?t=134264204)

Gunderak 08-13-2011 05:46 PM

Custom Name System
 
vHere is what have been able to come up with, but im still wondering, is there any way to check if the player is staff and if so make their name gold? iv managed to achieve this clientside but not serverside, meaning it only displays as gold to your self.

PHP Code:

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

function 
onTimeOut() {
  
hideimg(201 a);
  
hideimg(202 a);
  for (
0playerscounta++) {
    
showtext(201 aplayers[a].1.5players[a].3.2"Arial Bold""c", @players[a].nick);
    
changeimgcolors(201 a1111);
    
changeimgvis(201 a1);
    
changeimgzoom(201 a1);
    
showtext(202 aplayers[a].1.5players[a].4.5"Arial Bold""c", @players[a].hearts@"/"@players[a].maxhp);
    
changeimgcolors(202 a10.10.11);
    
changeimgvis(202 a1);
    
changeimgzoom(202 a0.8);
  }
  
setTimer(0.05);



cbk1994 08-13-2011 06:55 PM

Again, you need to work on your styling. In addition, the smallest timeout possible is 0.05 seconds, not 0.001 seconds.

The best way is probably to store some value in a player attribute (the attr array) so that you can check it clientside on other clients.

Gunderak 08-13-2011 07:10 PM

Iv changed to 0.05 il remember that for next time :) and yeah sorry about my styling. i fixed that too. i keep forgetting that it makes it hard to read for others :3
as for storing it in attributes.
not to be too suddle, but how the hell would i do that? would you be ever so kind to link me or show an example?
thanks.

ffcmike 08-13-2011 09:31 PM

Quote:

Originally Posted by Gunderak (Post 1663393)
vHere is what have been able to come up with, but im still wondering, is there any way to check if the player is staff and if so make their name gold? iv managed to achieve this clientside but not serverside, meaning it only displays as gold to your self.

PHP Code:

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

function 
onTimeOut() {
  
hideimg(201 a);
  
hideimg(202 a);
  for (
0playerscounta++) {
    
showtext(201 aplayers[a].1.5players[a].3.2"Arial Bold""c", @players[a].nick);
    
changeimgcolors(201 a1111);
    
changeimgvis(201 a1);
    
changeimgzoom(201 a1);
    
showtext(202 aplayers[a].1.5players[a].4.5"Arial Bold""c", @players[a].hearts@"/"@players[a].maxhp);
    
changeimgcolors(202 a10.10.11);
    
changeimgvis(202 a1);
    
changeimgzoom(202 a0.8);
  }
  
setTimer(0.05);



There's a couple of things within this script which don't really make sense, and suggest that you are still piecing things together without really understanding how they work.

First of all you do not need to use "@" to use a single variable such as how you do with "@players[a].nick", this is the type of thing you'd want to do in order to create an object from a dynamic string value, for instance:

PHP Code:

function onPlayerChats(){
  
temp.tokens player.chat.tokenize();
  
//lets say the players chat was "/dofunction heal somenoob 2"
  
if(temp.tokens[0] == "/dofunction"){
    
//temp.tokens[1] would be the function name it invokes, temp.tokens[2] + [3] would be the parameters passed
    
this.(@ temp.tokens[1])(temp.tokens[2], temp.tokens[3]);
  }
}

function 
heal(temp.pltemp.amount){
  
//stuff that heals the player supplied by the first parameter by the amount supplied in the second parameter



The 2nd parameter also does not require the first "@", it can be "players[a].hearts @ "/" @ players[a].maxhp", for the sake of read-ability it would also be better to space those separate values out.

Something more important is that when using indexes of 201 + a, and 202 + 1 and incrementing a by 1, the 2nd part of the loop will be over-writing one of the displays from the first part of the loop and so on.
For this you should be incrementing a by 2, this would do 201 and 202 for the first part of the loop, then 203 and 204 for the second part.

Having said that, it would be much better to simply do:

PHP Code:

for(temp.pl players){
  
this.showtext(200 this.itemp.pl.xtemp.pl.ystuff);
  
this.++;
  
this.showtext(200 this.itemp.pl.xtemp.pl.ystuff);
  
this.++;


Your hideimg functions are only hiding the first 2 display objects and would be ignoring any players beyond yourself.
If you keep track of the amount of displays created, you can do something simple such as :

PHP Code:

this.hideimgs(200200 this.i); 

Even then looping through all players and creating a new display every frame is a very inefficient method which consumes script time, I personally think it's better to just stick to default nicks unless you're knowledgeable enough to create an efficient system, such as storing the display objects and then simply modifying them in future frames.

I'm not 100% sure but I think the playerscount variable is a now deprecated relic of old GS1, you may for example have to use temp.s = players.size(); and refer to temp.s within the loop.

Gunderak 08-15-2011 07:07 AM

wow thats alot to chew.
yes i am still piecing together things on this script.
i would like to also learn about paramaters.
like for example if i had a triggerserver then at the end after it had the server param to trigger i did , player.whatever) iv noticed some scripts have this and then at the top it reads that param but im still confused on how that works.
thanks very much for your time and effort i really do want to learn GS2.
i think il abandon the custom name system.
what does the players[a].health does that mean all players? and why is it players and not player? that confuses me too :$
if you want to see what iv done so far have a look at dev draze.
anyway thanks for your help thor, il be sure to keep your afvice in mind :)
i think im trying to make things out of my abilities again :3

Gunderak 08-15-2011 07:09 AM

also sorry il have to rep you when i get home, my iDevice doesnt seem capable of it.

cbk1994 08-15-2011 12:59 PM

How do you type that poorly on an iDevice? Doesn't it capitalize stuff for you...?

callimuc 08-15-2011 06:09 PM

Quote:

Originally Posted by cbk1994 (Post 1663647)
How do you type that poorly on an iDevice? Doesn't it capitalize stuff for you...?

Just if you have the autocorrection turned on

Gunderak 08-19-2011 02:34 AM

Beaides the fact autocorrect is off, im also typing while im at work and doing other things.
So sorry youl have to excuse my poor grammar.

Bubble13 08-19-2011 02:54 AM

Quote:

Originally Posted by Gunderak (Post 1664251)
Beaides the fact autocorrect is off, im also typing while im at work and doing other things.
So sorry youl have to excuse my poor grammar.

Maybe you should stop what you're doing and just focus on typing. It would make it easier for everyone.


All times are GMT +2. The time now is 10:44 PM.

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