Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-28-2015, 03:54 PM
Kirko Kirko is offline
Registered Guest
Join Date: Dec 2014
Location: Texas
Posts: 61
Kirko has a spectacular aura aboutKirko has a spectacular aura about
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] ------------------------------
Reply With Quote
  #2  
Old 02-28-2015, 05:21 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________

Last edited by cbk1994; 02-28-2015 at 09:15 PM..
Reply With Quote
  #3  
Old 02-28-2015, 05:35 PM
Kirko Kirko is offline
Registered Guest
Join Date: Dec 2014
Location: Texas
Posts: 61
Kirko has a spectacular aura aboutKirko has a spectacular aura about
Thanks, it worked!
Reply With Quote
  #4  
Old 03-05-2015, 09:18 PM
Kirko Kirko is offline
Registered Guest
Join Date: Dec 2014
Location: Texas
Posts: 61
Kirko has a spectacular aura aboutKirko has a spectacular aura about
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();
Reply With Quote
  #5  
Old 03-07-2015, 05:09 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
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.
__________________
Reply With Quote
  #6  
Old 03-08-2015, 05:35 PM
Kirko Kirko is offline
Registered Guest
Join Date: Dec 2014
Location: Texas
Posts: 61
Kirko has a spectacular aura aboutKirko has a spectacular aura about
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.
Reply With Quote
  #7  
Old 03-20-2015, 04:29 PM
Kirko Kirko is offline
Registered Guest
Join Date: Dec 2014
Location: Texas
Posts: 61
Kirko has a spectacular aura aboutKirko has a spectacular aura about
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];
    }
  }

Reply With Quote
  #8  
Old 03-21-2015, 06:23 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Kirko View Post
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?
__________________
Reply With Quote
  #9  
Old 03-24-2015, 10:39 PM
Kirko Kirko is offline
Registered Guest
Join Date: Dec 2014
Location: Texas
Posts: 61
Kirko has a spectacular aura aboutKirko has a spectacular aura about
Quote:
Originally Posted by cbk1994 View Post
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.
Reply With Quote
  #10  
Old 03-28-2015, 10:31 PM
MysticalDragon MysticalDragon is offline
Global Administration
MysticalDragon's Avatar
Join Date: Oct 2002
Location: Lynn Ma
Posts: 883
MysticalDragon is just really niceMysticalDragon is just really nice
Send a message via AIM to MysticalDragon Send a message via MSN to MysticalDragon
Quote:
Originally Posted by Kirko View Post
I just figured what I was doing wrong but thanks.

It was such a simple mistake that took me 2 days to find.
echo(temp.i SPC this.Types[1][2] SPC this.Types.size());//doesnt echo

i see an one instead of a i (unless that was on purpose to see what it was going to echo), I hate when i do typos like that.
__________________
~Delteria Support
~Playerworld Support
~PWA Chief
http://support.toonslab.com
[email protected]



Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 09:40 PM.


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