Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- >>> READ EVERY 'IMPORTANT' TAG! (CTRL+F 'IMPORTANT' and then press F3).
- >>> READ EVERYTHING FROM LINE 1 - 50,
- THEY CAN SAVE YOUR LIFE (not really, but they'll inform you about some "lazy bug fixes" & how to avoid breaking my fixes)!!!!!!!!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- STUFF YOU MIGHT NEED TO KNOW,
- 'Interval' - The time it takes to capture the zone, default: 25.
- 'Controller' - The player who has captured/owns the, default: INVALID_PLAYER_ID.
- 'Zone' - Zone stuff for 'CreateDynamicSquare'
- 'zMinX', 'zMinY', 'zMaxX', 'zMaxY' - The Zone positions/borders or w.e.
- 'TextX', 'TextY', 'TextZ' - The 3D Text Label position.
- 'zText' - 3D Text Label for zone
- 'Name' - The Zone Name.
- 'Capturing' - Is the zone being captured or not.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- Q&A (with myself),
- Q: "How to add the zones?!?!!?!?!?!"
- A: go to 'zInfo' (line 116), and add the stuff.
- Q: "What stuff?"
- A: The stuff which I named above (Interval, Controller, Pos ...).
- Q: "How"
- A: Just look at the example zones I gave you.
- Q: "How to create zones??"
- A: I personally use "Xtremes Vehicle Plotter", but im sure there are many other editors out there.
- Q: "filterscript unload??"
- A: Check the console, if it prints(shows, writes..) errors and 2 notes, you did something wrong with adding the zones (line 123 - 125).
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- POSSIBLE ERROR/WARNING YOU MIGHT GET & HOW TO FIX IT,
- "error 052: multi-dimensional arrays must be fully initialized"
- Your 'MAX_ZONES' needs to be LOWERED! (-1 the number, EXAMPLE: You replace the 6 with a 5)
- * If you added a zone, you must raise it, if you removed a zone, you must lower it.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- "error 018: initialization data exceeds declared size",
- "error 001: expected token: "}", but found "{"",
- "error 054: unmatched closing brace ("}")",
- "error 010: invalid function or declaration"
- Your 'MAX_ZONES' needs to be RAISED! (+1 the number, EXAMPLE: You replace the 5 with a 6)
- * If you added a zone, you must raise it, if you removed a zone, you must lower it.
- **
- I haven't 'got' any other warns/errors that caused me to get confused,
- but most of the errors are being caused in the "zInfo" part -- So, right after you add a zone there, compile it.
- Might help you know where you went wrong.
- */
- #define FILTERSCRIPT
- #include <a_samp>
- #include <foreach>
- #include <streamer>
- #include <zcmd>
- #define MAX_ZONES 6
- #define ZONE_MESSAGE_CAPTURING 0
- #define ZONE_MESSAGE_SUCCESS 1
- #define ZONE_MESSAGE_FAIL 2
- enum playerInfo
- {
- bool:ZoneOwned[ MAX_ZONES ],
- CapturingZone,
- Name[ 24 ]
- };
- new
- pInfo[ MAX_PLAYERS ][ playerInfo ],
- Timer_ZoneControl
- ;
- enum zoneInfo
- {
- Interval, Controller,
- Zone,
- Float:zMinX, Float:zMinY,
- Float:zMaxX, Float:zMaxY,
- Float:TextX, Float:TextY, Float:TextZ,
- Text3D:zText,
- Name[ 18 ],
- bool:Capturing
- };
- new zInfo[ MAX_ZONES ][ zoneInfo ] =
- {
- { 25, INVALID_PLAYER_ID, -1, -1564.835, 2534.099, -1366.311, 2674.233, -1495.9861, 2601.3513, 55.6872, Text3D:zText, "El Quebrados", false },
- { 25, INVALID_PLAYER_ID, -1, -794.0955, 1996.917, -607.2495, 2090.34, -726.5607, 2061.4075, 60.3828, Text3D:zText, "Sherman Dam", false },
- { 25, INVALID_PLAYER_ID, -1, 1107.436, 2714.903, 1396.395, 2854.154, 1279.2919, 2779.8875, 10.8203, Text3D:zText, "Golf Course", false },
- { 25, INVALID_PLAYER_ID, -1, 1255.821, 2072.804, 1384.68, 2212.055, 1356.5494, 2144.2888, 11.0156, Text3D:zText, "Bandits Stadium", false },
- { 25, INVALID_PLAYER_ID, -1, 1333.917, 676.4326, 1536.969, 800.2107, 1494.1503, 707.7706, 10.6719, Text3D:zText, "Blackfield Chapel", false },
- //Add your next zones here, above 'To_Fix_Bugs'
- { 25, INVALID_PLAYER_ID, -1, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, Text3D:zText, "To_Fix_Bugs", true } //IMPORTANT: Do NOT remove or change this!!! (last zone won't work, so yes..)
- //IMPORTANT: Do NOT add your zones here!!! (Add them above 'To_Fix_Bugs'!!)
- };
- #if defined FILTERSCRIPT
- public OnFilterScriptInit()
- {
- print("\n--------------------------------------");
- print("'Player-Based Capture Zones' loading..\nVersion: 1.0");
- print("--------------------------------------\n");
- for(new i = 0; i < MAX_ZONES; i++)
- {
- EditZone( i, true );
- }
- foreach( Player, i )
- {
- GetPlayerName(i, pInfo[ i ][ Name ], 24);
- pInfo[ i ][ CapturingZone ] = -1;
- TogglePlayerAllDynamicAreas(i, true);
- }
- Timer_ZoneControl = SetTimer("UpdateZones", 1000, true);
- return 1;
- }
- public OnFilterScriptExit()
- {
- print("\n--------------------------------------");
- print("'Player-Based Capture Zones' unloading..");
- print("--------------------------------------\n");
- for(new i = 0; i < MAX_ZONES; i++)
- {
- EditZone( i, false );
- }
- KillTimer( Timer_ZoneControl );
- return 1;
- }
- #endif
- //- - - - CALLBACKs ( MAIN ONES )
- public OnPlayerConnect(playerid)
- {
- GetPlayerName(playerid, pInfo[ playerid ][ Name ], 24);
- for(new i; i < MAX_ZONES; i++)
- {
- if(zInfo[ i ][ Controller ] != playerid) continue;
- pInfo[ playerid ][ ZoneOwned ][ i ] = false;
- zInfo[ i ][ Controller ] = INVALID_PLAYER_ID;
- }
- TogglePlayerAllDynamicAreas(playerid, true);
- pInfo[ playerid ][ CapturingZone ] = -1;
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- new
- string[ 42 ]
- ;
- for(new i; i < MAX_ZONES; i++)
- {
- if(zInfo[ i ][ Controller ] != playerid) continue;
- format(string, sizeof( string ), "'%s'\nNOT CAPTURED", zInfo[ i ][ Name ]);
- Update3DTextLabelText(zInfo[ i ][ zText ], -1, string);
- pInfo[ playerid ][ ZoneOwned ][ i ] = false;
- zInfo[ i ][ Controller ] = INVALID_PLAYER_ID;
- }
- TogglePlayerAllDynamicAreas(playerid, false);
- zInfo[ pInfo[ playerid ][ CapturingZone ] ][ Capturing ] = false;
- pInfo[ playerid ][ CapturingZone ] = -1;
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- if(pInfo[ playerid ][ CapturingZone ] != -1)
- {
- EndCapture(playerid, pInfo[ playerid ][ CapturingZone ], false, true);
- }
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- if(pInfo[ playerid ][ CapturingZone ] != -1)
- {
- EndCapture(playerid, pInfo[ playerid ][ CapturingZone ], false, true);
- }
- return 1;
- }
- //- - - - CALLBACKs ( STREAMER ONES )
- public OnPlayerEnterDynamicArea(playerid, areaid)
- {
- areaid = areaid-1; //IMPORTANT: Do NOT remove this... as long as it doesn't ruin stuff, this is my "lazy bug fix" of a weird id bug.
- //It loads fine on console, but i dunno.. messes up the names and stuff (could be a bug w/ the new streamer? :O)
- if(!IsPlayerInAnyVehicle(playerid))
- {
- if(zInfo[ areaid ][ Capturing ] == false)
- {
- if(pInfo[ playerid ][ ZoneOwned ][ areaid ] == false)
- {
- StartCapture( playerid, areaid, true );
- }
- else SendClientMessage(playerid, -1, "(ZONE) You already own this zone!");
- }
- else SendClientMessage(playerid, -1, "(ZONE) This zone is already being captured!");
- }
- return 1;
- }
- public OnPlayerLeaveDynamicArea(playerid, areaid)
- {
- areaid = areaid-1; //IMPORTANT: Do NOT remove this... as long as it doesn't ruin stuff, this is my "lazy bug fix" of a weird id bug.
- //It loads fine on console, but i dunno.. messes up the names and stuff (could be a bug w/ the new streamer? :O)
- if(!IsPlayerInAnyVehicle(playerid))
- {
- if( pInfo[ playerid ][ CapturingZone ] == areaid )
- {
- EndCapture( playerid, areaid, false, true );
- }
- }
- return 1;
- }
- public OnPlayerStateChange(playerid, newstate, oldstate)
- {
- if(IsPlayerInAnyDynamicArea(playerid, 0))
- {
- if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
- {
- EndCapture( playerid, pInfo[ playerid ][ CapturingZone ], false, true );
- SendClientMessage(playerid, -1, "(ZONE) You must be on-foot!");
- }
- }
- return 1;
- }
- //- - - - FUNCTIONs
- ZoneMessage( playerid, zoneid, messagetype, bool:sendtoall = false )
- {
- new
- string[ 86 ]
- ;
- switch( messagetype )
- {
- case ZONE_MESSAGE_CAPTURING:
- {
- switch( sendtoall )
- {
- case false:
- {
- format(string, sizeof( string ), "(ZONE) You're capturing '%s'.", zInfo[ zoneid ][ Name ]);
- SendClientMessage(playerid, -1, string);
- }
- case true:
- {
- format(string, sizeof( string ), "(ZONE) %s is capturing '%s'.", pInfo[ playerid ][ Name ], zInfo[ zoneid ][ Name ]);
- SendClientMessageToAll(-1, string);
- }
- }
- }
- case ZONE_MESSAGE_SUCCESS:
- {
- switch( sendtoall )
- {
- case false:
- {
- format(string, sizeof( string ), "(ZONE) You've captured '%s'!", zInfo[ zoneid ][ Name ]);
- SendClientMessage(playerid, -1, string);
- }
- case true:
- {
- format(string, sizeof( string ), "(ZONE) %s has captured '%s'!", pInfo[ playerid ][ Name ], zInfo[ zoneid ][ Name ]);
- SendClientMessageToAll(-1, string);
- }
- }
- }
- case ZONE_MESSAGE_FAIL:
- {
- switch( sendtoall )
- {
- case false:
- {
- format(string, sizeof( string ), "(ZONE) You've failed to capture '%s'.", zInfo[ zoneid ][ Name ]);
- SendClientMessage(playerid, -1, string);
- }
- case true:
- {
- format(string, sizeof( string ), "(ZONE) %s has failed to capture '%s'.", pInfo[ playerid ][ Name ], zInfo[ zoneid ][ Name ]);
- SendClientMessageToAll(-1, string);
- }
- }
- }
- }
- }
- StartCapture( playerid, zoneid, bool:message )
- {
- new
- string[ 42 ]
- ;
- pInfo[ playerid ][ CapturingZone ] = zoneid;
- zInfo[ zoneid ][ Capturing ] = true;
- zInfo[ zoneid ][ Interval ] = 25;
- format(string, sizeof( string ), "'%s'\nBEING CAPTURED", zInfo[ zoneid ][ Name ]);
- Update3DTextLabelText(zInfo[ zoneid ][ zText ], -1, string);
- if(message) ZoneMessage( playerid, zoneid, ZONE_MESSAGE_CAPTURING, true );
- }
- EndCapture( playerid, zoneid, bool:success, bool:message )
- {
- new
- string[ 52 ]
- ;
- pInfo[ playerid ][ CapturingZone ] = -1;
- zInfo[ zoneid ][ Interval ] = 25;
- zInfo[ zoneid ][ Capturing ] = false;
- switch( success )
- {
- case true:
- {
- pInfo[ playerid ][ ZoneOwned ][ zoneid ] = true;
- zInfo[ zoneid ][ Controller ] = playerid;
- format(string, sizeof( string ), "'%s'\nCAPTURED BY: %s", zInfo[ zoneid ][ Name ], pInfo[ playerid ][ Name ]);
- Update3DTextLabelText(zInfo[ zoneid ][ zText ], -1, string);
- if(message) ZoneMessage( playerid, zoneid, ZONE_MESSAGE_SUCCESS, true );
- }
- case false:
- {
- pInfo[ playerid ][ ZoneOwned ][ zoneid ] = false;
- if(zInfo[ zoneid ][ Controller ] != -1)
- {
- format(string, sizeof( string ), "'%s'\nCAPTURED BY: %s", zInfo[ zoneid ][ Name ], pInfo[ zInfo[ zoneid ][ Controller ] ][ Name ]);
- Update3DTextLabelText(zInfo[ zoneid ][ zText ], -1, string);
- }
- else
- {
- format(string, sizeof( string ), "'%s'\nNOT CAPTURED", zInfo[ zoneid ][ Name ]);
- Update3DTextLabelText(zInfo[ zoneid ][ zText ], -1, string);
- }
- if(message) ZoneMessage( playerid, zoneid, ZONE_MESSAGE_FAIL, true );
- }
- }
- }
- EditZone( zoneid, bool:create )
- {
- switch( create )
- {
- case true:
- {
- new
- string[ 42 ]
- ;
- if( zoneid != MAX_ZONES-1 )
- {
- if(strcmp("To_Fix_Bugs", zInfo[ zoneid ][ Name ], true))
- {
- zInfo[ zoneid ][ Zone ] = CreateDynamicRectangle( zInfo[ zoneid ][ zMinX ], zInfo[ zoneid ][ zMinY ], zInfo[ zoneid ][ zMaxX ], zInfo[ zoneid ][ zMaxY ], 0, -1, -1);
- format(string, sizeof( string ), "'%s'\nNOT CAPTURED", zInfo[ zoneid ][ Name ]);
- zInfo[ zoneid ][ zText ] = Create3DTextLabel(string, -1, zInfo[ zoneid ][ TextX ], zInfo[ zoneid ][ TextY ], zInfo[ zoneid ][ TextZ ], 85, 0, 1);
- printf("--------------------\nzone %s(%d) created", zInfo[ zoneid ][ Name ], zoneid);
- }
- else
- {
- printf("ERROR: 'bug-zone %s' loaded with id %d\nNOTE: 'bug-zone' has an invalid id!\nNOTE: are you sure 'bug-zone' is last in the list?", zInfo[ zoneid ][ Name ], zoneid);
- SendRconCommand("unloadfs capturezones");
- }
- }
- else
- {
- zInfo[ zoneid ][ Zone ] = CreateDynamicRectangle( zInfo[ zoneid ][ zMinX ], zInfo[ zoneid ][ zMinY ], zInfo[ zoneid ][ zMaxX ], zInfo[ zoneid ][ zMaxY ], 69, -1, -1);
- printf("--------------------\nbug-zone %s(%d) created at world 69\n--------------------\n", zInfo[ zoneid ][ Name ], zoneid);
- }
- }
- case false:
- {
- DestroyDynamicArea( zoneid );
- Delete3DTextLabel( zInfo[ zoneid ][ zText ]);
- printf("--------------------\nzone %s(%d) deleted", zInfo[ zoneid ][ Name ], zoneid);
- }
- }
- }
- forward UpdateZones();
- public UpdateZones()
- {
- new
- pzoneid,
- str[ 50 ]
- ;
- foreach( Player, i )
- {
- if(pInfo[ i ][ CapturingZone ] == -1) continue;
- else
- {
- pzoneid = pInfo[ i ][ CapturingZone ];
- zInfo[ pzoneid ][ Interval ]--;
- if(zInfo[ pzoneid ][ Interval ] > 0) format(str, sizeof( str ), "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~r~%d", zInfo[ pzoneid ][ Interval ]), GameTextForPlayer(i, str, 1250, 3);
- else EndCapture( i, pzoneid, true, true ), GameTextForPlayer(i, "~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~n~~g~CAPTURED", 2500, 3);
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement