PDA

View Full Version : Script Help.


Kirko
02-28-2015, 03:54 PM
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".

function ContinueToRemove(member, guild){
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.test, temp.guild
);
//temp.req = requestSQL(temp.remove, false);

for(temp.i=0; temp.i < 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=0; temp.n < 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:


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.
// 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

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

temp.npcs = findareanpcs(temp.startx,temp.starty,1,1);
for (temp.npc: temp.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.

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(obj, plyr, time){
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)) {
x = screenwidth / 2;
y = 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][2] SPC 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
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
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
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.