new bool:actionButton[MAX_PLAYERS]; static const c_missileFireRate = 200; public OnGameModeInit() { SetTimer("missileTimer", c_missileFireRate, true); return 1; } forward missileTimer(); public missileTimer() { foreach(new i : Player) { if(actionButton[i]) //And some other condition... (is player in a plane or something) { //Shoot missile } } return 1; } public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { if(newkeys & KEY_ACTION) { actionButton[playerid] = true; } else { actionButton[playerid] = false; } return 1; }
Did I say it is optional? Of course it is, else you\'re calling a global timer.
|
SetTimerEx("missileTimer ", c_missileFireRate, false, "i", playerid);
A small problem has appeared, sadly.
The timer is only called for the first player connected to the server (That's what I think) The automatic fire works perfectly for this player, but other players still have the manual fire rate. How can I make the timer so that it's called for every player who presses the button? |
#define PRESSED(%0) \ (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) #define RELEASED(%0) \ (((oldkeys & (%0)) == (%0)) && ((newkeys & (%0)) != (%0))) if(PRESSED(KEY_SPRINT)) { if(missileTimer[playerid] != -1) return 1; missileTimer[playerid] = SetTimerEx("MissileFunction", 1000, true, "d", playerid); } if(RELEASED(KEY_SPRINT)) { if(missileTimer[playerid] != -1) { KillTimer(missileTimer[playerid]); missileTimer[playerid] = -1; } }
D:\Games\SAMP Server\filterscripts\1947_test.pwn(36) : error 028: invalid subscript (not an array or too many subscripts): "FireRateTimer" D:\Games\SAMP Server\filterscripts\1947_test.pwn(36) : warning 215: expression has no effect D:\Games\SAMP Server\filterscripts\1947_test.pwn(36) : error 001: expected token: ";", but found "]" D:\Games\SAMP Server\filterscripts\1947_test.pwn(36) : error 029: invalid expression, assumed zero D:\Games\SAMP Server\filterscripts\1947_test.pwn(36) : fatal error 107: too many error messages on one line
#include <a_samp> #include <foreach> #include <colandreas> #include <streamer> #include <3DTryg> #include <Missile> #include <VehicleMissileCol> #define PRESSED(%0) \ (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) #define RELEASED(%0) \ (((oldkeys & (%0)) == (%0)) && ((newkeys & (%0)) != (%0))) new bool:autoFireButton[MAX_PLAYERS]; static const c_AutoFireRate = 50; //define the rate of fire in milliseconds public OnGameModeInit() { SetTimer("FireRateTimer", c_AutoFireRate, true); return 1; } forward FireRateTimer(playerid,vehicleid); public FireRateTimer(playerid,vehicleid) { if(autoFireButton[playerid]) OnVehicleShot(playerid,VEHICLE_MISSILE_TYPE_CON); return 1; } public OnPlayerKeyStateChange(playerid, newkeys, oldkeys){ if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0){ new vid = GetPlayerVehicleID(playerid); if(IsToggleVehicleCongreve(vid)){ if(PRESSED(GetVehicleCongreveKey(vid))){ if(FireRateTimer[playerid] != -1) return 1; FireRateTimer[playerid] = SetTimerEx("MissileFunction", 1000, true, "d", playerid); SendClientMessage(playerid, 0x00FF00FF, "button pressed."); } if(RELEASED(GetVehicleCongreveKey(vid))){ if(FireRateTimer[playerid] != -1) { KillTimer(FireRateTimer[playerid]); FireRateTimer[playerid] = -1; SendClientMessage(playerid, 0x00FF00FF, "button released."); } } } } return 1; }
Thanks for all your replies! Sadly I\'ve been getting this error:
Code:
D:\Games\SAMP Server\filterscripts\1947_test.pwn(36) : error 028: invalid subscript (not an array or too many subscripts): "FireRateTimer" D:\Games\SAMP Server\filterscripts\1947_test.pwn(36) : warning 215: expression has no effect D:\Games\SAMP Server\filterscripts\1947_test.pwn(36) : error 001: expected token: ";", but found "]" D:\Games\SAMP Server\filterscripts\1947_test.pwn(36) : error 029: invalid expression, assumed zero D:\Games\SAMP Server\filterscripts\1947_test.pwn(36) : fatal error 107: too many error messages on one line |
1 #include <a_samp> 2 #include <foreach> 3 #include <colandreas> 4 #include <streamer> 5 #include <3DTryg> 6 #include <Missile> 7 #include <VehicleMissileCol> 8 9 #define PRESSED(%0) \ 10 (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) 11 #define RELEASED(%0) \ 12 (((oldkeys & (%0)) == (%0)) && ((newkeys & (%0)) != (%0))) 13 14 new bool:autoFireButton[MAX_PLAYERS]; 15 static const c_AutoFireRate = 50; //define the rate of fire in milliseconds 16 17 public OnGameModeInit() 18 { 19 SetTimer("FireRateTimer", c_AutoFireRate, true); 20 return 1; 21 } 22 23 forward FireRateTimer(playerid); 24 public FireRateTimer(playerid) 25 { 26 if(autoFireButton[playerid]) 27 OnVehicleShot(playerid,VEHICLE_MISSILE_TYPE_CON); 28 return 1; 29 } 30 31 forward FireRateTimer(playerid); 32 public OnPlayerKeyStateChange(playerid, newkeys, oldkeys){ 33 if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0){ 34 new vid = GetPlayerVehicleID(playerid); 35 if(IsToggleVehicleCongreve(vid)){ 36 if(PRESSED(GetVehicleCongreveKey(vid))){ 37 if(FireRateTimer[playerid] != -1) return 1; // <-- This is the line which gives the error 38 FireRateTimer[playerid] = SetTimerEx("MissileFunction", 1000, true, "d", playerid); 39 SendClientMessage(playerid, 0x00FF00FF, "button pressed."); 40 } 41 if(RELEASED(GetVehicleCongreveKey(vid))){ 42 if(FireRateTimer[playerid] != -1) { 43 KillTimer(FireRateTimer[playerid]); 44 FireRateTimer[playerid] = -1; 45 SendClientMessage(playerid, 0x00FF00FF, "button released."); 46 } 47 } 48 } 49 } 50 return 1; }
I removed the vehicle ID and forwarded FireRateTimer, didn\'t work.
Here is the script with all lines, sorry for not posting it in the first place. It\'s line 37 Code:
1 #include <a_samp> 2 #include <foreach> 3 #include <colandreas> 4 #include <streamer> 5 #include <3DTryg> 6 #include <Missile> 7 #include <VehicleMissileCol> 8 9 #define PRESSED(%0) \ 10 (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) 11 #define RELEASED(%0) \ 12 (((oldkeys & (%0)) == (%0)) && ((newkeys & (%0)) != (%0))) 13 14 new bool:autoFireButton[MAX_PLAYERS]; 15 static const c_AutoFireRate = 50; //define the rate of fire in milliseconds 16 17 public OnGameModeInit() 18 { 19 SetTimer("FireRateTimer", c_AutoFireRate, true); 20 return 1; 21 } 22 23 forward FireRateTimer(playerid); 24 public FireRateTimer(playerid) 25 { 26 if(autoFireButton[playerid]) 27 OnVehicleShot(playerid,VEHICLE_MISSILE_TYPE_CON); 28 return 1; 29 } 30 31 forward FireRateTimer(playerid); 32 public OnPlayerKeyStateChange(playerid, newkeys, oldkeys){ 33 if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0){ 34 new vid = GetPlayerVehicleID(playerid); 35 if(IsToggleVehicleCongreve(vid)){ 36 if(PRESSED(GetVehicleCongreveKey(vid))){ 37 if(FireRateTimer[playerid] != -1) return 1; // <-- This is the line which gives the error 38 FireRateTimer[playerid] = SetTimerEx("MissileFunction", 1000, true, "d", playerid); 39 SendClientMessage(playerid, 0x00FF00FF, "button pressed."); 40 } 41 if(RELEASED(GetVehicleCongreveKey(vid))){ 42 if(FireRateTimer[playerid] != -1) { 43 KillTimer(FireRateTimer[playerid]); 44 FireRateTimer[playerid] = -1; 45 SendClientMessage(playerid, 0x00FF00FF, "button released."); 46 } 47 } 48 } 49 } 50 return 1; } |
#include <a_samp> #include <foreach> #include <colandreas> #include <streamer> #include <3DTryg> #include <Missile> #include <VehicleMissileCol> #define PRESSED(%0) \ (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) #define RELEASED(%0) \ (((oldkeys & (%0)) == (%0)) && ((newkeys & (%0)) != (%0))) new bool:autoFireButton[MAX_PLAYERS], FireRateTimer[MAX_PLAYERS]; static const c_AutoFireRate = 50; //define the rate of fire in milliseconds public OnGameModeInit() { SetTimer("FireRateTimer", c_AutoFireRate, true); return 1; } forward MissileFunction(playerid); public MissileFunction(playerid) { if(autoFireButton[playerid]) // What is this? You don`t set autoFireButton on true anywhere OnVehicleShot(playerid,VEHICLE_MISSILE_TYPE_CON); return 1; } public OnPlayerConnect(playerid) { FireRateTimer[playerid] = -1; // other stuff from your gm } public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) { if(IsPlayerInAnyVehicle(playerid) && GetPlayerVehicleSeat(playerid) == 0) { new vid = GetPlayerVehicleID(playerid); if(IsToggleVehicleCongreve(vid)) { if(PRESSED(GetVehicleCongreveKey(vid))) { if(FireRateTimer[playerid] != -1) return 1; // <-- This is the line which gives the error FireRateTimer[playerid] = SetTimerEx("MissileFunction", 1000, true, "d", playerid); SendClientMessage(playerid, 0x00FF00FF, "button pressed."); } if(RELEASED(GetVehicleCongreveKey(vid))) { if(FireRateTimer[playerid] != -1) { KillTimer(FireRateTimer[playerid]); FireRateTimer[playerid] = -1; SendClientMessage(playerid, 0x00FF00FF, "button released."); } } } } return 1; }