Create speedcamera command
#1

Basically I tried to make a command which creates a camera and saves it into a file in scriptfiles/Cameras/cameraid.ini, but as always I massively failed while combining tons of information i found on sa-mp forums ^^
Код:
#define CAMERA_PATH "/Cameras/%d.ini"
#define MAX_CAMERAS 100

enum cInfo
{
	cax,
	cay,
	caz,
	limit,
	cangle
}
new CameraInfo[MAX_CAMERAS][cInfo];

stock CameraPath()
{
    new string[128],cameraid = CameraCount; //line 1438
    format(string,sizeof(string),CAMERA_PATH, cameraid);
    return string;
}
CMD:createcamera(playerid,params[])
{
	if(PlayerInfo[playerid][pLevel] < 3) return error
	if (sscanf(params,"n",limit)) return SendClientMessage(playerid, COLOR_RED,"USAGE: /createcamera <speedlimit>");
	new Float:x,Float:y,Float:z,Float:cangle;
	GetPlayerPos(playerid,x,y,z); //line 1447
	z = z - 1.0;
	GetPlayerFacingAngle(playerid,cangle);
	new INI:File = INI_Open(CameraPath()); //line 1450
	INI_SetTag(File, "Main");
	INI_WriteInt(File, "Limit", limit);
	INI_WriteFloat(File, "X", x);
	INI_WriteFloat(File, "Y", y);
	INI_WriteFloat(File, "Z", z);
	INI_WriteFloat(File, "Angle", cangle);
    INI_Close(File);
    Camera[cameraid] = CreateDynamicObject(18880, x, y, z, 0.0, 0.0, cangle); //line 1458
	SendClientMessage(playerid, COLOR_LIMEGREEN,"Speedcamera created!");
    return 1;
 }
And here are the errors.
Код:
C:\Users\Dorian\Desktop\sa-mp\gamemodes\bhaulers.pwn(1438) : error 017: undefined symbol "CameraCount"
C:\Users\Dorian\Desktop\sa-mp\gamemodes\bhaulers.pwn(1458) : error 017: undefined symbol "Camera"
C:\Users\Dorian\Desktop\sa-mp\gamemodes\bhaulers.pwn(1458) : error 017: undefined symbol "cameraid"
C:\Users\Dorian\Desktop\sa-mp\gamemodes\bhaulers.pwn(1458) : error 029: invalid expression, assumed zero
C:\Users\Dorian\Desktop\sa-mp\gamemodes\bhaulers.pwn(1458) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


5 Errors.
Reply
#2

pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <YSI\y_ini>
#define CAMERA_PATH "/Cameras/%d.ini"
#define MAX_CAMERAS 100
#define error SendClientMessage(playerid, COLOR_RED, "You don't have permission to use this command!");


new cameracount=0;

stock CameraPath()
{
    new string[128],cameraid = cameracount; //line 1438
    format(string,sizeof(string),CAMERA_PATH, cameraid);
    return string;
}

