SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 19/08/2019, 10:58 AM   #1
GnT
Big Clucker
 
Join Date: Oct 2017
Location: Los Santos
Posts: 63
Reputation: 0
Default Command amx backtrace

Hello. I have a problem with command /goto <name/id> and I don't know how to solve it. Here is the error:

Code:
[23:26:47] Bobo[ID: 2] used command /goto  1.
[23:26:47] [debug] Run time error 4: "Array index out of bounds"
[23:26:47] [debug]  Accessing element at negative index -400
[23:26:47] [debug] AMX backtrace:
[23:26:47] [debug] #0 001b8aec in public cmd_goto (2, 36216760) from ryse.amx
[23:26:47] [debug] #1 native CallLocalFunction () from samp03svr
[23:26:47] [debug] #2 00008738 in public OnPlayerCommandText (2, 36216724) from ryse.amx
This is the command:

Code:
CMD:goto(playerid, params[]) {
	if(gPlayerLogged[playerid] == 0) return SCM(playerid, COLOR_LIGHTRED, "You need to login first.");
	if(PlayerInfo[playerid][pAdmin] < 1) return SCM(playerid, COLOR_RED2, AdminOnly);
	new id;
	if(sscanf(params, "u", id)) return SCM(playerid, 0xFFFFFFFF, "{CF0000}Usage: {FFFFFF}/goto <Name/Playerid>"); 
	if(IsPlayerConnected(id)) {
		if(id == playerid) return SCM(playerid, COLOR_GREY, "You can't use this yourself.");
	    if(TutTime[id] >= 1) return SCM(playerid, COLOR_GREY, "This player is currently in the tutorial.");
		new Float:ax,Float:ay,Float:az, countx, Float:x, Float:y, Float:z;
		GetPlayerPos(playerid,ax,ay,az);
		GetPlayerPos(id, x, y, z);
		posxxx[playerid] = ax;
		posyyy[playerid] = ay;
		poszzz[playerid] = az;    
		if(GetPlayerState(playerid) == 2) {
			new car = GetPlayerVehicleID(playerid);
			SetVehiclePos(car, x, y+4, z);
			GetVehiclePos(car, old_veh_pos[car][0], old_veh_pos[car][1], old_veh_pos[car][2]);
			LinkVehicleToInterior(car, GetPlayerInterior(id));
			SetVehicleVirtualWorld(car, GetPlayerVirtualWorld(id));
			OnPlayerGoto(playerid, GetPlayerInterior(id), GetPlayerVirtualWorld(id));
		}
		else {
			if(GetPlayerState(id) == 2 || GetPlayerState(id) == 3) {
				if(MaxSeats[GetVehicleModel(GetPlayerVehicleID(id))-400] > 0) {
					for(new xx = 0; xx < MaxSeats[GetVehicleModel(GetPlayerVehicleID(id))-400]; xx++) {
						if(!IsSeatTaken(GetPlayerVehicleID(id), xx)) {
							PutPlayerInVehicleEx(playerid, GetPlayerVehicleID(id), xx);
							countx++;
							break;
						}
					}
				}
				else SetPlayerPosEx(playerid, x, y+2, z);
			}
			else SetPlayerPosEx(playerid, x, y+2, z);
			if(countx == 0) SetPlayerPosEx(playerid, x , y+2, z);
		}  
		SetPlayerVirtualWorld(playerid, GetPlayerVirtualWorld(id));
		SetPlayerInterior(playerid, GetPlayerInterior(id));
		if(InHouse[id] > -1) {
			InHouse[playerid] = InHouse[id];
			if(strlen(housestring[InHouse[playerid]]) > 0) {
			    StopAudioStreamForPlayer(playerid);
				PlayAudioStreamForPlayer(playerid, housestring[InHouse[playerid]]);
			}
		}
		else InHouse[playerid] = -1;	
		if(InHQ[id] > -1) InHQ[playerid] = InHQ[id];
		else InHQ[playerid] = -1;
		if(InBussines[id] > -1) InBussines[playerid] = InBussines[id];
		else InBussines[playerid] = -1;
		PlayerInfo[playerid][pLocal] = PlayerInfo[id][pLocal];
		new string[128];
		format(string,sizeof(string),"You have been teleported to %s[%d].",GetName(id), id);
		SCM(playerid, COLOR_GRAD1, string);
		format(string,sizeof(string),"Admin %s[%d] teleported to you.",GetName(playerid),playerid);
		SCM(id, COLOR_GRAD1, string);
		format(string,sizeof(string),"({CC0000}Admin Info{FFFFFF}) %s[%d] used /goto on %s[%d].",GetName(playerid),playerid,GetName(id),id);
		ABroadCast(COLOR_WHITE,string,1);
	}
	else return SCM(playerid, COLOR_GREY, "Player not connected."); 
	return 1;
}

