Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- #include <streamer>
- //Graffiti system by Arthur Kane
- //October 25, 2017
- #define PRESSED(%0) \
- (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
- #define RELEASED(%0) \
- (((newkeys & (%0)) != (%0)) && ((oldkeys & (%0)) == (%0)))
- #define DIALOG_GRAFFITI_MENU (888)
- enum E_GRAFFITI_INFO
- {
- Float: graffitiPos_X,
- Float: graffitiPos_Y,
- Float: graffitiPos_Z,
- Float: graffitiRot_X,
- Float: graffitiRot_Y,
- Float: graffitiRot_Z
- }
- new g_aGraffitiInfo[][E_GRAFFITI_INFO] =
- {
- {2081.867675, -1255.466430, 24.712007, -12.800003, 0.000000, 0.000000},
- {2268.340332, -1031.824707, 53.437198, 0.000000, 0.000000, 135.800155}
- };
- new g_GraffitiObject[sizeof g_aGraffitiInfo];
- public OnFilterScriptInit()
- {
- for(new i; i < sizeof g_aGraffitiInfo; i++)
- {
- g_GraffitiObject[i] = CreateDynamicObject(18666, g_aGraffitiInfo[i][graffitiPos_X], g_aGraffitiInfo[i][graffitiPos_Y], g_aGraffitiInfo[i][graffitiPos_Z], g_aGraffitiInfo[i][graffitiRot_X], g_aGraffitiInfo[i][graffitiRot_Y], g_aGraffitiInfo[i][graffitiRot_Z], -1, 0, -1, 6000.0);
- }
- print("Graffiti system is live.");
- return 1;
- }
- new playerGraffitiTimer[ MAX_PLAYERS ];
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
- {
- if(PRESSED( KEY_FIRE ) && GetPlayerWeapon(playerid) == WEAPON_SPRAYCAN && GetPVarInt(playerid, "SprayingGraffiti") == 0)
- {
- new
- bool: nearGraffiti;
- for(new i; i < sizeof g_aGraffitiInfo; i++)
- {
- if(IsPlayerInRangeOfPoint(playerid, 2.0, g_aGraffitiInfo[i][graffitiPos_X], g_aGraffitiInfo[i][graffitiPos_Y], g_aGraffitiInfo[i][graffitiPos_Z]))
- {
- nearGraffiti = true;
- SetPVarInt( playerid, "SprayingGraffiti", 1 );
- SetPVarInt( playerid, "NearGraffitiID", i );
- }
- }
- if(nearGraffiti)
- playerGraffitiTimer [ playerid ] = SetTimerEx("OnPlayerSpraying", 1000, true, "i", playerid);
- }
- if(RELEASED( KEY_FIRE ) && GetPlayerWeapon(playerid) == WEAPON_SPRAYCAN && GetPVarInt(playerid, "SprayingGraffiti") == 1)
- {
- KillTimer( playerGraffitiTimer[playerid] );
- DeletePVar( playerid, "SprayingGraffiti" );
- DeletePVar( playerid, "NearGraffitiID" );
- GameTextForPlayer(playerid, "~w~] ~n~~r~Stopped", 3000, 5);
- }
- return 1;
- }
- //Default Commands:
- CMD:graffiti(playerid, params[])
- {
- ShowPlayerDialog(playerid, DIALOG_GRAFFITI_MENU, DIALOG_STYLE_INPUT, "Graffiti Menu:", "These graffitis support color codes. Use:\nNew line (n), Black (b), Brown(br) Red (r), Blue (bl), Green (g), Orange (o), White (w), Yellow (y), Maroon (mr) before your text.\n\nEnter your graffitis text:", "Select", "Cancel");
- return 1;
- }
- CMD:getcan(playerid, params[])
- {
- GivePlayerWeapon( playerid, WEAPON_SPRAYCAN, 99999 );
- return 1;
- }
- //Admin Commands:
- new playerGraffitiObject[ MAX_PLAYERS ];
- CMD:makegraffiti(playerid, params[])
- {
- if(GetPVarInt(playerid, "MakingGraffiti") > 0)
- return SendClientMessage(playerid, -1, "You already have a graffiti object spawned.");
- new
- Float: myPos[3];
- GetPlayerPos(playerid, myPos[0], myPos[1], myPos[2]);
- SetPVarInt(playerid, "MakingGraffiti", 1);
- playerGraffitiObject[playerid] = CreateDynamicObject(18666, myPos[0], myPos[1], myPos[2], 0.0, 0.0, 0.0);
- EditDynamicObject(playerid, playerGraffitiObject[playerid]);
- SendClientMessage(playerid, -1, "Instructions:");
- SendClientMessage(playerid, -1, "Set your graffiti at a wall and adjust the rotations properly so you see the front.");
- SendClientMessage(playerid, -1, "Once you're done, press Save on the GUI and the coordinates will be printed in server_log.txt.");
- return 1;
- }
- //
- public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
- {
- if(GetPVarInt(playerid, "MakingGraffiti") == 1)
- {
- if(response == EDIT_RESPONSE_CANCEL)
- {
- DestroyDynamicObject(playerGraffitiObject[playerid]);
- DeletePVar(playerid, "MakingGraffiti");
- SendClientMessage(playerid, -1, "You cancelled your graffiti.");
- }
- else if(response == EDIT_RESPONSE_FINAL)
- {
- DestroyDynamicObject(playerGraffitiObject[playerid]);
- DeletePVar(playerid, "MakingGraffiti");
- SendClientMessage(playerid, -1, "Your graffitis coordinates have been printed in the server_log.");
- printf("{%f, %f, %f, %f, %f, %f}", x, y, z, rx, ry, rz);
- }
- }
- return 1;
- }
- //
- forward OnPlayerSpraying(playerid);
- public OnPlayerSpraying(playerid)
- {
- new sprayCounter, sprayingGraffiti;
- new counter[60], graffitiText[65];
- sprayCounter = GetPVarInt( playerid, "GraffitiLength" );
- sprayingGraffiti = GetPVarInt( playerid, "NearGraffitiID" );
- GetPVarString(playerid, "GraffitiText", graffitiText, sizeof graffitiText);
- if(IsPlayerInRangeOfPoint(playerid, 2.0, g_aGraffitiInfo[sprayingGraffiti][graffitiPos_X], g_aGraffitiInfo[sprayingGraffiti][graffitiPos_Y], g_aGraffitiInfo[sprayingGraffiti][graffitiPos_Z]))
- {
- sprayCounter--;
- SetPVarInt(playerid, "GraffitiLength", sprayCounter);
- format(counter, sizeof counter, "~r~Spraying~n~~w~%d]", sprayCounter);
- GameTextForPlayer(playerid, counter, 3000, 3);
- if(sprayCounter <= 0)
- {
- strreplace(graffitiText, "(n)", "\n");
- strreplace(graffitiText, "(o)", "{FF8B00}");
- strreplace(graffitiText, "(br)", "{5B3F01}");
- strreplace(graffitiText, "(bl)", "{0000FF}");
- strreplace(graffitiText, "(b)", "{000000}");
- strreplace(graffitiText, "(g)", "{008000}");
- strreplace(graffitiText, "(w)", "{FFFFFF}");
- strreplace(graffitiText, "(y)", "{FFFF00}");
- strreplace(graffitiText, "(r)", "{FF0000}");
- strreplace(graffitiText, "(mr)", "{800000}");
- SetDynamicObjectMaterialText(g_GraffitiObject[sprayingGraffiti], 0, graffitiText, OBJECT_MATERIAL_SIZE_256x256, "Arial", 27, 1, 0xFFFFFFFF, 0, 1);
- GameTextForPlayer(playerid, "~g~Sprayed~n~ ~w~]", 2000, 3);
- SetPVarInt(playerid, "GraffitiLength", GetPVarInt(playerid, "GraffitiLengthSave"));
- DeletePVar(playerid, "NearGraffitiID");
- DeletePVar(playerid, "SprayingGraffiti");
- KillTimer(playerGraffitiTimer[playerid]);
- }
- }
- else
- {
- SetPVarInt(playerid, "GraffitiLength", GetPVarInt(playerid, "GraffitiLengthSave"));
- DeletePVar(playerid, "NearGraffitiID");
- DeletePVar(playerid, "SprayingGraffiti");
- KillTimer(playerGraffitiTimer[playerid]);
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if( dialogid == DIALOG_GRAFFITI_MENU )
- {
- if(response)
- {
- if(strlen(inputtext) > 60 || strlen(inputtext) < 2)
- return cmd_graffiti(playerid, "");
- SetPVarInt(playerid, "GraffitiLength", strlen(inputtext));
- SetPVarInt(playerid, "GraffitiLengthSave", strlen(inputtext));
- SetPVarString(playerid, "GraffitiText", inputtext);
- new
- text[63];
- SendClientMessage(playerid, 0xFF6347FF, "You set your graffiti text. You can now spray at a graffiti.");
- format(text, sizeof text, "%s", inputtext);
- SendClientMessage(playerid, -1, text);
- }
- else SendClientMessage(playerid, -1, "Cancelled!");
- return 1;
- }
- return 0;
- }
- stock strreplace(string[], const search[], const replacement[], bool:ignorecase = false, pos = 0, limit = -1, maxlength = sizeof(string)) {
- // No need to do anything if the limit is 0.
- if (limit == 0)
- return 0;
- new
- sublen = strlen(search),
- replen = strlen(replacement),
- bool:packed = ispacked(string),
- maxlen = maxlength,
- len = strlen(string),
- count = 0
- ;
- // "maxlen" holds the max string length (not to be confused with "maxlength", which holds the max. array size).
- // Since packed strings hold 4 characters per array slot, we multiply "maxlen" by 4.
- if (packed)
- maxlen *= 4;
- // If the length of the substring is 0, we have nothing to look for..
- if (!sublen)
- return 0;
- // In this line we both assign the return value from "strfind" to "pos" then check if it's -1.
- while (-1 != (pos = strfind(string, search, ignorecase, pos))) {
- // Delete the string we found
- strdel(string, pos, pos + sublen);
- len -= sublen;
- // If there's anything to put as replacement, insert it. Make sure there's enough room first.
- if (replen && len + replen < maxlen) {
- strins(string, replacement, pos, maxlength);
- pos += replen;
- len += replen;
- }
- // Is there a limit of number of replacements, if so, did we break it?
- if (limit != -1 && ++count >= limit)
- break;
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment