STEAM GROUP
game development help gamedevhelp
STEAM GROUP
game development help gamedevhelp
9
IN-GAME
81
ONLINE
Founded
28 May, 2015
Language
English
All Discussions > questions > Topic Details
Verflucht 29 May, 2015 @ 3:34am
i need damn low script basics....
Hey guy !
how to set a cd for my bullets? if i press the left button very fast the bullets will create in the same speed. need to stop it!
im new here so excuse my stupid question :'D
< >
Showing 1-13 of 13 comments
Verflucht 29 May, 2015 @ 3:35am 
instance_create(x,y,obj_kugel)

if instance_create(x,y,obj_kugel)
{

}

i set it in /obj_"char"/event/global left pressed
Last edited by Verflucht; 29 May, 2015 @ 3:38am
epicmars 29 May, 2015 @ 5:44am 
I use
Event: Create >
firerate = 50; accuracy = 2; isfiring = false;
Event: alarm0 >
isfiring = false;
Event: global left mouse button >
if(!isfiring) { isfiring = true; alarm[0] = firerate; b1=instance_create(x,y,obj_bullet_1); b1.direction += (random(accuracy)); }

firerate = the fire speed (the higher the number the faster it shoots)
accuracy = how accurate it will shoot
Last edited by epicmars; 31 Jan, 2016 @ 6:54pm
epicmars 29 May, 2015 @ 6:45am 
this is all the code + movement (I don't know what you use for movement but maybe it will help)

Event: Create >

image_speed = 1; image_index = 0; walkingSpeed = 5; setSpeed = 0.5; firerate = 50; accuracy = 0; isfiring = false;

Event: alarm0 >

isfiring = false;

Event: Step >
image_angle = direction; direction = point_direction(x,y,mouse_x,mouse_y); friction = 0.5; if(keyboard_check(ord("W"))) { speed = walkingSpeed; } if(keyboard_check(ord("S"))) { speed = -walkingSpeed; }

Event: global left button >

if(!isfiring) { isfiring = true; alarm[0] = firerate; b1=instance_create(x,y,obj_A0_bullet_1); b1.direction += (random(accuracy)); }
Last edited by epicmars; 31 Jan, 2016 @ 6:53pm
Verflucht 29 May, 2015 @ 7:15am 
Create: counter = 0
step: if counter > 0 { counter -=1}
mouse_left_pressed: if(counter == 0) { instance_create(x,y,obj_bullet); counter = 60; }


that works, but thanks anyway :)
Verflucht 29 May, 2015 @ 7:21am 
i need to use this script cuz i use obj_bullet: draw event;


draw_sprite_ext(spt_bullet,image_index,x,y,1,1,direction,c_white,1)

"let the bullet fly straight to characters pov"

i think this will made the problem but its fixed now.
u can close this thread now or leave it for a smart lesson.
if another one get stuck here maybe on of this ways could help him
Verflucht 29 May, 2015 @ 7:23am 
if(keyboard_check(ord("W"))) { speed = walkingSpeed; }
if(keyboard_check(ord("S"))) { speed = -walkingSpeed; }


used simply the same movement code


var sp;
sp = 3;
if keyboard_check(ord("W")){if place_free(x,y-sp){y-=sp}}
if keyboard_check(ord("S")){if place_free(x,y+sp){y+=sp}}
if keyboard_check(ord("A")){if place_free(x-sp,y){x-=sp}}
if keyboard_check(ord("D")){if place_free(x+sp,y){x+=sp}}

the little bit smarter way, i also dont have to set the place_free var solo also got the speed into it. what do u think about it ? i think its a smart way to keep ur code small, it is?
:D
Last edited by Verflucht; 29 May, 2015 @ 7:27am
epicmars 29 May, 2015 @ 7:38am 
good to hear that it works :)
Alexa Reizla 30 Jan, 2016 @ 11:31pm 
Originally posted by ZaMi (inDev):
Create: counter = 0
step: if counter > 0 { counter -=1}
mouse_left_pressed: if(counter == 0) { instance_create(x,y,obj_bullet); counter = 60; }


that works, but thanks anyway :)
NEVER USE COUNTERS AS TIMERS! Better use CPU time instead.

Not sure what OP is programming in, but all C-dialects have a time method (time.deltaTime in C#) to calculate time passed between cycles.
Verflucht 31 Jan, 2016 @ 11:18am 
in gml (delta_time) :steamhappy:
ItsJustTony 9 May, 2016 @ 5:53pm 
The easiest way to make cooldowns that I have found, and I am fairly new to all this, is by the use of alarms.

Set the alarm to trigger when a button is pressed, then to time itself out for a certain amount of time then trigger itself again to create a cycle. My main PC is down for the moment or I would give you snippets of code to refer to.
ItsJustTony 9 May, 2016 @ 11:58pm 
Originally posted by ZaMi (inDev):
i dont like to work with alarms so i use delta_time or current_time, DemiGoth was right ! never use a counter as timer (if ur pc do lag, the counter will too) use delta_time or current_time this wont have this problem (excuse the german/english :P)
Just going off of your original subject of low script basics, alarms are the easiest way I can think of to do what you are wanting
ItsJustTony 10 May, 2016 @ 12:02am 
Originally posted by ZaMi (inDev):
i have not denied so whats ur prob?
I have no problem friend, happy coding
< >
Showing 1-13 of 13 comments
Per page: 1530 50

All Discussions > questions > Topic Details