10.06.2017, 09:00
Okay so I changed my script a bit so I won't get confused that much, I added stuff you mentioned in link you provided, this is how my code looks like right now:
OnGameModeInit / Exit
Creating the Table - via dialogs
stock
but what the current problem is.. I can't really solve those "errors" I'm getting:
Errors pops out whenever I'm editing the object with "SelectObject" function aka everytime I use the UI that SelectObject provides:
This is my OnPlayerEditObject callback I believe mistakes are in here:
Biggest part is from wiki as I'm using this callback from samp wiki, so can you point me at right direction how to get rid of errors ? :/ what I'm trying to do is, when I place the table at desired location it should message me it's current coordinats x y z etc.
Code:
#define MAX_POKERTABLES 10 #define POKER_TABLE_OBJECT 19474 #define POKER_TABLE_DIST 150.0 #define DIALOG_CREATEPOKER 5000 #define TableBounds(%0,%1); \ if(%0 < 0 || %0 > MAX_POKERTABLES) \ { \ print(%1); \ return 0; \ }
Code:
enum PokerInfo { TableID, ObjectID, Float:PokerX, Float:PokerY, Float:PokerZ, Float:PokerRX, Float:PokerRY, Float:PokerRZ, // stuff below
Code:
public OnGameModeInit() { for(new i = 0; i < MAX_POKERTABLES; i++) { PokerTable[i][ObjectID] = INVALID_OBJECT_ID; } return 1; } public OnGameModeExit() { for(new i = 0; i < MAX_POKERTABLES; i++) { if(PokerTable[i][ObjectID] != INVALID_OBJECT_ID) DestroyObject(PokerTable[i][ObjectID]); } return 1; }
Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) { new Float:x, Float:y, Float:z; GetPlayerPos(playerid, x, y, z); if(dialogid == DIALOG_CREATEPOKER) { if(response) { if(CreatePokerTable(x, y, z) == -1) return SendClientMessage(playerid, 0xFF0000FF, "There are too many tables"); SendClientMessage(playerid, -1, "New table created use /edittable to place it at desired location!!"); } else { SendClientMessage(playerid, -1, "You canceled the poker creating menu!"); } return 1; } return 0; }
Code:
stock CreatePokerTable(Float:x, Float:y, Float:z) { for(new i = 0; i < MAX_POKERTABLES; i++) { if(PokerTable[i][ObjectID] != INVALID_OBJECT_ID) continue; PokerTable[i][ObjectID] = CreateObject(POKER_TABLE_OBJECT, x, y, z, 0.0, 0.0, 0.0, POKER_TABLE_DIST); PokerTable[i][PokerX] = Float:x; PokerTable[i][PokerY] = Float:y; PokerTable[i][PokerZ] = Float:z; return PokerTable[i][ObjectID]; } print("ERROR: Tried to add too many hearts"); return INVALID_OBJECT_ID; }
Code:
[16:47:34] [debug] Accessing element at index 108 past array upper bound 9 [16:47:34] [debug] AMX backtrace: [16:47:34] [debug] #0 0001a284 in public Streamer_OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3fb70000, 0x00000000, 0x00000000, 0x00000000) from Poker.amx [16:47:34] [debug] #1 00019b24 in public OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3fb70000, 0x00000000, 0x00000000, 0x00000000) from Poker.amx [16:47:35] [debug] Run time error 4: "Array index out of bounds" [16:47:35] [debug] Accessing element at index 108 past array upper bound 9 [16:47:35] [debug] AMX backtrace: [16:47:35] [debug] #0 0001a284 in public Streamer_OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3f1ea3d8, 0x00000000, 0x00000000, 0x00000000) from Poker.amx [16:47:35] [debug] #1 00019b24 in public OnPlayerEditObject (0x00000000, 0x00000001, 0x00000001, 0x00000002, 0x43072df4, 0xc291eeb4, 0x3f1ea3d8, 0x00000000, 0x00000000, 0x00000000) from Poker.amx [16:47:35] [debug] Run time error 4: "Array index out of bounds" [16:47:35] [debug] Accessing element at index 108 past array upper bound 9 [16:47:35] [debug] AMX backtrace:
This is my OnPlayerEditObject callback I believe mistakes are in here:
Code:
public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ) { new tableid = PokerTable[tableid][TableID]; new testmsg[600]; new Float:oldX, Float:oldY, Float:oldZ, Float:oldRotX, Float:oldRotY, Float:oldRotZ; GetObjectPos(objectid, oldX, oldY, oldZ); GetObjectRot(objectid, oldRotX, oldRotY, oldRotZ); if(!playerobject) // If this is a global object, sync the position for other players // global = 0 | player = 1 { if(!IsValidObject(objectid)) return 1; SetObjectPos(objectid, fX, fY, fZ); SetObjectRot(objectid, fRotX, fRotY, fRotZ); } if(response == EDIT_RESPONSE_FINAL) { new Float:x, Float:y, Float:z; GetObjectPos(objectid, x, y, z); PokerTable[tableid][PokerX] = Float:x; PokerTable[tableid][PokerY] = Float:y; PokerTable[tableid][PokerZ] = Float:z; new Float:RotX,Float:RotY,Float:RotZ; GetObjectRot(objectid, RotX, RotY, RotZ); PokerTable[tableid][PokerRX] = Float:RotX; PokerTable[tableid][PokerRY] = Float:RotY; PokerTable[tableid][PokerRZ] = Float:RotZ; format(testmsg,sizeof(testmsg),"Table is set at X: %f | Y: %f | Z: %f | RX: %f | RY: %f | RZ: %f",x,y,z,RotX,RotY,RotZ); SendClientMessage(playerid,-1, testmsg); // The player clicked on the save icon // Do anything here to save the updated object position (and rotation) } if(response == EDIT_RESPONSE_CANCEL) { //The player cancelled, so put the object back to it's old position if(!playerobject) //Object is not a playerobject { SetObjectPos(objectid, oldX, oldY, oldZ); SetObjectRot(objectid, oldRotX, oldRotY, oldRotZ); } else { SetPlayerObjectPos(playerid, objectid, oldX, oldY, oldZ); SetPlayerObjectRot(playerid, objectid, oldRotX, oldRotY, oldRotZ); } } return 1; }