11.02.2018, 17:27
Hello!
I'm currently writing this system which replicates a bolt action rifle.
I'm having some trouble making it work correctly, thought. Sometimes it works, sometimes it doesnt, please give me your best advice and help if you can!
OnPlayerKeyStateChange callback
cerrojoTime
Bolt command
When player spawns, cerrojo value is set to 0.
Why do you think its working so erratically?
Do you think it is adviced to use a timer for this system? Or should I set the variable value directly in the OnPlayerKeyStateChange callback? My reasoning for using a timer is that the variable sets its value long before the shot is made, and it doesn't let the player shoot his rifle, but I'm not sure if I'm correct.
EDIT: After I use /bolt, the cerrojo value is still 1.
EDIT 2: If you have a more esthetic or optimized way to make this system, please let me know!
I'm currently writing this system which replicates a bolt action rifle.
I'm having some trouble making it work correctly, thought. Sometimes it works, sometimes it doesnt, please give me your best advice and help if you can!
OnPlayerKeyStateChange callback
Quote:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { if (PRESSED(KEY_FIRE)) { if(GetPlayerWeapon(playerid) == 33) { if(cerrojo == 0) { cerrojoTimer = SetTimer("cerrojoTime", 500, true); } else { SetPlayerArmedWeapon(playerid,0); SendClientMessage(playerid, COLOR_RED, "You must pull your rifle bolt."); ClearAnimations(playerid); } } } if (HOLDING(KEY_FIRE)) { if(GetPlayerWeapon(playerid) == 33) { if(cerrojo == 0) { cerrojoTimer = SetTimer("cerrojoTime", 500, true); } else { SetPlayerArmedWeapon(playerid,0); ClearAnimations(playerid); } } } return 1; } |
Quote:
public cerrojoTime() { cerrojo = 1; KillTimer(cerrojoTimer); } |
Quote:
CMD:bolt(playerid, params[]) { if(GetPlayerWeapon(playerid) == 33 && cerrojo == 1) { SendClientMessage(playerid, COLOR_GREEN, "You pull the bolt of your rifle."); cerrojo = 0; } else { SendClientMessage(playerid, COLOR_RED, "You're not holding your rifle or the bolt is already loaded."); } return 1; } |
Why do you think its working so erratically?
Do you think it is adviced to use a timer for this system? Or should I set the variable value directly in the OnPlayerKeyStateChange callback? My reasoning for using a timer is that the variable sets its value long before the shot is made, and it doesn't let the player shoot his rifle, but I'm not sure if I'm correct.
EDIT: After I use /bolt, the cerrojo value is still 1.
EDIT 2: If you have a more esthetic or optimized way to make this system, please let me know!