thx to scorp for helping last time.
Anyway, when i press the right mouse button, it changes to walk cursor and starts a timer. When the timer expires it is suppose to change back to look cursor. But it doesn't unless i press the left mouse button once again. y?
Oh, it's a shooter game, ammo engine thing.
btw any suggestions on my scripting would be nice.
int chooser;
int mouse_clicks = 0;
function on_mouse_click(int button) {
// called when a mouse button is clicked. button is either LEFT or RIGHT
if (IsTimerExpired(9)==1){ //when the reload timer is up
mouse_clicks = 0;
EnableCursorMode(MODE_LOOK);
SetCursorMode(MODE_LOOK);
SetObjectGraphic(3,10);
}
if (IsGamePaused() == 1) {
// Game is paused, so do nothing (ie. don't allow mouse click)
}
else if (button==LEFT) {
ProcessClick(mouse.x, mouse.y, GetCursorMode() );
mouse_clicks = mouse_clicks + 1; // increasing mouse click counter
if (mouse_clicks < 9) {
PlaySound(1);
}
if (mouse_clicks == 0) {
SetObjectGraphic(3,10);
SetCursorMode(MODE_LOOK);
}
if (mouse_clicks == 1) { //changes graphics with number of
SetObjectGraphic(3,11);//clicks. Changes the ammo thing.
}
if (mouse_clicks == 2) {
SetObjectGraphic(3,12);
}
if (mouse_clicks == 3) {
SetObjectGraphic(3,13);
}
if (mouse_clicks == 4) {
SetObjectGraphic(3,14);
}
if (mouse_clicks == 5) {
SetObjectGraphic(3,15);
}
if (mouse_clicks == 6) {
SetObjectGraphic(3,16);
}
if (mouse_clicks == 7) {
SetObjectGraphic(3,17);
}
if (mouse_clicks == 8) {
SetObjectGraphic(3,18);
SetTimer(9, 50);
SetCursorMode(MODE_WALK);
DisableCursorMode(MODE_LOOK);
mouse_clicks = 10;
}
}
else { // right-click, so cycle cursor
SetTimer(9, 50);
SetCursorMode(MODE_WALK); //when right clicked re-loads
DisableCursorMode(MODE_LOOK); //sets the time it
mouse_clicks = 10; //to reload
}
}
I think your problem is having the first piece of code in the on_mouse_click int which only operates if you click the mouse button - you'll probably fare better by putting that piece of code in the repeatedly_execute int - but you may have to tweak your programming so that the timer isn't expired when you don't want it to be.
This is all I can think of for now - hope it helps.
I've already got something in repeatedly. I tried to switch them but still the same.
This is a small bug but it bugs me all the same.
Yeah, Mr Frisby is right, move it to the repeatedly_execute:
function repeatedly_execute() {
if (IsTimerExpired(9)==1){ //when the reload timer is up
mouse_clicks = 0;
EnableCursorMode(MODE_LOOK);
SetCursorMode(MODE_LOOK);
SetObjectGraphic(3,10);
}
}
i made the other function, which is separated from the main bit. But when i reload it doesn't go back to normal, Even when i press left mouse again!
It will help if you post the whole script related. Also, couldn't you please summarize how that thingy is supposed to work, like pressing left button - fire, right - reload, etc?
When people say move it to the repeatedly execute, make sure you put the code in the same function as what you already had there, not in another repeatedly_execute, or swapping them round, just do:
function repeatedly_execute() {
if (IsTimerExpired(9)==1){ //when the reload timer is up
mouse_clicks = 0;
EnableCursorMode(MODE_LOOK);
SetCursorMode(MODE_LOOK);
SetObjectGraphic(3,10);
}
// Rest of your rep_ex code goes here....
}
Also, you can save some typing if you replace all those ifs 1-7 with:
SetObjectGraphic(3,10 + mouse_clicks);
SSH, i already figured that out when scorpiopus posted first.
still haven't figured reload...
Anyway: Left click is suppose to be fire.(look). Right click is reloads(walk). I put the objects to 'any click on object' so it would react to all but walk. I didn't put hide player as if you do that, there is no walk cursor.
New problem: The obects won't come up! function room_b() is suppose to make the obects come up, but it doesn't...this happened after i tried to make a 'shortcut' the riskshot.
int shum = 0; //nothing important. Random string
int chooser = 0; //what object is next
int mouse_clicks = 0; //mouse clicks
int gak = 0; //shot
int lives = 5; //lives
int riskshot = 0; //on if shot
function on_mouse_click(int button) {
if (IsGamePaused() == 1) {
// Game is paused, so do nothing (ie. don't allow mouse click)
}
else if (button==LEFT) {
ProcessClick(mouse.x, mouse.y, GetCursorMode() );
mouse_clicks = mouse_clicks + 1; // increasing mouse click counter
if (mouse_clicks < 9) {
PlaySound(1);
}
if (mouse_clicks == 0) {
SetObjectGraphic(3,10);
SetCursorMode(MODE_LOOK);
}
if (mouse_clicks == 1) { //changes graphics with number of
SetObjectGraphic(3,11);//clicks. Changes the ammo thing.
}
if (mouse_clicks == 2) {
SetObjectGraphic(3,12);
}
if (mouse_clicks == 3) {
SetObjectGraphic(3,13);
}
if (mouse_clicks == 4) {
SetObjectGraphic(3,14);
}
if (mouse_clicks == 5) {
SetObjectGraphic(3,15);
}
if (mouse_clicks == 6) {
SetObjectGraphic(3,16);
}
if (mouse_clicks == 7) {
SetObjectGraphic(3,17);
}
if (mouse_clicks == 8) {
SetObjectGraphic(3,18);
SetTimer(9, 50);
SetCursorMode(MODE_WALK);
DisableCursorMode(MODE_LOOK);
mouse_clicks = 10;
}
}
else { // right-click, so cycle cursor
shum = mouse_clicks * 10 + 15;
SetTimer(9, shum);
SetCursorMode(MODE_WALK); //when right clicked re-loads
DisableCursorMode(MODE_LOOK); //sets the time it takes to reload
mouse_clicks = 10;
}
}
// called when a mouse button is clicked. button is either LEFT or RIGHT
function repeatedly_execute() {
if (IsTimerExpired(9)==1){ //when the reload timer is up
mouse_clicks = 0;
EnableCursorMode(MODE_LOOK);
SetCursorMode(MODE_LOOK);
SetObjectGraphic(3,10);
}
if (gak == 1){
gak = 0;
lives --;
if (lives == 5) {
SetObjectGraphic(4,22);
}
if (lives == 4) {
SetObjectGraphic(4,23);
}
if (lives == 3) {
SetObjectGraphic(4,24);
}
if (lives == 2) {
SetObjectGraphic(4,25);
}
if (lives == 1) {
SetObjectGraphic(4,26);
}
if (lives == 0) {
SetObjectGraphic(4,27);
}
if (lives < 0) {
SetObjectGraphic(4,27);
}
}
}
function room_b() {
// script for room: Repeatedly execute
if (riskshot == 1){
if (IsTimerExpired(1) == 1){
gak = 1;
riskshot = 0;
}
}
if (chooser == 0){
SetObjectGraphic(0,6);
MoveObjectDirect(0,70,103,1);
SetTimer (1, 80);
riskshot = 1;}
if (chooser == 1){
SetObjectGraphic(1,6);
MoveObjectDirect (1,12,103,1);
SetTimer (1, 80);
riskshot = 1;
}
if (chooser == 2) {
SetObjectGraphic(5, 6);
MoveObjectDirect (5,219,113,2);
SetTimer (1,60);
riskshot = 1;
}
}
function object0_a() {
// script for object0: Any click on object
SetObjectGraphic(0,8);
MoveObjectDirect (0,68,126,1);
chooser = 2;
}
function object1_a() {
// script for object1: Any click on object
SetObjectGraphic(1,8);
MoveObjectDirect (1,13,127,1);
chooser = 3;
}
function room_c() {
// script for room: Player enters screen (before fadein)
SetCursorMode(MODE_LOOK);
}
function object4_a() {
// script for object4: Look at object
SetTimer(9, 80);
SetCursorMode(MODE_WALK);
DisableCursorMode(MODE_LOOK);
mouse_clicks = 10;
}
hmm, the repeatedly_execute() function should be placed into the main global script, is it? Or move the content of the repeatedly_execute to the room_b() (room's repeatedly execute). The if (chooser==...)'s code is executed when chooser is 0, 1 or 2. You've set chooser=2 and chooser=3.
btw, what object numbers are targets to shot at? Do they respawn when have been shot? In that case use SetObjectPosition instead of MoveObjectDirect:
function object0_a() {
// script for object0: Any click on object
SetObjectGraphic(0,8);
SetObjectPosition (0,68,126);
//MoveObjectDirect (0,68,126,1);
chooser = 2;
}
function object1_a() {
// script for object1: Any click on object
SetObjectGraphic(1,8);
SetObjectPosition (1,13,127);
MoveObjectDirect (1,13,127,1);
chooser = 3;
}
Any changes?