CMD:createcamera(playerid,params[])
{
if(cameracount<MAX_CAMERAS)
{
    if(!IsPlayerAdmin(playerid)) return 0;  //your own level checks here!
    new limit;
    if (sscanf(params,"n",limit)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /createcamera <speedlimit>");
    new Float:x,Float:y,Float:z,Float:cangle;
    GetPlayerPos(playerid,x,y,z); //line 1447
    z = z - 1.0;
    GetPlayerFacingAngle(playerid,cangle);
    new INI:File = INI_Open(CameraPath()); //line 1450
    INI_SetTag(File, "Main");
    INI_WriteInt(File, "Limit", limit);
    INI_WriteFloat(File, "X", x);
    INI_WriteFloat(File, "Y", y);
    INI_WriteFloat(File, "Z", z);
    INI_WriteFloat(File, "Angle", cangle);
    INI_Close(File);
    new Camera = CreateObject(18880, x, y, z, 0.0, 0.0, cangle); //line 1458
    SendClientMessage(playerid,COLOR_LIMEGREEN,"Speedcamera created!");
    cameracount++;
   
}
return 1;
}
pardon the indent!
Reply
#3

i'm sorry if i'm wrong i'm trying to help
define this
#define CameraCount
#define Camera
#define Cameraid
Reply
#4

Quote:
Originally Posted by kartik
Посмотреть сообщение
Need a Semi-colon here?
pawn Код:
if(PlayerInfo[playerid][pLevel] < 3) return error
Nah
Код:
#define error SendClientMessage(playerid, COLOR_RED, "You don't have permission to use this command!");
Quote:
Originally Posted by Rafael_Zambrano
Посмотреть сообщение
i'm sorry if i'm wrong i'm trying to help
define this
#define CameraCount
#define Camera
#define Cameraid
wont work
Reply
#5

Updated !
Reply
#6

Quote:
Originally Posted by kartik
Посмотреть сообщение
Updated !
What?
Reply
#7

Quote:
Originally Posted by kartik
Посмотреть сообщение
pawn Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2>
#include <YSI\y_ini>
#define CAMERA_PATH "/Cameras/%d.ini"
#define MAX_CAMERAS 100
#define error SendClientMessage(playerid, COLOR_RED, "You don't have permission to use this command!");


new cameracount=0;

stock CameraPath()
{
    new string[128],cameraid = cameracount; //line 1438
    format(string,sizeof(string),CAMERA_PATH, cameraid);
    return string;
}

CMD:createcamera(playerid,params[])
{
if(cameracount<MAX_CAMERAS)
{
    if(!IsPlayerAdmin(playerid)) return 0;  //your own level checks here!
    new limit;
    if (sscanf(params,"n",limit)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /createcamera <speedlimit>");
    new Float:x,Float:y,Float:z,Float:cangle;
    GetPlayerPos(playerid,x,y,z); //line 1447
    z = z - 1.0;
    GetPlayerFacingAngle(playerid,cangle);
    new INI:File = INI_Open(CameraPath()); //line 1450
    INI_SetTag(File, "Main");
    INI_WriteInt(File, "Limit", limit);
    INI_WriteFloat(File, "X", x);
    INI_WriteFloat(File, "Y", y);
    INI_WriteFloat(File, "Z", z);
    INI_WriteFloat(File, "Angle", cangle);
    INI_Close(File);
    new Camera = CreateObject(18880, x, y, z, 0.0, 0.0, cangle); //line 1458
    SendClientMessage(playerid,COLOR_LIMEGREEN,"Speedcamera created!");
    cameracount++;
   
}
return 1;
}
pardon the indent!
this !
Reply
#8

Quote:
Originally Posted by kartik
Посмотреть сообщение
this !
Код:
C:\Users\Dorian\Desktop\sa-mp\gamemodes\bhaulers.pwn(1465) : warning 204: symbol is assigned a value that is never used: "Camera"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
Other than this works like a charm.
Reply
#9

I think this might solve your problem:

pawn Код:
#include <a_samp>
#include <sscanf2>
#include <zcmd>
#include <YSI\y_ini>
#include <streamer>

#if defined FILTERSCRIPT
public OnFilterScriptInit()
{
    LoadCameras();
    return 1;
}
#else
public OnGameModeInit()
{
    LoadCameras();
    return 1;
}
#endif

#define CAMERA_PATH "/Cameras/%d.ini"
#define MAX_CAMERAS 100

enum cInfo
{
    Float:cax,
    Float:cay,
    Float:caz,
    limit,
    Float:cangle
}
new CameraInfo[MAX_CAMERAS][cInfo];
new Camera[MAX_CAMERAS];

stock CameraPath(cameraid)
{
    new string[40];
    format(string,sizeof(string), CAMERA_PATH, cameraid);
    return string;
}

CMD:createcamera(playerid,params[])
{
    if(PlayerInfo[playerid][pLevel] < 3) return SendClientMessage(playerid, COLOR_RED, "You must be a level 3+ Administrator to use this command!");
    new slimit;
    if(sscanf(params,"i",slimit)) return SendClientMessage(playerid, COLOR_RED,"USAGE: /createcamera <speedlimit>");
    new Float:x,Float:y,Float:z,Float:pangle;
    GetPlayerPos(playerid,x,y,z); //line 1447
    z -= 1.0;
    GetPlayerFacingAngle(playerid,pangle);
    new nextid = GetNextCameraID();
    if(nextid == -1) return SendClientMessage(playerid, COLOR_RED, "You have reached the maximum amount of speed cameras, please delete one before continuing.");
    new INI:File = INI_Open(CameraPath(nextid)); //line 1450
    INI_SetTag(File, "Main");
    INI_WriteInt(File, "Limit", slimit);
    INI_WriteFloat(File, "X", x);
    INI_WriteFloat(File, "Y", y);
    INI_WriteFloat(File, "Z", z);
    INI_WriteFloat(File, "Angle", pangle);
    INI_Close(File);
    Camera[nextid] = CreateDynamicObject(18880, x, y, z, 0.0, 0.0, pangle); //line 1458
    SendClientMessage(playerid, COLOR_LIMEGREEN,"Speedcamera created!");
    return 1;
 }
 
stock GetNextCameraID()
{
    for(new i = 0; i < MAX_CAMERAS; i++)
    {
        if(fexist(CameraPath(i))) continue;
        return i;
    }
    return -1;
}

stock LoadCameras()
{
    new file[40];
    for(new i = 0; i < MAX_CAMERAS; i++)
    {
        format(file, sizeof(file), CAMERA_PATH, i);
        if(fexist(file))
        {
            INI_ParseFile(file, "LoadCameraData_%s", .bExtra = true, .extra = i);
            Camera[i] = CreateDynamicObject(18880, CameraInfo[i][cax], CameraInfo[i][cay], CameraInfo[i][caz], 0.0, 0.0, CameraInfo[i][cangle]);
        }
    }
    return 1;
}

forward LoadCameraData_Main(cameraid, name[], value[]);
public LoadCameraData_Main(cameraid, name[], value[])
{
    INI_Int("Limit", CameraInfo[cameraid][limit]);
    INI_Float("X", CameraInfo[cameraid][cax]);
    INI_Float("Y", CameraInfo[cameraid][cay]);
    INI_Float("Z", CameraInfo[cameraid][caz]);
    INI_Float("Angle", CameraInfo[cameraid][cangle]);
    return 1;
}
NOTE: The stuff in between the two comments is what I added because I wasn't sure if it was already included.
You need the following includes for this code:
a_samp
streamer
zcmd
sscanf2
y_ini


Took me a while to make, and besides not knowing what is already in your script,will compile with no errors.
Reply
#10

Quote:
Originally Posted by wumpyc
Посмотреть сообщение
Код:
C:\Users\Dorian\Desktop\sa-mp\gamemodes\bhaulers.pwn(1465) : warning 204: symbol is assigned a value that is never used: "Camera"
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


1 Warning.
Other than this works like a charm.
I thought you'd like to track your cameras so left that variable there! Incase you don't need it change
pawn Код:
new Camera=CreateObject
to
CreateObject...
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)