Graal Forums

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

GregoryYoshi 02-07-2002 02:40 AM

Dilema...
 
I seem to be having a problem with my mineral mining scripts.

The NPC weapon is fine for the most part...it retrieves the player's ID and then sends it through triggeraction.

NPC Code:
//#CLIENTSIDE
// NPC made by GregoryYoshi
if (playerenters) {
setshape 1,32,32;
this.axepower = 2;
setcharprop #c,Level 1 Pickaxe;
}
if (playertouchsme) {
toweapons Pickaxe L1;
hide;
sleep 3;
show;
}

if (weaponfired) {
this.axepower = 2;
this.playerid = playerid;
freezeplayer .75;
setani jaxe,pickaxemetal.png;
triggeraction playerx+1.5+vecx(playerdir)*2,playery+1.75+vecy(pl ayerdir)*2,mining,#v(this.axepower),#v(this.player id);
showimg 210,dk_hitpointer.png,playerx+1.5+vecx(playerdir)* 2,playery+1.75+vecy(playerdir)*2;
sleep .75;
setani idle,;
hideimg 210;
}



The problem is the mineral NPC (which is a class NPC script) is not accepting the playerid parameter sent through triggeraction

NPC Code:
if (created) {
setshape 1,32,32;
this.mined = 0;
}

