Gate placer doest work. Help pls! -
qkac1234 - 31.07.2013
Hi!
I've modifed a script because I want to choose the gate's object.
So it complied wihtout errors or warnings, but when i use /placegate [!] and it says Succesfully placed a gate, but doesnt place it (edited). I've tried with some objects and it isnt under the ground... How can i fix this bug?
Код:
#include a_samp
#include zcmd
#include Dini
#define DIALOG_x 1
#define MAX_GATES 20
//#define GATE_OBJECT 980
#define GATE_STATE_CLOSED 0
#define GATE_STATE_OPEN 1
new GATE_OBJECT;
enum fs_gates
{
gCreated,
Float:gX,
Float:gY,
Float:gZ,
Float:gA,
gObject,
gPlacedBy[24],
gStatus,
gPassword
}
new GateInfo[MAX_GATES][fs_gates];
COMMAND:model(playerid, params[])
{
ShowPlayerDialog(playerid, DIALOG_x, DIALOG_STYLE_INPUT, "GATE'S MODEL:", "Type it:", "Submit", "Cancel");
return 1;
}
CMD:placegate( playerid, params[] )
{
if( isnull( params) )
return SendClientMessage( playerid, -1, "Syntax: /placegate [password]" );
if( !strval( params ) )
return SendClientMessage( playerid, -1, "You need to input numbers." );
if( IsPlayerInAnyVehicle( playerid ) )
return SendClientMessage( playerid, -1, "You need to exit your vehicle." );
new Float:pPos[4];
GetPlayerPos( playerid, pPos[0], pPos[1], pPos[2] );
GetPlayerFacingAngle( playerid, pPos[3] );
CreateGate( playerid, strval( params ), pPos[0], pPos[1], pPos[2], pPos[3] );
SendClientMessage( playerid, -1, "You succesfully created a movable gate. Use /gopen or /gclose." );
return 1;
}
CMD:gopen( playerid, params[] )
{
if( isnull( params ) )
return SendClientMessage( playerid, -1, "Syntax: /gopen [password]" );
new szName[24], gate = -1;
GetPlayerName( playerid, szName, 24 );
for( new i = 0; i != MAX_GATES; i++ )
if( GateInfo[i][gCreated] == 1 )
if( strval( params ) == GateInfo[i][gPassword] )
{ gate = i; break; }
if( gate != -1 )
{
if( !IsObjectMoving( GateInfo[gate][gObject] ) )
{
if( IsPlayerInRangeOfPoint( playerid, 10.0, GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ] ) )
{
if( GateInfo[gate][gStatus] == GATE_STATE_CLOSED )
{
MoveObject( GateInfo[gate][gObject], GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ]-5.3, 7.0 );
SendClientMessage( playerid, -1, "You opened the gate." );
}
else
return SendClientMessage( playerid, -1, "The gate is already open." );
}
else
return SendClientMessage( playerid, -1, "You're not near any gate." );
}
else
return SendClientMessage( playerid, -1, "You must wait untill the gate has moved." );
}
else
return SendClientMessage( playerid, -1, "Invalid password." );
return 1;
}
CMD:gclose( playerid, params[] )
{
if( isnull( params ) )
return SendClientMessage( playerid, -1, "Syntax: /gclose [password]" );
new szName[24], gate = -1;
GetPlayerName( playerid, szName, 24 );
for( new i = 0; i != MAX_GATES; i++ )
if( GateInfo[i][gCreated] == 1 )
if( strval( params ) == GateInfo[i][gPassword] )
{ gate = i; break; }
if( gate != -1 )
{
if( !IsObjectMoving( GateInfo[gate][gObject] ) )
{
if( IsPlayerInRangeOfPoint( playerid, 10.0, GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ] ) )
{
if( GateInfo[gate][gStatus] == GATE_STATE_OPEN )
{
MoveObject( GateInfo[gate][gObject], GateInfo[gate][gX], GateInfo[gate][gY], GateInfo[gate][gZ]+5.3, 7.0 );
SendClientMessage( playerid, -1, "You closed the gate." );
}
else
return SendClientMessage( playerid, -1, "The gate is already closed." );
}
else
return SendClientMessage( playerid, -1, "You're not near any gate." );
}
else
return SendClientMessage( playerid, -1, "You must wait untill the gate has moved." );
}
else
return SendClientMessage( playerid, -1, "Invalid password." );
return 1;
}
CMD:removegate( playerid, params[] )
{
for( new i = 0; i != MAX_GATES; i++ )
{
if( GateInfo[i][gCreated] == 1 )
{
if( IsPlayerInRangeOfPoint( playerid, 10.0, GateInfo[i][gX], GateInfo[i][gY], GateInfo[i][gZ] ) )
{
new szName[24];
GetPlayerName( playerid, szName, 24 );
if( !strcmp( szName, GateInfo[i][gPlacedBy], true ) || IsPlayerAdmin( playerid ) )
{
DestroyObject( GateInfo[i][gObject] );
format( GateInfo[i][gPlacedBy], 24, "None" );
GateInfo[i][gCreated] = 0;
GateInfo[i][gX] = 0.0;
GateInfo[i][gY] = 0.0;
GateInfo[i][gZ] = 0.0;
GateInfo[i][gA] = 0.0;
GateInfo[i][gPassword] = 0;
GateInfo[i][gStatus] = GATE_STATE_CLOSED;
SendClientMessage( playerid, -1, "You removed the gate." );
new file[32];
format( file, 32, "Gates/gate_%d.ini", i );
if( dini_Exists( file ) )
dini_Remove( file );
break;
}
else
return SendClientMessage( playerid, -1, "You don't own this gate." );
}
else
return SendClientMessage( playerid, -1, "You're not near any gate." );
}
}
return 1;
}
CMD:gateinfo( playerid, params[] )
{
if( IsPlayerAdmin( playerid ) )
{
for( new i = 0; i != MAX_GATES; i++ )
{
if( GateInfo[i][gCreated] == 1 )
{
if( IsPlayerInRangeOfPoint( playerid, 5.0, GateInfo[i][gX], GateInfo[i][gY], GateInfo[i][gZ] ) )
{
new szString[128];
format( szString, 128, "Gate Info( Placed by: %s | Password: %d)", GateInfo[i][gPlacedBy], GateInfo[i][gPassword] );
SendClientMessage( playerid, -1, szString );
return 1;
}
else
return SendClientMessage( playerid, -1, "You're not near any gate." );
}
}
}
else
return SendClientMessage( playerid, -1, "You're not an admin." );
return 1;
}
public OnFilterScriptInit( )
{
for( new i = 0; i != MAX_GATES; i++ )
{
if( GateInfo[i][gCreated] == 0 )
{
new file[64];
format( file, 64, "Gates/gate_%d.ini", i );
if( fexist( file ) )
{
GateInfo[i][gCreated] = 1;
GateInfo[i][gX] = dini_Float( file, "X" );
GateInfo[i][gY] = dini_Float( file, "Y" );
GateInfo[i][gZ] = dini_Float( file, "Z" );
GateInfo[i][gA] = dini_Float( file, "A" );
GateInfo[i][gStatus] = dini_Int( file, "Status" );
GateInfo[i][gPassword] = dini_Int( file, "Password" );
format( GateInfo[i][gPlacedBy], 24, dini_Get( file, "PlacedBy" ) );
GateInfo[i][gObject] = CreateObject( GATE_OBJECT, GateInfo[i][gX], GateInfo[i][gY], GateInfo[i][gZ], 0, 0, GateInfo[i][gA] );
}
}
}
return 1;
}
public OnFilterScriptExit( )
{
for( new i = 0; i != MAX_GATES; i++ )
{
if( GateInfo[i][gCreated] == 1 )
{
new file[64];
format( file, 64, "Gates/gate_%d.ini", i );
if( fexist( file ) )
{
dini_IntSet( file, "Object", GateInfo[i][gObject] );
dini_FloatSet( file, "X", GateInfo[i][gX] );
dini_FloatSet( file, "Y", GateInfo[i][gY] );
dini_FloatSet( file, "Z", GateInfo[i][gZ] );
dini_FloatSet( file, "A", GateInfo[i][gA] );
dini_IntSet( file, "Status", GateInfo[i][gStatus] );
dini_IntSet( file, "Password", GateInfo[i][gPassword] );
dini_Set( file, "PlacedBy", GateInfo[i][gPlacedBy] );
DestroyObject( GateInfo[i][gObject] );
format( GateInfo[i][gPlacedBy], 24, "None" );
GateInfo[i][gCreated] = 0;
GateInfo[i][gX] = 0.0;
GateInfo[i][gY] = 0.0;
GateInfo[i][gZ] = 0.0;
GateInfo[i][gA] = 0.0;
GateInfo[i][gStatus] = GATE_STATE_CLOSED;
}
}
}
return 1;
}
public OnObjectMoved( objectid )
{
for( new i = 0; i != MAX_GATES; i++ )
{
if( GateInfo[i][gCreated] == 1 )
{
if( GateInfo[i][gObject] == objectid )
{
if( GateInfo[i][gStatus] == GATE_STATE_CLOSED )
GateInfo[i][gStatus] = GATE_STATE_OPEN;
else if( GateInfo[i][gStatus] == GATE_STATE_OPEN )
GateInfo[i][gStatus] = GATE_STATE_CLOSED;
// Update the variables.
new Float:oPos[3];
GetObjectPos( objectid, oPos[0], oPos[1], oPos[2] );
GateInfo[i][gX] = oPos[0];
GateInfo[i][gY] = oPos[1];
GateInfo[i][gZ] = oPos[2];
break;
}
}
}
return 1;
}
stock CreateGate( playerid, password, Float:x, Float:y, Float:z, Float:a )
{
for( new i = 0; i != MAX_GATES; i++ )
{
if( GateInfo[i][gCreated] == 0 )
{
new szName[24];
GetPlayerName( playerid, szName, 24 );
GateInfo[i][gObject] = CreateObject( GATE_OBJECT, x, y, z+1.5, 0, 0, a );
format( GateInfo[i][gPlacedBy], 24, "%s", szName );
GateInfo[i][gCreated] = 1;
GateInfo[i][gX] = x;
GateInfo[i][gY] = y;
GateInfo[i][gZ] = z+1.5; // comment the +1.5 if you're not using object 980.
GateInfo[i][gA] = a;
GateInfo[i][gStatus] = GATE_STATE_CLOSED;
GateInfo[i][gPassword] = password;
SetPlayerPos( playerid, x+1, y+1, z );
new file[64];
format( file, 64, "Gates/gate_%d.ini", i );
if( !fexist( file ) )
{
dini_Create( file );
dini_IntSet( file, "Object", GateInfo[i][gObject] );
dini_FloatSet( file, "X", GateInfo[i][gX] );
dini_FloatSet( file, "Y", GateInfo[i][gY] );
dini_FloatSet( file, "Z", GateInfo[i][gZ] );
dini_FloatSet( file, "A", GateInfo[i][gA] );
dini_IntSet( file, "Status", GateInfo[i][gStatus] );
dini_Set( file, "PlacedBy", GateInfo[i][gPlacedBy] );
}
break;
}
}
}
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == DIALOG_x)
{
if(response == 1)
{
//=inputtext[20];
GATE_OBJECT=strval(inputtext);
}
else
{
SendClientMessage(playerid, 0xEB000FFF, ":(");
}
return 1;
}
return 1;
}
What did i do wrong?
Original:
http://pastebin.com/862f9RhN
AW: Gate placer doest work. Help pls! -
CutX - 31.07.2013
Quote:
Originally Posted by qkac1234
when i use /gateplace nothing happens.
|
did you type
/gateplace ?
if that's really the command, then it's true that nothing's happening.
cuz it's not in the script! :P
the correct command is
/placegate
lol'd so hard if that really was ur mistake xDD
Re: Gate placer doest work. Help pls! -
qkac1234 - 31.07.2013
No, I made the mistake only in the post....... And I edited it.
I tested more, and it places something. An invisible object.
AW: Gate placer doest work. Help pls! -
CutX - 31.07.2013
hmm... you could debug your way trough the " CreateGate " function.
see when it suddenly stops.
And then when you know where it stops, you know why it wasn't working, usually.
if you don't know how 2 do that, here's a example:
Код:
stock lol(playerid,val)
{
print("lol - top");
if(!IsPlayerInAnyVehicle(playerid)) return 0;
print("lol - after \"IsPlayerIn...\"");
val = (val == 15) ? (val++) : (val--);
printf("lol - \"val\" is: %d",val);
print("lol - bottom");
return val;
}
the print's here are the debug messages.
so if notihng goes wrong, lol will return 16
Re: Gate placer doest work. Help pls! -
qkac1234 - 31.07.2013
Nice idea thanks. But before I try this. Maybe I found the problem.
I added this command:
Код:
COMMAND:id(playerid, params[])
{
new string[60];
format(string, sizeof(string), "ID: %d", GATE_OBJECT);
SendClientMessage(playerid, -1, string);
return 1;
}
First I added a number in the dialog.
Then I chacked the variable, before use the /placegate command. And it said: ID: 0. Maybe there is the problem. Can u help me to make another input and check with that? It's because debug is a littlebit difficult to me...
AW: Gate placer doest work. Help pls! -
CutX - 31.07.2013
jep, that's normal for it being 0.
on top you have:
which automatically becomes "0" if you don't assign it to a value before trying to return it.
you're using that in OnFilterScriptInit() at that line
Код:
GateInfo[i][gObject] = CreateObject( GATE_OBJECT, GateInfo[i][gX], GateInfo[i][gY], GateInfo[i][gZ], 0, 0, GateInfo[i][gA] );
on top, where you've got your "new GATE_OBJECT;" replace it with "new GATE_OBJECT = 123;"(123 is the object id) so you should be abel to see the gate created in OnFilterscriptInit()
Re: Gate placer doest work. Help pls! -
qkac1234 - 31.07.2013
Yes, now it works. So I won't be able to choose the gate's object ingame :/ ... Thanks for help.
AW: Gate placer doest work. Help pls! -
CutX - 31.07.2013
you can change it ingame.
you don't have to create the gate when the script loads.
You could put it all in a function and call it using a command
example of the function:
Код:
stock CreateTheGate(playerid,objectid)//customize the params depending on what you need to create your gate
{
///your gate - creation code, using the given "objectid"
return 1;
}
you could use it like CreateTheGate(playerid,980); //980 is the object you want