Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, TraderTom, Akow), 1,388 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19055 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
problem with script, please help. (SOLVED!) #314224
03/06/10 19:24
03/06/10 19:24
Joined: Mar 2010
Posts: 29
L
lollollollollol Offline OP
Newbie
lollollollollol  Offline OP
Newbie
L

Joined: Mar 2010
Posts: 29
hey, (this is page 1/2)

I got this question about scripting/ level editing.

I want to let the camera follow my playing character, let him walk on the ground(but when there is a ramp, he has to walk up the ramp in stead of walking through) and he may not walk through walls.

So i have this code:
Code:
#include <acknex.h>
#include <default.c>
#define walk_percentage skill11
#define STATE     skill1
#define STATE     skill1
#define ANIMATION skill2


////////////////////////////////////////////////////////////////////

BMAP* cursor_pcx = "cursor.pcx";
BMAP* crosshair_pcx = "crosshair.pcx";

////////////////////////////////////////////////////////////////////

function camera_follow(ENTITY* ent)
{
	while(1) 
	{
		vec_set(camera.x,vector(-150,10,50));  // camera position relative to the player      
		vec_rotate(camera.x,ent.pan); // rotate the camera position with the player
		vec_add(camera.x,ent.x);      // add player position
		vec_set(camera.pan,vector(ent.pan,-10,0)); // look in player direction, slighty down      
		wait(1);
	}
}


action character_walking()
{ 
  camera_follow(me);
 
  VECTOR vFeet;
  vec_for_min(vFeet,me); // vFeet.z = distance from player origin to lowest vertex
  
  my.STATE = 1; 
  while (1)
  {
// state 1: walking ////////////////////////////////////////////
    if (my.STATE == 1)
    {
// rotate the entity with the arrow keys     
      my.pan += (key_cul-key_cur)*5*time_step;   

// move the entity forward/backward with the arrow keys
      var distance = (key_cuu-key_cud)*5*time_step;
      c_move(me, vector(distance,0,0), NULL, GLIDE);

// animate the entity    
      my.ANIMATION += 2*distance;
      ent_animate(me,"walk",my.ANIMATION,ANM_CYCLE);

// adjust entity to the ground height, using a downwards trace
      c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME | IGNORE_PASSABLE);
      my.z = hit.z - vFeet.z; // always place player's feet on the ground

    }
  }
}

    


function change_mouse_mode()
{
	mouse_mode += 1;
	mouse_mode %= 3;
	if (1 == mouse_mode)
		mouse_map = crosshair_pcx;
	if (2 == mouse_mode)
		mouse_map = cursor_pcx;
}

action zombie_bars()
{
	while (1)
	{
		my.walk_percentage += 2 * time_step; // 3 = animation speed 
		ent_animate(me, "attack", my.walk_percentage, ANM_CYCLE); // "attack" animation loop
		wait (1);
	}
}

action zombie_fight_against_eachother()
{
	while (1)
	{
		my.walk_percentage += 3 * time_step; // 3 = animation speed 
		ent_animate(me, "hit", my.walk_percentage, ANM_CYCLE); // "attack" animation loop
		wait (1);
	}
}
	action zombie_fight_against_eachotherr()
{
	while (1)
	{
		my.walk_percentage += 2.5 * time_step; // 3 = animation speed 
		ent_animate(me, "hit", my.walk_percentage, ANM_CYCLE); // "attack" animation loop
		wait (1);
	}
}

function main()
{
	video_mode = 7;
	level_load ("Huis.wmb");
	ent_create("zombiek.mdl",vector(293,-107,-55), zombie_bars);
	you = ent_create("zombiek.mdl",vector(425,106,-47), zombie_fight_against_eachother);
	you.pan= 60;
	you = ent_create("zombiek.mdl",vector(530,106,-47), zombie_fight_against_eachotherr);
	you.pan= 240;
	on_m = change_mouse_mode;
	while (1)
	{
		mouse_pos.x = mouse_cursor.x;
		mouse_pos.y = mouse_cursor.y;
		camera.pan -= mouse_force.x;
		camera.tilt += mouse_force.y;
		 
		wait (1);
	}
	camera.z = 120; // choose a convenient height
	camera.tilt = -15; // and tilt angle for the camera
}



so if anyone knows why my script doesnt work, please respond.

p.s. i havent loaded the character i will play with yet, but if that is nessecary, then could you please make this script with the main character in it.

Last edited by lollollollollol; 03/08/10 18:55.
Re: problem with script, please help. [Re: lollollollollol] #314267
03/07/10 11:50
03/07/10 11:50
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
I didn't have a close look into your script, but it seems okay.
What is your ramp and your wall made of? Are they blocks? Is the level built? Are they models? Then you have to set their POLYGON on. You can do that in WED in the properties panel or in script, assigning an action to them.
But your last sentence is confusing:
Did you try to run your script without a model that moves in a level?
For collision treatment (c_move and c_trace) you actually need collision entities, means a model with a collision box/ellipsoid that you steer through a world with obstacles with collision properties.