if (actionmining && !this.mined==100) {
this.mined = this.mined + strtofloat(#p(0));
this.hitterid = strtofloat(#p(2));
gethitter();
setcharprop #c,#v(this.mined) | #v(this.hitter);
} else
if (actionmining && this.mined==100) {
this.hitterid = strtofloat(#p(1));
gethitter();
setimg explosion.gif;
play2 bomb.wav,x-1,y-1,1;
if (hitter>0) {
with (players[hitter]) {
freezeplayer 1;
setani dk_mined,this.type*10;
if (this.type==4) {
setstring uncraftedgold,#v(strtofloat(#s(uncraftedgold))+1);
} else if (this.type==3) {
setstring uncraftedred,#v(strtofloat(#s(uncraftedred))+1);
} else if (this.type==2) {
setstring uncraftedblue,#v(strtofloat(#s(uncraftedblue))+1);
} else if (this.type==1) {
setstring uncraftedgreen,#v(strtofloat(#s(uncraftedgreen))+1 );
}
}
}
hide;
sleep 5;
this.type = int(random(1,5);
this.mined = 0;
show;
}

function gethitter() {
hitter = -1;
for (i=0; i<playerscount; i++)
if (players[i].id==this.hitterid) {
hitter = i;
break;
}
}



Neither of these are confidentail scripts, so I don't mind showing them :D

There's probably something wrong that I'm doing...hopefully I can get this fixed fast :)

TDO2000 02-07-2002 03:06 AM

this.hitterid = strtofloat(#p(2));

u had this line in it and there is NO #p(2) it's #p(1) like u used it later if I am not totaly wrong ^_^

TDK_RC6 02-07-2002 04:29 AM

you would be correct

GregoryYoshi 02-07-2002 11:10 AM

Quote:

Originally posted by TDO2000
this.hitterid = strtofloat(#p(2));

u had this line in it and there is NO #p(2) it's #p(1) like u used it later if I am not totaly wrong ^_^

triggeraction can send more than one parameter :p

#p(index) gets the parameters from the specified index in triggeraction.

The reason I had it #p(2) was because I was testing other indexes...even #p(1) returned a value of 0.

GregoryYoshi 02-07-2002 11:23 AM

hmm...I take back what I said about it not returning a value for
#p(1). However, it still fails to identify the player's ID for later parts of the script.

I suppose it'll work fine if I use this.hitterid instead of hitter since the gethitter function does not seem to work like it should :/

GregoryYoshi 02-07-2002 01:35 PM

Quote:

Originally posted by Kaimetsu
I'm gonna stop looking at scripts that contain all the irrelevant stuff in them. If you wanna post here asking about a problem then remove all the stuff that doesn't affect the problem, otherwise I have to trawl through it all looking for the parts that matter.
Sorry :/ All I asked for was some assitstance...that is the service you provide here, correct ;)

GregoryYoshi 02-07-2002 01:56 PM

Quote:

Originally posted by Kaimetsu


My job here is to moderate the forums, not provide unconditional help, just like it's not your job to interject into every debate in the NGR forum. And if you want my help, which I'm happy to give, then please do a little work yourself beforehand.


Hmm, would the fact that've spent nearly half an hour trying to get it to work right, count? The NPC weapon works fine, just that the class script does not...but as I said, I could probably do without that function...just there will be less security.

GregoryYoshi 02-07-2002 02:04 PM

Quote:

Originally posted by Kaimetsu


No, my point is that you should take out all the stuff that doesn't affect the problem and post a basic script with the basic fundamentals of the problem so that I don't need to look though the frosting on the cake just to get to the thing I need to fix.

thing is, I don't know what exactly the problem is :p

GregoryYoshi 02-07-2002 02:10 PM

Quote:

Originally posted by Kaimetsu


If I was working on my 3D thing and found that there was a problem with the transformation matrix, would I post the whole script and just say "Fix it"? No, I would take out the relevant parts and post those. If you can't identify what the relevant part is then you need to spend longer than half an hour.

Sorry...I figured if I posted the whole script it would help.

All I know is that:
NPC Code:
function gethitter() {
hitter = -1;
for (i=0; i<playerscount; i++)
if (players[i].id==this.hitterid) {
hitter = i;
break;
}
}


is not working for whatever reason :p

GregoryYoshi 02-07-2002 02:15 PM

Quote:

Originally posted by Kaimetsu


Have you tried making it output the result via some sort of message statement or something? Just to check what it's throwing up.

Yep, I do that often when I want the value of anything I'm working on :)

I've made it check i...returns 0
I've made it check hitter...returns 0

The only value that returns correctly is this.hitterid

GregoryYoshi 02-07-2002 02:35 PM

Quote:

Originally posted by Kaimetsu


Wait a second... That loop looks mighty strange.

NPC Code:
function gethitter() {
hitter = -1;
for (i=0; i<playerscount; i++)
if (players[i].id==this.hitterid) {
hitter = i;
break;
}
}



Look at the brackets. If I were you, I'd try it like this:

NPC Code:
function gethitter() {
hitter = -1;
for (i=0; i<playerscount; i++){
if (players[i].id==this.hitterid) {
hitter = i;
break;
}
}
}


Sometimes I hate myself :( Figures I'd miss a bracket :rolleyes:

GregoryYoshi 02-07-2002 02:41 PM

Quote:

Originally posted by Kaimetsu


Does it work now?

unfortunately, no :(

It still does not properly save the player's ID to the variable hitter.

Frolic_RC2 02-07-2002 02:44 PM

G Yoshi, simply use the actionplayer variable.

GregoryYoshi 02-07-2002 02:45 PM

If you like, you can log onto my PW and I'll warp you to the Mineral Mines so you can see it.

Frolic_RC2 02-07-2002 02:50 PM

Quote:

Originally posted by GregoryYoshi
If you like, you can log onto my PW and I'll warp you to the Mineral Mines so you can see it.
Eh? Its 11:45, I am going to go to sleep soon (need to wake up at 5:00 X_X). If that was to Kaimetsu, then nevermind.

GregoryYoshi 02-07-2002 03:02 PM

Quote:

Originally posted by Frolic_RC2
G Yoshi, simply use the actionplayer variable.
eh? *confused*

Something new to learn :D

TDO2000 02-07-2002 09:41 PM

Quote:

Originally posted by GregoryYoshi


triggeraction can send more than one parameter :p

#p(index) gets the parameters from the specified index in triggeraction.

The reason I had it #p(2) was because I was testing other indexes...even #p(1) returned a value of 0.

I know that u can use more then only one param but I thought in that case #p(2) would be wrong....
and u missed a bracket here:
NPC Code:

this.type = int(random(1,5);



and this part:
NPC Code:

setcharprop #c,#v(this.mined) | #v(this.hitter);
} else



needs another bracket too
NPC Code:

setcharprop #c,#v(this.mined) | #v(this.hitter);
} else {


GregoryYoshi 02-08-2002 01:27 AM

Quote:

Originally posted by TDO2000


I know that u can use more then only one param but I thought in that case #p(2) would be wrong....
and u missed a bracket here:
NPC Code:

this.type = int(random(1,5);



and this part:
NPC Code:

setcharprop #c,#v(this.mined) | #v(this.hitter);
} else



needs another bracket too
NPC Code:

setcharprop #c,#v(this.mined) | #v(this.hitter);
} else {


If you look again, I did 'else if (arguments) { which is perfectly legal in GScript :p I just had the If statement down a line so the script would look nice :)

As for not closing the parenthesis...I would have caught that eventually, but thank you just the same :)

Saga2001 02-08-2002 02:14 AM

Well if that is the only part that returns correctly, than that must mean that there is some sort of problem in the returning process. Maybe you sould (if all else fails) try using different function/variable names, because many times I have been haing the same problem and i have found that i accidently stumbled onto a keyword (reserved). Also you could do multiple things to test it, every time you go to the nest stage of something, have it add 1 to this.breakingpoint, and wherever it stops, post that and maybe we can help more.
If you are not sure what is wrong with your script, instead of posting the entire thing without any definition, you could do something like saying, "The problem seems to be ing the hitterid area", and you could put that part of the script in bold. If you do not do this, when it is posted people get frustrated as seen here by Kaimetsu and they refuse to help. For example when i first came here, I looked for what you said was happening, since you gave no definition of what was going wrong, I ignored the script and looked at the next posts to see if they had any clue. If there was a bold part, or a bold comment line in the script that said something like "Its somewhere in here" than i would be more attracted to help. Or even tell us what IS working so we can look at what is not. Just information for future reference. ;)

Saga2001 02-08-2002 02:16 AM

Quote:

Originally posted by TDO2000


I know that u can use more then only one param but I thought in that case #p(2) would be wrong....
and u missed a bracket here:
NPC Code:

this.type = int(random(1,5);



When you tested that in the scrpter, didn't it say "Variables cannot contain spaces"? Thats what it has always done for me.

GregoryYoshi 02-08-2002 04:17 AM

Quote:

Originally posted by Saga2001


When you tested that in the scrpter, didn't it say "Variables cannot contain spaces"? Thats what it has always done for me.

Nope...simply because it stops at the with (players i) since it doesn't recognize it :)


All times are GMT +2. The time now is 12:26 PM.

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