Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 677 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
after mouse_left 0.5 second wait?? #411693
11/18/12 21:22
11/18/12 21:22
Joined: Nov 2012
Posts: 32
T
thorus Offline OP
Newbie
thorus  Offline OP
Newbie
T

Joined: Nov 2012
Posts: 32
hey guys, i realy like to know how i can do a pause after left click couse i have the action swing axe on left click and everytime i press is do it so i can make 20x attacks in 1 second,
please can u help me to get a wait around 0.5 second after i pressed mouse_left till i can do it again? hope u understand my english... thanks!!

Code:
var player_weapon = 0;
var player_got_axe = 0;

STRING* key_weapon1 = "1";
STRING* hithole_tga = "hithole.tga"; // the hit hole bitmap

function display_hithole(); // shows the hit hole bitmap
function axt_schlaege(); // creates the bullets

//SOUND* axe_hit_wav = "axe_hit.wav"; // axe sound
//SOUND* gotweapon_wav = "gotweapon.wav"; // this sound is played when the player gets a new weapon

ENTITY* player_axeent = // the axe is created as an entity so that its model doesn't penetrate the walls
{
type = "chopper.mdl"; // use your own weapon model here
x = 50; // 50 quants ahead of the view, play with this value
y = -20; // 25 quants towards the right side of the screen, play with this value
z = -20; // 30 quants below, play with this value
pan = 210; // axe pan angle (set its tilt, roll, etc if you want to)
tilt = -5;
roll =90;
scale_x = 0.5; // spieler größe ändern
scale_y = 0.7; // spieler größe ändern
scale_z = 0.5; // spieler größe ändern
layer = 20;
}


action player_axe() // attach this action to your axe model
{
set (my, PASSABLE); // don't hinder player's movement
while (!player) {wait (1);} // wait until the player is loaded
while (vec_dist (player.x, my.x) > 80 || !key_pressed(18)) // wait until the player has come close to the axe and key e pressed

wait (1);
//snd_play(gotweapon_wav, 80, 0); // play the "got weapon" sound
player_got_axe = 1; // got the axe
wait (-0.5); // wait for 0.5 seconds
player_weapon = 1; // give the player the axe (show the axe entity on the screen)
ent_remove (my); // and then remove the axe from the ground
}


function player_weapons_startup()
{
var bob_factor = 0;
VECTOR player1_pos, player2_pos, trace_coords;
on_mouse_left = axt_schlaege; // call this function when the left mouse button is pressed
while (!player) {wait (1);} // wait until the player model is loaded
proc_mode = PROC_LATE; // run this function at the end of the function scheduler list (eliminates jerkiness)
while (1)
{
vec_set (player1_pos.x, player.x); // store the current position of the player
wait (1); // wait for one frame
vec_set (player2_pos.x, player.x); // get the new position of the player after a frame
if (vec_dist(player2_pos.x, player1_pos.x) > 0 && (key_shift)) // the player has moved during the last frame?
{
bob_factor += 25 * time_step; // then increase bob_factor
if (player_axeent) // if the pistol was picked up
player_axeent.z += 0.3 * sin(bob_factor); // move the axe up and down as the player moves in the level
player_axeent.x += 0.3 * sin(bob_factor);
player_axeent.y += 0.3 * sin(bob_factor);
}

if (vec_dist(player2_pos.x, player1_pos.x) > 0 && (!key_shift)) // the player has moved during the last frame?
{
bob_factor += 25 * time_step; // then increase bob_factor
if (player_axeent) // if the pistol was picked up
player_axeent.z += 0.07 * sin(bob_factor); // move the axe up and down as the player moves in the level
player_axeent.x += 0.07 * sin(bob_factor);
player_axeent.y += 0.07 * sin(bob_factor);
}



// the key for the first weapon was pressed and we've got the axe right now?
if (player_weapon == 0) // no weapon is selected?
{
player_axeent.flags2 &= ~SHOW;
}
if (player_weapon == 1)
{
player_axeent.flags2 |= SHOW;
}

}
}
var attack_perc = 0;

action axt_schlag()
{
if (mouse_left ==1)
{
wait(0.5);
}
if (attack_perc <=1 )
{
attack_perc += 51;
player_axeent.tilt +=60;
}


wait(-0.5);

if (attack_perc >=1 )
{
attack_perc -= 51;
player_axeent.tilt -=60;
}
}



function axt_schlaege()
{
if (lebensenergie <= 0) return;
VECTOR trace_coords;
while (mouse_left)
{
switch(player_weapon)
{
case 0:

return;
case 1:

axt_schlag();
wait(1);

return;
}
wait (1);
}
}

