Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************************************************
- ____ _
- / __ )_____(_)___ _____
- / __ / ___/ / __ `/ __ \
- / /_/ / / / / /_/ / / / /
- /_____/_/ /_/\__,_/_/ /_/
- Ingame Holding Object editor v1.1 (for SetPlayerHoldingObject)
- (25th August, 2010), by Brian (Resident Kangaroo)
- Sharing is caring, but don't rip (not that I can see this really being
- ripped, it's not going to find much use in a gamemode).
- Updated with sscanf stock (rather than the plugin), textdraws, and
- a command (/bone) to switch bones while editing.
- *******************************************************************************/
- #define FILTERSCRIPT
- #include <a_samp>
- #include <zcmd>
- /******************************************************
- *** objectOffsets information (axes), for reference ***
- *******************************************************
- >> [0] = OffsetX
- >> [1] = OffsetY
- >> [2] = OffsetZ
- >> [3] = RotationX
- >> [4] = RotationY
- >> [5] = RotationZ
- ******************************************************/
- new Float:objectOffsets[MAX_PLAYERS][6], editingObject[MAX_PLAYERS], editingBone[MAX_PLAYERS],
- editingAxis[MAX_PLAYERS], editingStatus[MAX_PLAYERS], movedObject[MAX_PLAYERS], Text:PosText[MAX_PLAYERS];
- new atext[16] = "X offset";
- stock SaveObj(comment[], playerid)
- {
- new File: objfile;
- if(!fexist("savedobjs.txt"))
- {
- objfile = fopen("savedobjs.txt", io_write);
- if (objfile) { fclose(objfile); }
- }
- new string[256];
- format(string,sizeof(string),"SetPlayerHoldingObject(playerid, %d, %d, %f, %f, %f, %f, %f, %f); // %s\n",editingObject[playerid],
- editingBone[playerid],objectOffsets[playerid][0],objectOffsets[playerid][1],objectOffsets[playerid][2],objectOffsets[playerid][3],
- objectOffsets[playerid][4],objectOffsets[playerid][5],comment);
- objfile = fopen("savedobjs.txt", io_append);
- fwrite(objfile, string);
- fclose(objfile);
- }
- public OnPlayerConnect(playerid)
- {
- PosText[playerid] = TextDrawCreate(240.0,580.0," ");
- for(new i = 0; i < 6; i++) { objectOffsets[playerid][i] = 0.0; }
- editingObject[playerid] = -1;
- editingStatus[playerid] = 0;
- editingBone[playerid] = -1;
- editingAxis[playerid] = -1;
- return 1;
- }
- cmd(bone,playerid,params[])
- {
- if(editingStatus[playerid] != 1) return SendClientMessage(playerid,0xFFFFFFFF,"You're not editing an object.");
- new bone, string[64];
- if(sscanf(params,"d",bone)) return SendClientMessage(playerid,0xFFFFFFFF,"SYNTAX: /bone (bone ID 0-18).");
- else if(bone < 1 || bone > 18) return SendClientMessage(playerid,0xFFFFFFFF,"Invalid bone specified.");
- else editingBone[playerid] = bone;
- format(string,sizeof(string),"You are now editing object %d on bone %d.",editingObject[playerid], editingBone[playerid]);
- SendClientMessage(playerid,0xFFFFFFFF,string);
- SetPlayerHoldingObject(playerid, editingObject[playerid], editingBone[playerid], objectOffsets[playerid][0], objectOffsets[playerid][1],
- objectOffsets[playerid][2], objectOffsets[playerid][3], objectOffsets[playerid][4], objectOffsets[playerid][5]);
- return 1;
- }
- cmd(preview,playerid,params[])
- {
- #pragma unused params
- switch(editingStatus[playerid])
- {
- case 1:
- {
- SendClientMessage(playerid,0xFFFFFFFF,"You are now previewing the object; use /preview again to resume editing.");
- TogglePlayerControllable(playerid, 1);
- editingStatus[playerid] = 2;
- }
- case 2:
- {
- SendClientMessage(playerid,0xFFFFFFFF,"Preview finished.");
- TogglePlayerControllable(playerid, 0);
- editingStatus[playerid] = 1;
- }
- default: SendClientMessage(playerid,0xFFFFFFFF,"You're not editing/previewing an object.");
- }
- return 1;
- }
- cmd(editorhelp,playerid,params[])
- {
- #pragma unused params
- SendClientMessage(playerid,0xFFFFFFFF,"Available commands: /editor, /saveobj, /preview, /bone.");
- return 1;
- }
- cmd(saveobj,playerid,params[])
- {
- new string[128];
- if(!editingStatus[playerid]) return SendClientMessage(playerid,0xFFFFFFFF,"You're not editing/previewing an object.");
- if(sscanf(params,"s",string)) return SendClientMessage(playerid,0xFFFFFFFF,"SYNTAX: /saveobj (comment).");
- SaveObj(string, playerid);
- SendClientMessage(playerid,0xFFFFFFFF,"Object saved to 'scriptfiles/savedobjs.txt'.");
- return 1;
- }
- cmd(editor,playerid,params[])
- {
- new string[128], object, bone;
- if(editingStatus[playerid])
- {
- TextDrawHideForPlayer(playerid, PosText[playerid]);
- SendClientMessage(playerid,0xFFFFFFFF,"You have stopped editing. Last object settings:");
- format(string,sizeof(string),"Object %d | Bone %d | Offset (XYZ) %f, %f, %f | Rotation (XYZ) %f, %f, %f",editingObject[playerid],
- editingBone[playerid],objectOffsets[playerid][0],objectOffsets[playerid][1],objectOffsets[playerid][2],objectOffsets[playerid][3],
- objectOffsets[playerid][4],objectOffsets[playerid][5]);
- SendClientMessage(playerid,0xFFFFFFFF,string);
- StopPlayerHoldingObject(playerid);
- editingObject[playerid] = -1;
- editingStatus[playerid] = 0;
- editingBone[playerid] = -1;
- editingAxis[playerid] = -1;
- for(new i = 0; i < 6; i++) { objectOffsets[playerid][i] = 0.0; }
- TogglePlayerControllable(playerid,1);
- return 1;
- }
- if(sscanf(params,"dd",object,bone))
- {
- SendClientMessage(playerid,0xFFFFFFFF,"SYNTAX: /editor (object ID) (bone 0-18).");
- return 1;
- }
- if(bone < 1 || bone > 18) return SendClientMessage(playerid,0xFFFFFFFF,"Invalid bone specified.");
- TextDrawShowForPlayer(playerid, PosText[playerid]);
- editingObject[playerid] = object; editingBone[playerid] = bone; editingStatus[playerid] = 1;
- SetPlayerHoldingObject(playerid, editingObject[playerid], editingBone[playerid], objectOffsets[playerid][0], objectOffsets[playerid][1],
- objectOffsets[playerid][2], objectOffsets[playerid][3], objectOffsets[playerid][4], objectOffsets[playerid][5]);
- format(string,sizeof(string),"Editing object %d, bone %d - use up/down to adjust the value, and left/right to switch the axis.",object,bone);
- TogglePlayerControllable(playerid,0);
- SendClientMessage(playerid,0xFFFFFFFF,string);
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- if(editingStatus[playerid] == 1)
- {
- new string[128];
- if(movedObject[playerid] > 0)
- {
- SetPlayerHoldingObject(playerid, editingObject[playerid], editingBone[playerid], objectOffsets[playerid][0], objectOffsets[playerid][1],
- objectOffsets[playerid][2], objectOffsets[playerid][3], objectOffsets[playerid][4], objectOffsets[playerid][5]);
- movedObject[playerid]--;
- }
- new keys, updown, leftright;
- GetPlayerKeys(playerid,keys,updown,leftright);
- if(updown > 0)
- {
- if(editingAxis[playerid] < 3) objectOffsets[playerid][editingAxis[playerid]] -= 0.01;
- else objectOffsets[playerid][editingAxis[playerid]] -= 1.0;
- movedObject[playerid] = 500;
- }
- else if(updown < 0)
- {
- if(editingAxis[playerid] < 3) objectOffsets[playerid][editingAxis[playerid]] += 0.01;
- else objectOffsets[playerid][editingAxis[playerid]] += 1.0;
- movedObject[playerid] = 500;
- }
- if(leftright > 0)
- {
- if(editingAxis[playerid] != 0) editingAxis[playerid]--;
- else editingAxis[playerid] = 5;
- switch(editingAxis[playerid])
- {
- case 0: atext = "X offset";
- case 1: atext = "Y offset";
- case 2: atext = "Z offset";
- case 3: atext = "X rotation";
- case 4: atext = "Y rotation";
- case 5: atext = "Z rotation";
- }
- }
- else if(leftright < 0)
- {
- if(editingAxis[playerid] != 5) editingAxis[playerid]++;
- else editingAxis[playerid] = 0;
- switch(editingAxis[playerid])
- {
- case 0: atext = "X offset";
- case 1: atext = "Y offset";
- case 2: atext = "Z offset";
- case 3: atext = "X rotation";
- case 4: atext = "Y rotation";
- case 5: atext = "Z rotation";
- }
- }
- if(editingAxis[playerid] < 3) { format(string,sizeof(string),"~r~%s~n~~w~%f, %f, %f~n~~b~Object %d, bone %d",atext,objectOffsets[playerid][0],objectOffsets[playerid][1],objectOffsets[playerid][2], editingObject[playerid], editingBone[playerid]); }
- else { format(string,sizeof(string),"~r~%s~n~~w~%f, %f, %f~n~~b~Object %d, bone %d",atext,objectOffsets[playerid][3], objectOffsets[playerid][4],objectOffsets[playerid][5], editingObject[playerid], editingBone[playerid]); }
- TextDrawSetString(PosText[playerid], string);
- }
- return 1;
- }
- public OnPlayerDisconnect (playerid)
- {
- TextDrawDestroy(PosText[playerid]);
- return 1;
- }
- stock sscanf(string[], format[], {Float,_}:...)
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = string[stringPos];
- do
- {
- stringPos++;
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new changestr[16], changepos = 0, strpos = stringPos;
- while(changepos < 16 && string[strpos] && string[strpos] != delim)
- {
- changestr[changepos++] = string[strpos++];
- }
- changestr[changepos] = '\0';
- setarg(paramPos,0,_:floatstr(changestr));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement