1 registered members (TipmyPip),
18,449
guests, and 6
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
How to open up inventory and freeze movement?
#429794
09/18/13 17:43
09/18/13 17:43
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
I am trying to make it so that my player can move normally as usual, but when the player presses the "i" key, I want the player's inventory to show, I want the mouse cursor to appear in order to manipulate the inventory, and I want the player's movement to cease, all happening simultaneously. If the player presses the "i" key a second time, I want the inventory to close, the mouse cursor to disappear, and the player be able to move again normally. Here is the code I am using to try and make this happen
var bag_i_counter = 0;
function change_mouse_mode()
{
mouse_mode += 1;
mouse_mode %= 2;
if (1 == mouse_mode)
mouse_map = cursor_pcx;
}
...
if(key_i)
{
bag_i_counter = 1;
if(bag_i_counter == 1)
{
inv_open_bag(bag, 500, 0);
mouse_mode = 1;
if(key_i)
{
bag_i_counter = 0;
inv_close_bag(bag);
mouse_mode = 0;
}
}
}
When I run this code, all I see is this error box stating this: Error E1512 Empty function called in inv_open_bag I press the OK button, but nothing happens. The inventory does not show up, the mouse cursor does not show up, and my player can still move about as normal. **************** Keep in mind that I do not have a fully functioning inventory yet. I am including the "inventory.c" code by Bret Truchan. In the past, when I pressed the "i" key, the only thing that happened was I got the same error message above. When I pressed the OK button on this error box, I saw a horizontal row of images that I placed in the inventory slots using my Lite-C code, and was even able to drag the first image from the row across the screen.
Last edited by Ruben; 09/18/13 17:44.
|
|
|
Re: How to open up inventory and freeze movement?
[Re: Ch40zzC0d3r]
#429812
09/19/13 05:20
09/19/13 05:20
|
Joined: Jun 2010
Posts: 590 California
Ruben
OP
User
|
OP
User
Joined: Jun 2010
Posts: 590
California
|
Here's the full function where the crash occurs:
action walking_guard()
{
player = me;
vec_fill(move_vec, 0); // always reset a vector to zero when creating
var bag_i_counter = 0;
my.JUMP_FORCE = 13;
var gravity_var = 0;
var gravity_force = 2;
var jumplck = 0;
var space_lck = 0;
my.FEET_HEIGHT = -my.min_z+1;
my.eflags |= FAT | NARROW; // set both flags to prevent automatic
// recalculation on scale changes.
my.emask |= ENABLE_SHOOT;
my.event = spell_fly_damage;
my.HEALTH = 500;
// set FLAG2 to make the guard detectable by c_scan,
// and store the guard pointer in its own CREATOR skill
// so that the detecting entity knows its enemy
set(my,FLAG2);
my.CREATOR = me;
set(my, POLYGON);
camera.tilt = -5;
my.STATE = 1;
while(my.x)
{
player_health();
// state 1: walking ////////////////////////////////////////////
if (my.STATE == 1)
{
while(mouse_mode == 1)
{
move_vec.x = 0;
move_vec.y = 0;
wait(1);
}
// MOVE PLAYER FORWARD/BACKWARD WITH "W" AND "S" KEYS, AND SIDEWAYS WITH
// "A" AND "D" KEYS
move_vec.x = key_w - key_s;
move_vec.y = key_a - key_d;
// MOVING FORWARD/BACKWARD KEYS - OPTIONS: UP AND DOWN ARROW KEYS, OR "W"
// AND "S" KEYS
distance = (key_w-key_s)*20*time_step;
distance_crawl = (key_w-key_s) * 5 * time_step;
if(key_i)
{
bag_i_counter = 1;
if(bag_i_counter == 1)
{
inv_open_bag(bag, 500, 0);
mouse_mode = 1;
if(key_i)
{
bag_i_counter = 0;
inv_close_bag(bag);
mouse_mode = 0;
}
}
}
// JUMPING CODE
if( (key_space) && !space_lck && !jumplck)
{
gravity_var = my.JUMP_FORCE;
jumplck = 1;
my.ANIMATION = 0;
}
space_lck = key_space;
gravity_var -= gravity_force * time_step;
// RUNNING
vec_normalize(move_vec, 20 * time_step); // normalize the vector -
// otherwise walking forward and sideways at the same time will be
// faster (~1.4151x)
c_move(me, move_vec, vector(0, 0, gravity_var), IGNORE_PASSABLE | GLIDE);
_handle_cam_3rdperson();
if(((key_w == 1) || (key_s == 1)) && (mouse_right == 0))
{
// FORWARD/BACKWARD MOVEMENT ANIMATION
my.ANIMATION += 1*distance;
ent_animate(me,"run",my.ANIMATION,ANM_CYCLE);
}
else
if(((key_w == 1) || (key_s == 1) || (key_a == 1) || (key_d == 1)) &&
(mouse_right == 1))
{
// CRAWLING
vec_normalize(move_vec, 5 * time_step); // normalize the vector -
// otherwise walking forward and sideways at the same time will be
// faster (~1.4151x)
// FORWARD/BACKWARD MOVEMENT ANIMATION
my.ANIMATION += 1*distance_crawl;
ent_animate(me,"crawl",my.ANIMATION,ANM_CYCLE);
}
else
if(mouse_right == 1)
{
// FORWARD/BACKWARD MOVEMENT ANIMATION
my.ANIMATION += 1*distance;
ent_animate(me,"crouch",my.ANIMATION,ANM_CYCLE);
}
else
{
// STANDING STILL ANIMATION
my.ANIMATION += 1*time_step;
ent_animate(me,"idle",my.ANIMATION,ANM_CYCLE); // "idle" stance
// continual animation
}
// adjust entity to the ground height, using a downwards trace
if(c_trace(my.x, vector(my.x, my.y, my.z - my.FEET_HEIGHT), IGNORE_ME |
IGNORE_PASSABLE | IGNORE_PASSENTS | USE_POLYGON))
{
my.z = target.z + (my.FEET_HEIGHT);
gravity_var = 0;
jumplck = 0;
}
// ATTACK CODE
if (mouse_left)
{ // key pressed -> go to state 2
my.ANIMATION = 0;
my.STATE = 2;
}
// state 2: guard swing attacking ///////////////////////////////////
if (my.STATE == 2)
{
while (1)
{
my.ANIMATION += 15*time_step;
ent_animate(me,"attack",my.ANIMATION,0); // "attack" one-shot
// animation
if (my.ANIMATION > 100) // finish the attack swing and go to state 3
{
while(1)
{
player_ctrace();
my.ANIMATION -= 35*time_step;
ent_animate(me,"attack",my.ANIMATION,0); // "attack" one-shot
// animation
if (my.ANIMATION <= 0)
{
my.STATE = 3;
break;
}
wait(1);
}
}
if (my.STATE == 3)
{
my.ANIMATION = 0;
my.STATE = 1;
break;
}
wait (1);
}
}
// DEATH OF PLAYER CODE
if (my.HEALTH <= 0)
{
my.ANIMATION = 0;
while(1)
{
ent_animate(me,"death",my.ANIMATION,0);
my.ANIMATION += 5*time_step;
if (my.ANIMATION >= 100)
return;
wait(1);
}
}
}
wait(1);
}
}
|
|
|
Re: How to open up inventory and freeze movement?
[Re: CanadianDavid]
#429816
09/19/13 06:43
09/19/13 06:43
|
Joined: Jul 2008
Posts: 2,110 Germany
rayp
 