Re: problem with script, please help. [Re: Pappenheimer] #314273
03/07/10 12:26
03/07/10 12:26
Joined: Mar 2010
Posts: 29
L
lollollollollol Offline OP
Newbie
lollollollollol  Offline OP
Newbie
L

Joined: Mar 2010
Posts: 29
The walls are made of blocks.

With the last sentence, i mean that I do have a character i can move, but it is not yet loaded in the script nor in the level.

I don't know how to call up an entity i can move with my arrows in a script. I thought i had done it with this script, but I cant combine the walking part with a character i can walk... So the script is there, but i can use it yet, and i dont understand why.

Re: problem with script, please help. [Re: lollollollollol] #314276
03/07/10 12:49
03/07/10 12:49
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
This is how you load the zombie in the level:

you = ent_create("zombiek.mdl",vector(530,106,-47), zombie_fight_against_eachotherr);


It is the same with the player:

you = ent_create("zombiek.mdl",vector(530,106,-47), character_walking);


Did you have a look into the manual?
Index 'ent_create'.

Re: problem with script, please help. [Re: Pappenheimer] #314379
03/08/10 06:53
03/08/10 06:53
Joined: Mar 2010
Posts: 29
L
lollollollollol Offline OP
Newbie
lollollollollol  Offline OP
Newbie
L

Joined: Mar 2010
Posts: 29
I did have a look in the manual, but how do i define , that my character can walk with the arrow keys, and that the camera is following him. I know how to load an entity, but not with this 2 functions.

So if anyone is kind enough to tell me that wink please...

Re: problem with script, please help. [Re: lollollollollol] #314394
03/08/10 11:28
03/08/10 11:28
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
assign an action and in that action use the my-pointer to control the entity. key events and states are described in the manual.

Re: problem with script, please help. [Re: Joey] #314396
03/08/10 11:46
03/08/10 11:46
Joined: Mar 2010
Posts: 29
L
lollollollollol Offline OP
Newbie
lollollollollol  Offline OP
Newbie
L

Joined: Mar 2010
Posts: 29
where in the manual, as I searched it everywhere?

Re: problem with script, please help. [Re: lollollollollol] #314420
03/08/10 15:04
03/08/10 15:04
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
You already posted such a code, so I thought you already know about that. Look into it: key_cul, key cur, etc. are the inputs of the key.
So something like the following means that the angle of the entity is changed by adding the 'signals' from the keys:
my.pan += (key_cul-key_cur)*5*time_step;

And the following lines mean that the variable distance is equal to the input of the result of the computed inputs of the keys at the right of '='.

This means simply as I said in my post before that assigning this action to an entity is sufficient to control that entity.


Code:
action character_walking()
{ 
  camera_follow(me);
 
  VECTOR vFeet;
  vec_for_min(vFeet,me); // vFeet.z = distance from player origin to lowest vertex
  
  my.STATE = 1; 
  while (1)
  {
// state 1: walking ////////////////////////////////////////////
    if (my.STATE == 1)
    {
// rotate the entity with the arrow keys     
      my.pan += (key_cul-key_cur)*5*time_step;   

// move the entity forward/backward with the arrow keys
      var distance = (key_cuu-key_cud)*5*time_step;
      c_move(me, vector(distance,0,0), NULL, GLIDE);

// animate the entity    
      my.ANIMATION += 2*distance;
      ent_animate(me,"walk",my.ANIMATION,ANM_CYCLE);

// adjust entity to the ground height, using a downwards trace
      c_trace(my.x,vector(my.x,my.y,my.z-1000),IGNORE_ME | IGNORE_PASSABLE);
      my.z = hit.z - vFeet.z; // always place player's feet on the ground

    }
  }
}



Re: problem with script, please help. [Re: Pappenheimer] #314421
03/08/10 15:19
03/08/10 15:19
Joined: Mar 2010
Posts: 29
L
lollollollollol Offline OP
Newbie
lollollollollol  Offline OP
Newbie
L

Joined: Mar 2010
Posts: 29
i know, but i cant link that script to the character i play with... I know that script can make you walk, but not how to bind it to a character

Re: problem with script, please help. [Re: lollollollollol] #314434
03/08/10 16:37
03/08/10 16:37
Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
Pappenheimer Offline
Senior Expert
Pappenheimer  Offline
Senior Expert

Joined: Sep 2003
Posts: 5,900
Bielefeld, Germany
In your initial post you posted a script, and you ask whether someone knows why it isn't working for you.

But you didn't say, what didn't work.
Did the level load?
Did you see zombies fighting against each other?

If you say, yes, at least that worked, then you only need to paste the following line within the curly brackets within the function main(), after the level_load instruction:


you = ent_create("zombiek.mdl",vector(0,0,0), character_walking);

EDIT:
Sorry, I posted too fast, forgot things that had to be changeed to make sense to you.

Last edited by Pappenheimer; 03/08/10 18:12.
Page 1 of 2 1 2

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1