Graalians

Graalians (https://www.graalians.com/forums/index.php)
-   GraalOnline Era (https://www.graalians.com/forums/forumdisplay.php?f=13)
-   -   Small Script Help! Can't get Statue working (https://www.graalians.com/forums/showthread.php?t=7791)

Johnaudi 06-23-2012 04:42 PM

Small Script Help! Can't get Statue working
 
Hey,
bin trying to script for the past days, my gold gonna expire in 1 day so i gotta find a quick way to fix it up... so what shall I do? It used to work but I messed and added the /reset command, not working anymore :/ Thanks
Quote:

// Created by Graal804226
function onMouseDown(mode) {
if (mode == "left") {
Temp.pl = findnearestplayer(mousex, mousey);
Player.chat = format("%s was clicked", temp.pl.communityname);

this.head=player.head;
this.chat=player.chat;
this.body=player.body;
this.nick=player.nick;
this.ap=player.ap;
setcharprop #P1,#P1;
this.ani = player.ani;
this.dir = player.dir;
}
}
if (created) {
showcharacter();
this.head = "head0.png";
this.nick = "Statue";
this.colors[0] = "orange";
this.colors[1] = "white";
this.colors[2] = "blue";
this.colors[3] = "red";
this.colors[4] = "black";
this.shield = "no-shield.png";
this.dir = 2;
setcharani("idle",NULL);
message click on me!;
function onPlayerChats() {
if (player.chat == "/reset") {
this.chat ="reset";
}
if (player.chat !="/reset"){
return;
}
}
}
also somehow, function onCreate() doesn't work here...

DanTheMan 06-23-2012 05:03 PM

- Didn't even use 'temp.pl' in defining the NPC's looks (example: temp.pl.head)
- Mixing GS1 and GS2
- Nesting another function inside of 'onCreated' for no apparent reason
- What exactly are you trying to do?

Johnaudi 06-23-2012 05:06 PM

Quote:

Posted by DanTheMan (Post 146887)
- Didn't even use 'temp.pl' in defining the NPC's looks (example: temp.pl.head)
- Mixing GS1 and GS2
- Nesting another function inside of 'onCreated' for no apparent reason
- What exactly are you trying to do?

Oh thanks about the temp.pl =] completely forgot it...
-I get that alot
-I'll try
-making it once clicked, the attributes will load as the player's

Emera 06-23-2012 05:14 PM

Are you using this online or offline? If you're using it online I'll help you with a GS2 version.

Johnaudi 06-23-2012 05:15 PM

Quote:

Posted by Emera (Post 146889)
Are you using this online or offline? If you're using it online I'll help you with a GS2 version.

Online =] yeah sorry for the gs1

Emera 06-23-2012 05:26 PM

PHP Code:

function onCreated() {
  
//Makes sure it's a character NPC
  
showCharacter();
  
  
//Set look before it clones a player
  
this.head "head.png";
  
this.body "body.png";
  
this.nick "unknown";
  
this.dir 2;
}

function 
onMouseDown(mode) {
  
//Only sets if the left mouse button is pressed
  
if (mode != "left") return;
  
  
//Check if the mouse is over the NPC
  
if (mousex in this.xthis.1.5 | && mousey in this.ythis.|) {
    
//Copy the player's features to the NPC
    
this.head player.head;
    
this.body player.body;
    
this.shield player.shield;
    
this.colors[0] = player.colors[0];
    
this.colors[1] = player.colors[1];
    
this.colors[2] = player.colors[2];
    
this.colors[3] = player.colors[3];
    
this.colors[4] = player.colors[4];
    
this.attr[1] = player.attr[1]
    
this.nick player.nick;
    
this.ap player.ap;
  }


That should work. I've commented parts of the code to help you understand it.

callimuc 06-23-2012 05:28 PM

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
showcharacter();
  
this.head "head0.png";
  
this.body "body.png";
  
this.nick "Statue";
  
this.colors[0] = "orange";
  
this.colors[1] = "white";
  
this.colors[2] = "blue";
  
this.colors[3] = "red";
  
this.colors[4] = "black";
  
this.shield "no-shield.png";
  
this.dir 2;
  
setcharani("idle",NULL);
  
this.attr[1] = "";
  
this.chat "Click me!";
}