X
|
 
X
Joined: Jul 2008
Posts: 2,110
Germany
|
but the logic doesn't look too nice +1 I dont get the logic of this
bag_i_counter = 1;
if(bag_i_counter == 1)
{
inv_open_bag(bag, 500, 0);
mouse_mode = 1;
..
First u set it to 1 then u check if its 1 ? Do u want to prevent a double start of this part ? If so this wont work this way in while. Without testing it, it needs to look like this fex
if(key_i)
{
bag_i_counter = 1;
inv_open_bag(bag, 500, 0);
mouse_mode = 1;
while(bag_i_counter == 1)
{
if(key_i)
{
bag_i_counter = 0;
inv_close_bag(bag);
mouse_mode = 0;
break;
}
wait (1);
}
}
This would pause player movement btw.
Last edited by rayp; 09/19/13 06:46.
Acknex umgibt uns...zwischen Dir, mir, dem Stein dort... "Hey Griswold ... where u gonna put a tree that big ?" 1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected rayp.flags |= UNTOUCHABLE;
|
|
|
Re: How to open up inventory and freeze movement?
[Re: rayp]
#429838
09/19/13 09:24
09/19/13 09:24
|
Joined: Jan 2006
Posts: 968
EpsiloN
User
|
User
Joined: Jan 2006
Posts: 968
|
Waiting for "I" key...
if(key_i)
{
bag_i_counter = 1;
inv_open_bag(bag, 500, 0);
mouse_mode = 1;
while(key_i == 1) { wait(1); }
while(key_i == 0) { wait(1); }
bag_i_counter = 0;
inv_close_bag(bag);
mouse_mode = 0;
}
}
And , you'll always see the same result(crash) until you post your inv_open_bag function or find out yourself why it is crashing. There is a problem (my guess...) with the method of calling the function.
|
|
|
Re: How to open up inventory and freeze movement?
[Re: EpsiloN]
#429841
09/19/13 09:39
09/19/13 09:39
|
Joined: May 2009
Posts: 5,377 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,377
Caucasus
|
What is the big deal behind this anyway guys?? Why don't you simply do this like this (this will works for 100%, cause this is how I've done it in my inventory):
// switch to toggle inventory:
void toggleInventory(){
// put some comperisions here:
// f.e. if we are dead, don't allow to toggle inventory:
if(player.health <= 0){ return; }
// toggle var:
invOpen += 1;
invOpen %= 2;
// if we've opened the intentory:
if(invOpen == 1){
// show the mouse pointer:
mouse_mode = 2;
}
else{
// hide the mouse:
mouse_mode = 0;
}
}
// players actions:
action heroDude(){
// toggle inventory:
on_i = toggleInventory;
// player's loop:
while(my.health > 0){
// .......
// .......
// .......
// if inventory closed:
if(invOpen == 0){
// allow to move:
force.x = 10 * (key_w - key_s) * time_step;
force.y = 10 * (key_a - key_d) * time_step;
force.z = 0;
}
else{
// if it was open, stop movement:
vec_set(force.x, nullvector);
}
// .......
// .......
// .......
// wait one frame:
wait(1);
}
}
// main game function:
void main(){
// .......
// .......
// .......
// main game loop:
while(1){
// .......
// .......
// .......
// if we've enabled the mouse:
if(mouse_mode > 0){
// move it's position with a cursor:
vec_set(mouse_pos.x, mouse_cursor.x);
}
// wait one frame:
wait(1);
}
}
Why are you trying to make things complicated? Make it easier instead  Greets
Last edited by 3run; 09/19/13 09:45. Reason: ADDED MOUSE CURSOR!
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|