PDA

View Full Version : Majora attempts scripting.



Majora
10-05-2012, 01:51 PM
ffc script Patrol{
void run(){
while(true){
if (this->X == Link->X+8 || Link->X-8) {
this->Vx = 0;
}
if (this->X != Link->X+8 || Link->X-8) {
this->Vx = 1;
}

Waitframe();
}
}
}

What this is supposed to do is move the FFC at a constant speed, stopping if it bumps into link. I have a vague idea of what i'm doing but naturally, it's not working. The FFC moves, sure, but it just zooms right by link. :( Before I made some edits the FFC would stop if it was completely overlapped with link. It was odd. I put link against a corner (of solid combos) and the FFC would stop. but it wouldn't stop no matter what otherwise. The lack of intuition to this backwoods game engine will be the aneurysm of me.

This is a WIP script, taking it one step at a time. I don't want this to turn into a 300-line block of code for something as simple as moving a FFC between two points and being wary of link. However, the following behavior is what I'd like to achieve after working on this script some more:

FFC moving between two points (specified with those scripting combo flags).
------ When it reaches that point, the FFC switches combos or tiles. They will be consecutive either way.

Stops moving when Link bumps into the FFC. Resumes moving after he moves away.

I think that's it. I would love to be able to have guards that move between more than 2 points but I don't want to incur the wrath of Zscript. Siiiiiiiiigh. @_@

CJC
10-05-2012, 03:24 PM
ffc script Patrol{
void run(){
while(true){
if (this->X == Link->X+8 || Link->X-8) {
this->Vx = 0;
}
if (this->X != Link->X+8 || Link->X-8) {
this->Vx = 1;
}

Waitframe();
}
}
}

What this is supposed to do is move the FFC at a constant speed, stopping if it bumps into link. I have a vague idea of what i'm doing but naturally, it's not working. The FFC moves, sure, but it just zooms right by link. :( Before I made some edits the FFC would stop if it was completely overlapped with link. It was odd. I put link against a corner (of solid combos) and the FFC would stop. but it wouldn't stop no matter what otherwise. The lack of intuition to this backwoods game engine will be the aneurysm of me.

This is a WIP script, taking it one step at a time. I don't want this to turn into a 300-line block of code for something as simple as moving a FFC between two points and being wary of link. However, the following behavior is what I'd like to achieve after working on this script some more:

FFC moving between two points (specified with those scripting combo flags).
------ When it reaches that point, the FFC switches combos or tiles. They will be consecutive either way.

Stops moving when Link bumps into the FFC. Resumes moving after he moves away.

I think that's it. I would love to be able to have guards that move between more than 2 points but I don't want to incur the wrath of Zscript. Siiiiiiiiigh. @_@

Okay, you're using the OR (||) command incorrectly. You need to specify the ENTIRE criterion on each side of the OR. Like this:

ffc script Patrol{
void run(){
while(true){
if (this->X == Link->X+8 || this->X == Link->X-8) {
this->Vx = 0;
}
if (this->X != Link->X+8 || this->X != Link->X-8) {
this->Vx = 1;
}

Waitframe();
}
}
}
You need a "this->X ==" on BOTH sides of the OR. It should (might) work as intended now.

Also, I am so glad now that the [CODE] BBtag doesn't do the same function as [noparse] BBtag. It let me highlight the change to the code.



The reason the corner was stopping the guard had nothing to do with the corner... it had to do with Link being to the RIGHT of the guard. Since your script was not properly checking to the LEFT (that second side of the OR), the guard just zoomed along.

Since Link's XY position is recorded as the UPPER LEFT side of his tile, you might want to switch it three ORs... like so:

ffc script Patrol{
void run(){
while(true){
if (this->X == Link->X || this->X == Link->X+8 || this->X == Link->X+15) {
this->Vx = 0;
}
if (this->X != Link->X || this->X != Link->X+8 || this->X != Link->X+15) {
this->Vx = 1;
}

Waitframe();
}
}
}


Also, since this script doesn't check y-proximity, the guard may stop if Link is all the way across the room. It may need a few extra lines, but let's just make sure it works on the horizontal first.

CJC
10-05-2012, 04:38 PM
Lets try this...



ffc script Patrol{
void run(){
while(true){
if (ComboF[ComboAt(this->X+16, this->Y || this->Y+8 || this->Y+15)] == 96){ //Checks if the combo to the right has flag 96
this->Vx = -1;
}
else if (ComboF[ComboAt(this->X-1, this->Y || this->Y+8 || this->Y+15)] == 96){
this->Vx = 1;
}
else if ((this->X == Link->X-8 || this->X == Link->X+23) && (this->Y == Link->Y || this->Y == Link->Y +8 || this->Y == Link-> Y+15)){
this->Vx = 0;
}
Waitframe();
}


EDIT: Doesn't compile, because I'm a space case. What about this?



int PatrolV;

ffc script Patrol{
void run(){
while(true){
if (Screen->ComboF[ComboAt(this->X+16, this->Y) || ComboAt(this->X+16, this->Y+8) || ComboAt(this->X+16, this->Y+15)] == 96 || this->X > 208){ //Checks if the combo to the right has flag 96
PatrolV = -1;
}
else if (Screen->ComboF[ComboAt(this->X-1, this->Y) || ComboAt(this->X-1, this->Y+8) || ComboAt(this->X-1, this->Y+15)] == 96 || this->X < -1){
PatrolV = 1;
}
else if ((this->X == Link->X-8 || this->X == Link->X+23) && (this->Y == Link->Y || this->Y == Link->Y +8 || this->Y == Link-> Y+15)){
this->Vx = 0;
}
else {this->Vx = PatrolV}
Waitframe();
}
}

Majora
10-05-2012, 04:56 PM
ComboF is undeclared. ;_;

CJC
10-05-2012, 05:05 PM
I'm sorry I'm so inept at this. I'll try again.



ffc script Patrol{
void run(){
while(true){
if (this->X > 208){
this->Vx = -1;
}
else if (this->X < -1){
this->Vx = 1;
}
else if ((this->X == Link->X-8 || this->X == Link->X+23) && (this->Y == Link->Y || this->Y == Link->Y +8 || this->Y == Link-> Y+15)){
this->Vx = 0;
}
Waitframe();
}
}

EDIT: Getting closer!



int PatrolV = 1; //The guard will begin by moving to the right

ffc script Patrol{
void run(){
while(true){
if (this->X > 208){
PatrolV = -1;
}
else if (this->X < 1){
PatrolV = 1;
}
if ((((this->X == Link->X-8) && (PatrolV == 1)) || ((this->X == Link->X+23) && (PatrolV == -1))) && (this->Y == Link->Y || this->Y == Link->Y +8 || this->Y == Link-> Y+15)){
this->Vx = 0;
}
else {this->Vx = PatrolV};
Waitframe();
}
}

Majora
10-07-2012, 11:38 PM
Everything works except the guard only stops once in each direction if it bumps into link. How to make it always stop if it bumps into link? then wait until link moves along the Y axis a certain distance before resuming its movement.


int PatrolV;

ffc script Patrol{
void run(int MaxX, int MaxY, int npcissolid, int MinX, int MinY, int cbo){
int tho=(this->TileHeight*16-16);
while(true){
if (this->X > MaxX){
PatrolV = -.75;
this->Data = cbo+1;
}
else if (this->X < MinX){
PatrolV = .75;
this->Data = cbo;
}
if ((((this->X == Link->X-12) && (PatrolV == .75)) || ((this->X == Link->X+23) && (PatrolV == -.75))) && (this->Y == Link->Y || this->Y == Link->Y +12 || this->Y == Link-> Y+15)){
this->Vx = 0;
}
else {this->Vx = PatrolV;}
//This enables the NPC to be solid without having to lay a solid combo under it.
if (npcissolid>0){
if ((Abs(Link->X - this->X) < 10) &&
(Link->Y <= this->Y+tho + 12) && (Link->Y > this->Y+tho+8)){Link->Y = this->Y+tho+12;}

if ((Abs(Link->Y - this->Y-tho) < 10) &&
(Link->X >= this->X - 12) && (Link->X < this->X-8)){Link->X = this->X-12;}

if ((Abs(Link->X - this->X) < 10) &&
(Link->Y >= this->Y+tho - 12) && (Link->Y < this->Y+tho-8)){Link->Y = this->Y+tho-12;}

if ((Abs(Link->Y - this->Y-tho) < 10) &&
(Link->X <= this->X + 12) && (Link->X > this->X+8)){Link->X = this->X+12;}
}
Waitframe();
}
}
}

And also that chunk of code at the bottom for FFC pseudo-solidity, can someone edit it so that FFCs are only half solid? If this was a combo in the combo editor, only the bottom half would be pink.

Double-also I want to remove the hard-coded speeds and just make it PURELY "if link is nearby, stop. if link is not nearby, resume paying attention to your speed values". That is, the ones on the FFC itself.