| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- /*
- [DECLARATIONS]
- */
- #if !defined _samp_included
- #error Please include a_samp before actor_robbery.
- #endif
- #if !defined KEY_AIM
- #define KEY_AIM 128
- #endif
- #if !defined PreloadAnimLib
- #define PreloadAnimLib(%1,%2) ApplyAnimation(%1,%2,"null",0.0,0,0,0,0,0)
- #endif
- #define MAX_ROBBERY_ACTORS (50)
- #define TYPE_SUCCESS (0)
- #define TYPE_FAILED (1)
- #define TYPE_UNFINISHED (2)
- #define MIN_MONEY_ROB 500
- #define MAX_MONEY_ROB 10000
- #define ROBBERY_WAIT_TIME (5)
- enum E_ACTOR_ROBBERY_DATA
- {
- actor_skin,
- Float:actor_x,
- Float:actor_y,
- Float:actor_z,
- Float:actor_ang,
- actor_vw,
- money_min,
- money_max,
- bool:actor_created,
- actor_robbedRecently
- }
- static
- robbery_data[MAX_ROBBERY_ACTORS][E_ACTOR_ROBBERY_DATA],
- i_actor = 0;
- forward RunActorAnimationSequence(playerid, actorid, animation_pattern);
- forward OnPlayerStartRobbery(playerid, actorid, bool:robbed_recently);
- forward OnPlayerFinishRobbery(playerid, actorid, robbedmoney, type);
- forward OnPlayerRequestRobbery(playerid, actorid);
- /*
- Function:
- CreateActorRobbery
- Info:
- Creates the robbery actor according to the position set.
- Param:
- * skinid -> Skin ID of the robbery actor
- * Float:x -> Coordinate X of the robbery actor
- * Float:y -> Coordinate X of the robbery actor
- * Float:z -> Coordinate X of the robbery actor
- * Float:ang -> Facing angle of the robbery actor
- * actor_vwid -> virtualid of the robbery actor
- * r_moneymin -> Minimum money to be robbed from the robbery actor
- * r_moneymax -> Maximum money to be robbed from the robbery actor
- */
- #pragma deprecated GetActorRobberyData
- stock GetActorRobberyData(actorid, &skinid, &Float:x, &Float:y, &Float:z, &Float:ang, &actor_vwid, &r_moneymin, &r_moneymax) {
- #pragma unused actorid, skinid, x, y, z, ang, actor_vwid, r_moneymin, r_moneymax
- }
- #pragma deprecated Please use new function name Robbery_CreateActor.
- stock CreateActorRobbery(skinid, Float:x, Float:y, Float:z, Float:ang, actor_vwid = 0, r_moneymin = MIN_MONEY_ROB, r_moneymax = MAX_MONEY_ROB) {
- #pragma unused skinid, x, y, z, ang, actor_vwid, r_moneymin, r_moneymax
- return -1;
- }
- stock Robbery_CreateActor(skinid, Float:x, Float:y, Float:z, Float:ang, actor_vwid = 0, r_moneymin = MIN_MONEY_ROB, r_moneymax = MAX_MONEY_ROB) {
- new actorid = GetActorFreeID();
- if(actorid == -1) {
- print("ERROR: Robbery_CreateActor - MAX_ROBBERY_ACTOR reached, increase the limit size.");
- return -1;
- }
- CreateActor(skinid, x, y, z, ang);
- SetActorVirtualWorld(actorid, actor_vwid);
- robbery_data[actorid][actor_created] = true;
- robbery_data[actorid][actor_skin] = skinid;
- robbery_data[actorid][actor_x] = x;
- robbery_data[actorid][actor_y] = y;
- robbery_data[actorid][actor_z] = z;
- robbery_data[actorid][actor_ang] = ang;
- robbery_data[actorid][actor_vw] = actor_vwid;
- robbery_data[actorid][money_min] = r_moneymin;
- robbery_data[actorid][money_max] = r_moneymax;
- return (i_actor ++);
- }
- /*
- Function:
- Robbery_GetActorData
- Info:
- Retrieves the actor data
- Param:
- * actorid -> ID of robbery actor you want to retrieve data from.
- * &skinid -> Skin ID of the robbery actor
- * &Float:x -> Coordinate X of the robbery actor
- * &Float:y -> Coordinate X of the robbery actor
- * &Float:z -> Coordinate X of the robbery actor
- * &Float:ang -> Facing angle of the robbery actor
- * &actor_vwid -> virtualid of the robbery actor
- * &r_moneymin -> Minimum money to be robbed from the robbery actor
- * &r_moneymax -> Maximum money to be robbed from the robbery actor
- */
- stock Robbery_GetActorData(actorid, &skinid, &Float:x, &Float:y, &Float:z, &Float:ang, &actor_vwid, &r_moneymin, &r_moneymax) {
- if(actorid == INVALID_ACTOR_ID) {
- print("ERROR: GetActorRobberyData - Invalid actorid input.");
- return 1;
- }
- skinid = robbery_data[actorid][actor_skin];
- x = robbery_data[actorid][actor_x];
- y = robbery_data[actorid][actor_y];
- z = robbery_data[actorid][actor_z] ;
- ang = robbery_data[actorid][actor_ang] ;
- actor_vwid = robbery_data[actorid][actor_vw];
- r_moneymin = robbery_data[actorid][money_min];
- r_moneymax = robbery_data[actorid][money_max];
- return 1;
- }
- /*
- Function:
- GetActorFreeID
- Info:
- Retrieves the unused ID of an actor.
- Param:
- None
- */
- static stock GetActorFreeID()
- {
- for(new i = 0; i < MAX_ROBBERY_ACTORS; i++) {
- if(!robbery_data[i][actor_created]) {
- return i;
- }
- }
- return -1;
- }
- /*
- Robbery IMPL
- */
- public RunActorAnimationSequence(playerid, actorid, animation_pattern) {
- switch(animation_pattern) {
- case 0: {
- ClearActorAnimations(actorid);
- ApplyActorAnimation(actorid, "SHOP", "SHP_Rob_HandsUp", 4.1, 0, 1, 1, 1, 0);
- SetTimerEx("RunActorAnimationSequence", 1000 * ROBBERY_WAIT_TIME, false, "iii", playerid, actorid, 1);
- new Float:x, Float:y, Float:z;
- GetPlayerPos(playerid, x, y, z);
- for(new i = 0, j = GetPlayerPoolSize(); i <= j; i++) {
- if(!IsPlayerConnected(i)) {
- continue;
- }
- PlayerPlaySound(i, 3401, x, y, z);
- }
- }
- case 1: {
- if(!IsPlayerInRangeOfPoint(playerid, 10.0, robbery_data[actorid][actor_x], robbery_data[actorid][actor_y], robbery_data[actorid][actor_z])) {
- CallLocalFunction("OnPlayerFinishRobbery", "iiii", playerid, actorid, 0, TYPE_UNFINISHED);
- }
- else {
- ClearActorAnimations(actorid);
- ApplyActorAnimation(actorid, "SHOP", "SHP_Rob_GiveCash", 4.1, 0, 1, 1, 1, 0);
- SetTimerEx("RunActorAnimationSequence", 1000 * ROBBERY_WAIT_TIME, false, "iii", playerid, actorid, 2);
- }
- }
- case 2: {
- ClearActorAnimations(actorid);
- ApplyActorAnimation(actorid, "PED", "DUCK_cower", 4.1, 1, 1, 1, 1, 1);
- SetTimerEx("RunActorAnimationSequence", 1000 * 60 * ROBBERY_WAIT_TIME, false, "iii", playerid, actorid, 3);
- new robberyChance = random(100);
- if(robberyChance > 40) {
- CallLocalFunction("OnPlayerFinishRobbery", "iiii", playerid, actorid, (random(robbery_data[actorid][money_max] - robbery_data[actorid][money_min]) + robbery_data[actorid][money_min]), TYPE_SUCCESS);
- }
- else {
- CallLocalFunction("OnPlayerFinishRobbery", "iiii", playerid, actorid, 0, TYPE_FAILED);
- }
- }
- case 3: {
- ClearActorAnimations(actorid);
- PlayerPlaySound(playerid, 0, 0.0, 0.0, 0.0);
- }
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- EnablePlayerCameraTarget(playerid, 1);
- PreloadAnimLib(playerid, "PED");
- PreloadAnimLib(playerid, "SHOP");
- #if defined actorrob_OnPlayerConnect
- return actorrob_OnPlayerConnect(playerid);
- #else
- return 1;
- #endif
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if((newkeys & KEY_AIM) == KEY_AIM && GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
- {
- switch(GetPlayerWeapon(playerid))
- {
- case 22 .. 33:
- {
- new actorid = GetPlayerCameraTargetActor(playerid);
- if(actorid == INVALID_ACTOR_ID) {
- return 1;
- }
- if(!robbery_data[actorid][actor_created]) {
- // this fixes the issue with normal create actors.
- // there was a bug that you aim at an actor and rob it even though it wasn't created by actor_robbery.
- return 1;
- }
- if(!OnPlayerRequestRobbery(playerid, actorid))
- {
- return 1;
- }
- if(gettime() - robbery_data[actorid][actor_robbedRecently] < 60 * ROBBERY_WAIT_TIME) {
- return CallLocalFunction("OnPlayerStartRobbery", "iii", playerid, actorid, true);
- }
- robbery_data[actorid][actor_robbedRecently] = gettime();
- RunActorAnimationSequence(playerid, actorid, 0);
- CallLocalFunction("OnPlayerStartRobbery", "iii", playerid, actorid, false);
- }
- }
- }
- #if defined actorrob_OnPlayerKeyStateChange
- return actorrob_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
- #else
- return 1;
- #endif
- }
- /* OnPlayerRequestRobbery
- Usage: return 0 to disallow the robbery.
- See test.pwn for example.
- */
- public OnPlayerRequestRobbery(playerid, actorid)
- {
- #if defined actorrob_OnPlayerRequestRobbery
- return actorrob_OnPlayerRequestRobbery(playerid, actorid);
- #else
- return 1; // Default version always wants to returns >1 to allow robbery
- #endif
- }
- //OnPlayerKeyStateChange hook directives
- #if defined _ALS_OnPlayerKeyStateChange
- #undef OnPlayerKeyStateChange
- #else
- #define _ALS_OnPlayerKeyState
- #endif
- #define OnPlayerKeyStateChange actorrob_OnPlayerKeyStateChange
- #if defined actorrob_OnPlayerKeyStateChange
- forward actorrob_OnPlayerKeyStateChange(playerid, newkeys, oldkeys);
- #endif
- //OnPlayerConnect directives
- #if defined _ALS_OnPlayerConnect
- #undef OnPlayerConnect
- #else
- #define _ALS_OnPlayerConnect
- #endif
- #define OnPlayerConnect actorrob_OnPlayerConnect
- #if defined actorrob_OnPlayerConnect
- forward actorrob_OnPlayerConnect(playerid);
- #endif
- //OnPlayerRequestRobbery directives
- #if defined _ALS_OnPlayerRequestRobbery
- #undef OnPlayerRequestRobbery
- #else
- #define _ALS_OnPlayerRequestRobbery
- #endif
- #define OnPlayerRequestRobbery actorrob_OnPlayerRequestRobbery
- #if defined actorrob_OnPlayerRequestRobbery
- forward actorrob_OnPlayerRequestRobbery(playerid);
- #endif
|