function 
onMouseDown(mode) {
  if (
mode != "left") return;
  
temp.pl findnearestplayer(mousexmousey);
  
player.chat format("%s was the nearest target"temp.pl.communityname);

  
this.head player.head;
  
this.chat player.chat;
  
this.body player.body;
  
this.nick player.nick;
  
this.ap player.ap;
  
this.attr[1] = player.attr[1//hat
  
this.ani player.ani;
  
this.dir player.dir;
}
function 
onPlayerChats() {
  if (
player.chat == "/reset"this.chat "reset";


Keep in mind, this will reset whenever the level is updated. To prevent that you could do something like this (very simple and just viewable for you);

PHP Code:

//#CLIENTSIDE
function onPlayerEnters() {
  
showcharacter();
  if (
client.statue_first == NULL) {
    
this.head "head0.png";
    
this.body "body.png";
    
this.nick "Statue";
    
this.colors[0] = "orange";
    
this.colors[1] = "white";
    
this.colors[2] = "blue";
    
this.colors[3] = "red";
    
this.colors[4] = "black";
    
this.shield "no-shield.png";
    
this.dir 2;
    
setcharani("idle",NULL);
    
this.attr[1] = "";
    
this.chat "Click me!";
  }
  else {
    
this.head client.statue_first[0];
    
this.body client.statue_first[1];
    
this.nick client.statue_first[2];
    
this.colors[0] = client.statue_first[3][0];
    
this.colors[1] = client.statue_first[3][1];
    
this.colors[2] = client.statue_first[3][2];
    
this.colors[3] = client.statue_first[3][3];
    
this.colors[4] = client.statue_first[3][4];
    
this.shield client.statue_first[4];
    
this.dir client.statue_first[5];
    
setcharani(client.statue_first[6], NULL);
    
this.attr[1] = client.statue_first[7];
  }
}

function 
onMouseDown(mode) {
  if (
mode != "left") return;
  
client.statue_first = {
    
player.head//head
    
player.body//body
    
player.nick//nickname
    
{player.colors[0], player.colors[1], player.colors[2], player.colors[3], player.colors[4]}, //colors
    
player.shield//shield
    
player.dir//direction
    
player.ani//gani
    
player.attr[1//hat
  
};
  
onPlayerEnters();
}

function 
onPlayerChats() {
  if (
player.chat != "reset") return;
  
this.chat "reset";
  
client.statue_first NULL;
  
onPlayerEnters();
  
setTimer(2);
}

function 
onTimeOut() {
  
this.chat "";


Wasnt sure if you want to have your look setted or the other players look. If you want the other players look setted, you could do something like this for the onActionMouseDown()

PHP Code:

function onMouseDown(mode) {
  if (
mode != "left") return;
  
temp.pl findNearestPlayer(mousexmousey);
  if (
mousex in |temp.pl.xtemp.pl.x+3| && mousey in |temp.pl.ytemp.pl.y+3|) {
    
client.statue_first = {
      
temp.pl.head//head
      
temp.pl.body//body
      
temp.pl.nick//nickname
      
{temp.pl.colors[0], temp.pl.colors[1], temp.pl.colors[2], temp.pl.colors[3], temp.pl.colors[4]}, //colors
      
temp.pl.shield//shield
      
temp.pl.dir//direction
      
temp.pl.ani//gani
      
temp.pl.attr[1//hat
    
};
    
onPlayerEnters();
  }




Yah no clue what I wrote there so ask me if you didnt understand something


Damn Emera was faster but anyway it might help

Emera 06-23-2012 05:30 PM

Wouldn't you want to be saving them in serverr. variables instead of client variables so they don't change for each player?

callimuc 06-23-2012 05:34 PM

Quote:

Posted by Emera (Post 146896)
Wouldn't you want to be saving them in serverr. variables instead of client variables so they don't change for each player?

Depending on if the statue should be shown clientside or not. Yah maybe the serverr.flags if everyone should see it.

EDIT for John:
To have it viewable for everyone you could simply change the client.statue_first to server.statue_first. That should work aswell and would be viewable for everyone. But probably I'd change it to something serverside than and use serverr.flags since they are more secure and not changeable with memory editors.

Johnaudi 06-23-2012 06:05 PM

Quote:

Posted by callimuc (Post 146895)
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
showcharacter();
  
this.head "head0.png";
  
this.body "body.png";
  
this.nick "Statue";
  
this.colors[0] = "orange";
  
this.colors[1] = "white";
  
this.colors[2] = "blue";
  
this.colors[3] = "red";
  
this.colors[4] = "black";
  
this.shield "no-shield.png";
  
this.dir 2;
  
setcharani("idle",NULL);
  
this.attr[1] = "";
  
this.chat "Click me!";
}

function 
onMouseDown(mode) {
  if (
mode != "left") return;
  
temp.pl findnearestplayer(mousexmousey);
  
player.chat format("%s was the nearest target"temp.pl.communityname);

  
this.head player.head;
  
this.chat player.chat;
  
this.body player.body;
  
this.nick player.nick;
  
this.ap player.ap;
  
this.attr[1] = player.attr[1//hat
  
this.ani player.ani;
  
this.dir player.dir;
}
function 
onPlayerChats() {
  if (
player.chat == "/reset"this.chat "reset";


Keep in mind, this will reset whenever the level is updated. To prevent that you could do something like this (very simple and just viewable for you);

PHP Code:

//#CLIENTSIDE
function onPlayerEnters() {
  
showcharacter();
  if (
client.statue_first == NULL) {
    
this.head "head0.png";
    
this.body "body.png";
    
this.nick "Statue";
    
this.colors[0] = "orange";
    
this.colors[1] = "white";
    
this.colors[2] = "blue";
    
this.colors[3] = "red";
    
this.colors[4] = "black";
    
this.shield "no-shield.png";
    
this.dir 2;
    
setcharani("idle",NULL);
    
this.attr[1] = "";
    
this.chat "Click me!";
  }
  else {
    
this.head client.statue_first[0];
    
this.body client.statue_first[1];
    
this.nick client.statue_first[2];
    
this.colors[0] = client.statue_first[3][0];
    
this.colors[1] = client.statue_first[3][1];
    
this.colors[2] = client.statue_first[3][2];
    
this.colors[3] = client.statue_first[3][3];
    
this.colors[4] = client.statue_first[3][4];
    
this.shield client.statue_first[4];
    
this.dir client.statue_first[5];
    
setcharani(client.statue_first[6], NULL);
    
this.attr[1] = client.statue_first[7];
  }
}

function 
onMouseDown(mode) {
  if (
mode != "left") return;
  
client.statue_first = {
    
player.head//head
    
player.body//body
    
player.nick//nickname
    
{player.colors[0], player.colors[1], player.colors[2], player.colors[3], player.colors[4]}, //colors
    
player.shield//shield
    
player.dir//direction
    
player.ani//gani
    
player.attr[1//hat
  
};
  
onPlayerEnters();
}

function 
onPlayerChats() {
  if (
player.chat != "reset") return;
  
this.chat "reset";
  
client.statue_first NULL;
  
onPlayerEnters();
  
setTimer(2);
}

function 
onTimeOut() {
  
this.chat "";


Wasnt sure if you want to have your look setted or the other players look. If you want the other players look setted, you could do something like this for the onActionMouseDown()

PHP Code:

function onMouseDown(mode) {
  if (
mode != "left") return;
  
temp.pl findNearestPlayer(mousexmousey);
  if (
mousex in |temp.pl.xtemp.pl.x+3| && mousey in |temp.pl.ytemp.pl.y+3|) {
    
client.statue_first = {
      
temp.pl.head//head
      
temp.pl.body//body
      
temp.pl.nick//nickname
      
{temp.pl.colors[0], temp.pl.colors[1], temp.pl.colors[2], temp.pl.colors[3], temp.pl.colors[4]}, //colors
      
temp.pl.shield//shield
      
temp.pl.dir//direction
      
temp.pl.ani//gani
      
temp.pl.attr[1//hat
    
};
    
onPlayerEnters();
  }




Yah no clue what I wrote there so ask me if you didnt understand something


Damn Emera was faster but anyway it might help

This works, but once level updated it changes...

Edit : oh nvm got it fixed!

Twinny 06-26-2012 01:21 AM

If you save statue settings to serverr flags, Skyld will cleanse your server with flame. Server flags are not appropriate for statues at all... What if 1000 statues were added? >: (

If statues absolutely NEED to keep their outfit even when the level is updated/server is restarted, use files.

e.g.

this.statuename = "myhouse_statue1" and then when the outfit is set serverside, save all the variables into a file e.g. statues/myhouse_states1.txt

In the oncreated event, check if the file exists and if it does, load the values from it. Keep it all serverside and then the server won't have to sync Statue outfits for statues in every single damn level with the player :)

Higbey 06-26-2012 05:25 AM

Quote:

Posted by Twinny
If you save statue settings to serverr flags, Skyld will cleanse your server with flame. Server flags are not appropriate for statues at all... What if 1000 statues were added? >: (

Skyld: he kills it with fire.

Johnaudi 06-26-2012 10:11 AM

Since its a scripting thread, I need help with the variable commands, for example the ec system, I wanted to make it add on each time I want.
Quote:

function onCreate() {
this.level.ecteller = this;
}
function onPlayerTouchsMe() {
if (player.account =="Graal804226") {
this.ec=10;
this.chat ="You have"SPC this.ec SPC"EC's";
}
}
function onTest() {
this.ec +=1;
}
I added this on another NPC :
Quote:

function onPlayerChats() {
if (player.chat=="addec") {
this.level.ecteller.trigger("Test","");
}
}
Thanks...

Twinny 06-26-2012 11:00 PM

Quote:

Posted by Johnaudi (Post 148574)
Since its a scripting thread, I need help with the variable commands, for example the ec system, I wanted to make it add on each time I want.

I added this on another NPC :

Thanks...

I will say straight off the bat that you need onCreated and not onCreate. I also don't see why you are using level references and seperate NPCs for that.

But, you should take it to the OGCC and not here at this point.

Emera 06-30-2012 07:44 PM

Quote:

Posted by Johnaudi (Post 148574)
Since its a scripting thread, I need help with the variable commands, for example the ec system, I wanted to make it add on each time I want.

I added this on another NPC :

Thanks...

Are you trying to give players EC? You'll find it won't work if you're giving NPCs the EC using this.ec instead of player.clientr.ec. This is because this. refers to the NPC, and player.clientr. refers to the player's clientr flags. Save the EC to the player's flags to give the player EC.

PHP Code:

player.clientr.ec ++;
//OR
player.clientr.ec += 10

Just a note, clientr flags can only be changed on the serverside, but can be read from both the clientside and the serverside, so you'll have to add the EC on the serverside. Also, use php tags to show coding instead of quotes ;)

I doubt you'll be able to understand how to load/save from text files this early on in learning GS2, so here's an example of how to save and load your NPC's configuration to/from a text file. Firstly, you'll have to give your NPC-Server the following right.

HTML Code:

rw objects/statues/*.txt
After that, simply add this code to a class and join it to the NPC you wish to make a statue. After that, simply call the loadStatueConfig(); function to load the statue and the saveStatueConfig(); function to save the statue.

PHP Code:

function onCreated() {
  
showCharacter();
  
loadStatueConfig();
}

function 
loadStatueConfig() {
  
this.loadfrom "objects/statues/statue_" this.id ".txt";
  
temp.config.loadlines(this.loadfrom); 
  
  for (
lines temp.config) {
    
this.head lines[0];
    
this.body lines[1];
    
this.shield lines[2];
    
this.sword lines[3];
    
this.colors[0] = lines[4];
    
this.colors[1] = lines[5];
    
this.colors[2] = lines[6];
    
this.colors[3] = lines[7];
    
this.colors[4] = lines[8];
  }
}

function 
saveStatueConfig() {
  
this.saveto "objects/statues/statue_" this.id ".txt";
  
temp.config = {
    
this.head,
    
this.body,
    
this.shield,
    
this.sword,
    
this.colors[0],
    
this.colors[1],
    
this.colors[2],
    
this.colors[3],
    
this.colors[4]
  };
  
  
temp.config.savelines(this.savetofalse);


I hope that helped!


All times are GMT. The time now is 01:34 PM.

Powered by vBulletin/Copyright ©2000 - 2025, vBulletin Solutions Inc.