Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Script Help. (https://forums.graalonline.com/forums/showthread.php?t=134269888)

Kirko 02-28-2015 03:54 PM

Script Help.
 
Why doesn't this script remove the player from the array? What I'm trying to do is get the list of members in a guild then remove the player that is said. Everything works but the removing of the player. The player I'm trying to remove is "Test".

PHP Code:

function ContinueToRemove(memberguild){
  
temp.test NULL;
  
/*temp.remove = format(
    "UPDATE Guilds" NL
    " SET Members = REPLACE(Members, '%s', NULL)" NL
    "  WHERE Name = '%s'",
    temp.member, temp.guild
  );*/

  
temp.remove format(
    
"UPDATE Guilds" NL
    
" SET Members = '%s'" NL
    
"  WHERE Name = '%s'",
    
temp.testtemp.guild
  
);
  
//temp.req = requestSQL(temp.remove, false);
  
  
for(temp.i=0temp.GetMembers(temp.guild).size(); temp.i++){
    
temp.test.add(GetMembers(temp.guild)[i]);
    echo(
"Created Array" SPC temp.i SPC ":" SPC temp.test);
  }
  for(
temp.n=0temp.temp.test.size(); temp.n++){
    if(
temp.test[n] == temp.member){
      echo(
"Remove:" SPC temp.test[n]);
      echo(
"From:" SPC temp.test);
      echo(
"New Array:" SPC temp.test.delete(n));//isnt working
    
}
  }
  echo(
"------------------------------");


I also tried doing remove instead of delete and still didn't work

this is what echos into rc.
[12:39] ------------------------------
[12:39] Updated Array: Graal1341684,
[12:39] Updated Array: Graal1341684,Holder
[12:39] Updated Array: Graal1341684,Holder,Test
[12:39] Updated Array: Graal1341684,Holder,Test,Holder2
[12:39] Remove: Test
[12:39] From: Graal1341684,Holder,Test,Holder2
[12:39] New Array: 0
[12:39] ------------------------------

cbk1994 02-28-2015 05:21 PM

array.delete mutates the array, it doesn't return a new one. So:

PHP Code:

      echo("Remove:" SPC temp.test[n]); 
      echo(
"From:" SPC temp.test);
      
temp.test.delete(n);
      echo(
"New Array:" SPC temp.test); 

will probably work. You might also find array.remove(element) useful, which removes the first instance of an element in an array (meaning you don't have to iterate to find the index).

edit: on a related note, beware SQL injection in that query if you're not already escaping those values.

Kirko 02-28-2015 05:35 PM

Thanks, it worked! :)

Kirko 03-05-2015 09:18 PM

What am I doing wrong in this script? I can't get it to do a triggerserver in it so I can destroy once player gets it.

This is the class im using and also the weapon.
PHP Code:

// Created by *Kirko (Graal1341684)
function onCreated() {
  
showcharacter();
  
this.head "head0.png";
  
this.body "body.png";
  
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;
  
this.ani "idle";
}

function 
onActionServerSide(){
  switch(
params[0]){
    case 
"picked":
      
this.chat "got picked up";
      break;
  }
}

//#CLIENTSIDE
function onCreated(){
  
dontblock();
  
drawunderplayer();
  
this.zoom .5;
  
this.noobnpc 1;
}

public function 
GetPickedUp(){
  
triggerserver("weapon"this.name"picked");
}

public function 
test(){
  
this.chat "im it";
  
sleep(2);
  
this.chat "";
  
//this.destroy();


below is part of the weapon
PHP Code:

function findnpcs(){
  
temp.startx player.1.0 vecx(player.dir) * 2;
  
temp.starty player.1.0 vecy(player.dir) * 2;

  
temp.npcs findareanpcs(temp.startx,temp.starty,1,1);
  for (
temp.npctemp.npcs){
    if(
temp.npc.noobnpc == 1){
      
player.chat "I found npc..";
      
//temp.npc.chat = "hello";
      
temp.npc.test();
      
temp.npc.GetPickedUp();
    }
  }


the temp.npc.test(); works fine but not temp.npc.GetPickedUp();

cbk1994 03-07-2015 05:09 AM

That doesn't look like a weapon to me? You can't trigger it like a weapon if it's an NPC.

For level NPCs, you have two options: try to trigger at its coordinates (x/y), which imo is almost always a bad idea (things can block the trigger, you need to be careful with the shape, it really shouldn't move, etc.); or, trigger something else (a DB NPC or weapon, for example), and have it handle the action.

In your case you might just want to move the check serverside, but not really sure what you're trying to accomplish.

Kirko 03-08-2015 05:35 PM

I was trying to make something like a trash picker but where I picked up mini noob npcs. I did get it to work but I had to completely rewrite the script and make it server side.

Kirko 03-20-2015 04:29 PM

Can someone tell me what I'm doing wrong here? I'm making a showlag command that shows the lag and says if its low, moderate, high etc. Later on I'm planning on changing the color of text so if its high the text is red and low is green. Anyways here is the script.

PHP Code:

findplayer("Graal1341684").addweapon(name);

function 
onActionServerSide(){
  switch(
params[0]){
    case
"GetMyPing":
      
GetPing();
      break;

    default:
      
printf("%s: Error",name);
  }
}

function 
GetPing(){
  
temp.obj player.sendping();
  
this.catchevent(obj"onReceivePing""onGPingReply");
}

function 
onGPingReply(objplyrtime){
  
time int(time 1000);
  
plyr.triggerClient("gui"name"GivePing"time);
}


//#CLIENTSIDE
function onCreated(){
  
this.Types = {
    {
0,49,"Very Low"},
    {
50,199,"Low"},
    {
200,399,"Moderate"},
    {
400,600,"High"},
    {
601,9999,"Very High"}
  };
}

function 
onPlayerChats(){
  if(
player.chat == "/showlag"){
    
triggerserver("gui"name"GetMyPing");
    
player.chat "";
  }
}

function 
onActionClientside(){
  switch(
params[0]){
    case
"GivePing":
      
ShowLag(params[1]);
      break;
  }
}

function 
ShowLag(time){
    
with(findimg(200)) {
      
screenwidth 2;
      
screenheight 50;
      
text GetType(time);//always says 0
      
font "Arial";
      
style "bc";
      
zoom 1.2;
      
layer 4;

      
textshadow true;
      
shadowcolor "0 0 0";
      
shadowoffset "2 2";
    }
}

function 
GetType(time){
  
//time = 200;
  
echo("Getting type" SPC time);

  for(
temp.i=0;temp.i<5;temp.i++){
    if(
time >= this.Types[i][0] && time <= this.Types[i][1]){
      
//player.chat = format("your lag is %s",this.Stuff[i][2]);
      
echo(temp.i SPC this.Types[1][2SPC this.Types.size());//doesnt echo
      //i did get it to echo once but all it said was "0 0 0"
      
return "your lag is "@this.Types[i][2];
    }
  }



cbk1994 03-21-2015 06:23 PM

Quote:

Originally Posted by Kirko (Post 1735526)
Can someone tell me what I'm doing wrong here? I'm making a showlag command that shows the lag and says if its low, moderate, high etc. Later on I'm planning on changing the color of text so if its high the text is red and low is green. Anyways here is the script.

What problems are you having with it?

Kirko 03-24-2015 10:39 PM

Quote:

Originally Posted by cbk1994 (Post 1735533)
What problems are you having with it?

I just figured what I was doing wrong but thanks.

It was such a simple mistake that took me 2 days to find. :mad:

MysticalDragon 03-28-2015 10:31 PM

Quote:

Originally Posted by Kirko (Post 1735549)
I just figured what I was doing wrong but thanks.

It was such a simple mistake that took me 2 days to find. :mad:

echo(temp.i SPC this.Types[1][2] SPC this.Types.size());//doesnt echo

i see an one instead of a i :p (unless that was on purpose to see what it was going to echo), I hate when i do typos like that.


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

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