// VEHICLE SEATS
new MaxSeats[212] = {
4,2,2,2,4,4,1,2,2,4,2,2,2,4,2,2,4,2,4,2,4,4,2,2,2,1,4,4,4,2,1,9,1,2,2,1,2,9,4,2,
4,1,2,2,2,4,1,2,1,6,1,2,1,1,1,2,2,2,4,4,2,2,2,2,2,2,4,4,2,2,4,2,1,1,2,2,1,2,2,4,
2,1,4,3,1,1,1,4,2,2,4,2,4,1,2,2,2,4,4,2,2,2,2,2,2,2,2,4,2,1,1,2,1,1,2,2,4,2,2,1,
1,2,2,2,2,2,2,2,2,4,1,1,1,2,2,2,2,0,0,1,4,2,2,2,2,2,4,4,2,2,4,4,2,1,2,2,2,2,2,2,
4,4,2,2,1,2,4,4,1,0,0,1,1,2,1,2,2,2,2,4,4,2,4,1,1,4,2,2,2,2,6,1,2,2,2,1,4,4,4,2,
2,2,2,2,4,2,1,1,1,4,1,1
};
If you have any ideas
GnT is offline   Reply With Quote
Old 19/08/2019, 04:16 PM   #2
Nero_3D
High-roller
 
Nero_3D's Avatar
 
Join Date: Jun 2007
Location: Germany
Posts: 2,837
Reputation: 671
Default Re: Command amx backtrace

Aside from the strange shape of the code, there are only two places where the runtime error could happen and both use the same code
pawn Code:
MaxSeats[GetVehicleModel(GetPlayerVehicleID(id))-400]

Make sure that GetVehicleModel did return a valid modelid
If you want to find out why it happens, debug your code
Nero_3D is offline   Reply With Quote
Old 19/08/2019, 04:47 PM   #3
TheToretto
Gangsta
 
TheToretto's Avatar
 
Join Date: Jul 2015
Posts: 586
Reputation: 66
Default Re: Command amx backtrace

Add a check before anything.

pawn Code:
if(!car) return 0;

because if the player isn't in a vehicle, Model ID would return 0 so the array would translate to:

pawn Code:
MaxSeats[-400]

Code:
[23:26:47] [debug]  Accessing element at negative index -400

(The vehicle's model ID, or 0 if the vehicle doesn't exist. (source wiki.sa-mp.com))
__________________






Toretto#9902

Rest in peace grandpa, 03 November 2018
TheToretto is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
AMX Backtrace PepsiCola23 Scripting Help 0 09/02/2018 12:36 PM
AMX backtrace Youssef221 Scripting Help 1 13/11/2014 05:57 PM
AMX Backtrace Ph0eniX Scripting Help 1 17/08/2014 06:22 PM
Amx Backtrace! nguyenquynh Scripting Help 9 03/09/2013 08:04 PM


All times are GMT. The time now is 09:33 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.