function display_hithole() // this tiny function pust a hit hole bitmap on the walls
{
vec_to_angle (my.pan, normal); // orient the hit hole sprite correctly
vec_add(my.x, normal.x); // move the sprite a bit away from the wall
set (my, PASSABLE); // the hit hole bitmap is passable
set (my, TRANSLUCENT); // and transparent
my.ambient = 30;
my.roll = random(360); // has a random roll angle
my.scale_x = 1; // we scale it down
my.scale_y = my.scale_x; // on the x and y axis
wait (-20); // show the hit hole bitmap for 20 seconds
ent_remove (my); // and then remove it
}


Last edited by JustSid; 11/19/12 08:46. Reason: Added code tags. Sadly it doesn't make it easier to read because there is zero indentation
Re: after mouse_left 0.5 second wait?? [Re: thorus] #411694
11/18/12 21:35
11/18/12 21:35
Joined: Jan 2002
Posts: 4,225
Germany / Essen
Uhrwerk Offline
Expert
Uhrwerk  Offline
Expert

Joined: Jan 2002
Posts: 4,225
Germany / Essen
Waiting is pretty easy. You can use the wait function for that: http://www.conitec.net/beta/acrt-wait.htm

Passing negative values to wait will wait the absolute value in seconds.
Passing positive values to wait will wait the given number of frames.

Code:
wait(-0.5); // waits half a second.
wait(13); // Waits for 13 frames.



Please use code tags when posting code.


Always learn from history, to be sure you make the same mistakes again...
Re: after mouse_left 0.5 second wait?? [Re: Uhrwerk] #411717
11/19/12 04:07
11/19/12 04:07
Joined: Nov 2012
Posts: 32
T
thorus Offline OP
Newbie
thorus  Offline OP
Newbie
T

Joined: Nov 2012
Posts: 32
yeah but that dont work... if i press mouse_left again the tilt from the axe turn up again and the function restart.. so i can hit 20x in a second.. frown

Re: after mouse_left 0.5 second wait?? [Re: thorus] #411718
11/19/12 06:17
11/19/12 06:17
Joined: Feb 2010
Posts: 320
TANA/Madagascar
3dgs_snake Offline
Senior Member
3dgs_snake  Offline
Senior Member

Joined: Feb 2010
Posts: 320
TANA/Madagascar
Hi,

You can also create and update an internal interval to check against every time you press mouse button.

Re: after mouse_left 0.5 second wait?? [Re: 3dgs_snake] #411742
11/19/12 13:48
11/19/12 13:48
Joined: Nov 2012
Posts: 32
T
thorus Offline OP
Newbie
thorus  Offline OP
Newbie
T

Joined: Nov 2012
Posts: 32
ahh thanks, could u explain me in some letters how that work? ( little example) please

Re: after mouse_left 0.5 second wait?? [Re: thorus] #411746
11/19/12 14:04
11/19/12 14:04
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
God, use on_mouse_left and wait and you should get it to work..

Re: after mouse_left 0.5 second wait?? [Re: Ch40zzC0d3r] #411747
11/19/12 14:24
11/19/12 14:24
Joined: Nov 2012
Posts: 32
T
thorus Offline OP
Newbie
thorus  Offline OP
Newbie
T

Joined: Nov 2012
Posts: 32
no doesnt work smirk the problem is, when i hit the mousebutton fast ~20x the axe tilt go 60...120...180...and so on, when i wait the -0.5 seconds it tilt go back as i should do.. but it should not be able to do this ..

Re: after mouse_left 0.5 second wait?? [Re: thorus] #411750
11/19/12 14:50
11/19/12 14:50
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Originally Posted By: thorus
no doesnt work smirk the problem is, when i hit the mousebutton fast ~20x the axe tilt go 60...120...180...and so on, when i wait the -0.5 seconds it tilt go back as i should do.. but it should not be able to do this ..


I said ON_mouse_left, you can give it a function pointer and de-assign the function in the function. Then wait 0.5 and re-assign the function. Please look at the manual if you dont understand this..

Re: after mouse_left 0.5 second wait?? [Re: Ch40zzC0d3r] #411772
11/19/12 18:41
11/19/12 18:41
Joined: Nov 2012
Posts: 32
T
thorus Offline OP
Newbie
thorus  Offline OP
Newbie
T

Joined: Nov 2012
Posts: 32
allright, it works now, thanks!


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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