PDA

View Full Version : need help


RafaelHDI
14/05/2019, 12:38 PM
i need help scripting two gates. i have two gates stacked on top of each other, and i wanted to open them with the same command at the same time and close after 10 seconds. can someone help me?

here is the code i created using simple gate explanation videos



new Portao;
new Portao2;

Portao =
CreateDynamicObject(991,321.29998779297,-1188.1999511719,76.599998474121,0.0000000,0.000000 0,219.25);
Portao2 =
CreateDynamicObject(991,321.29998779297,-1188.2001953125,79,0.0000000,0.0000000,40);

public OnPlayerCommandText(playerid,cmdtext[])
//portao1
if(strcmp(cmdtext, "/rb1", true) == 0) {
MoveDynamicObject(Portao,316,-1192.3000488281,76.599998474121,4);
SendClientMessage(playerid,0x09D19BFF,"Portao aberto!");
return 1;
}
if(strcmp(cmdtext, "/rb2", true) == 0) {
MoveDynamicObject(Portao,321.29998779297,-1188.1999511719,76.599998474121,4);
SendClientMessage(playerid,0x09D19BFF,"Portao fechado!");
return 1;
}
//portao2
if(strcmp(cmdtext, "/rb3", true) == 0) {
MoveDynamicObject(Portao2,316.10000610352,-1192.3000488281,78.900001525879,4);
SendClientMessage(playerid,0x09D19BFF,"Portao aberto!");
return 1;
}

if(strcmp(cmdtext, "/rb4", true) == 0) {
MoveDynamicObject(Portao2,321.29998779297,-1188.2001953125,79,4);
SendClientMessage(playerid,0x09D19BFF,"Portao fechado!");
return 1;
}



// btw Portao means gate
ty

Plastikmensch
14/05/2019, 01:15 PM
When you want to move two objects with one command you need to put MoveDynamicObject twice in one command.
For closing the gates after 10 seconds, create a timer and a public function.

//OnPlayerCommandText
//Command
{
MoveDynamicObject(object1,...);
MoveDynamicObject(object2,...);
SetTimer("CloseGate",...);
}
//Outside any callback
forward CloseGate();
public CloseGate()
{
MoveDynamicObject(object1,...);
MoveDynamicObject(object2,...);
return 1;
}

https://wiki.sa-mp.com/wiki/SetTimer

RafaelHDI
14/05/2019, 02:11 PM
thanks, it worked, but i have another question how do i create the command to a specific player? ex: my nick is lol123 , how do i open my gates using just my nick and no other people that know that command?
what i mean is how only me can acess the gates and use that specific command and no one else?
thanks again

Plastikmensch
14/05/2019, 02:54 PM
Use GetPlayerName to get the name of the player and strcmp to compare it with your name.

//command
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
if(!strcmp(name,"lol123"))//same as strcmp(string1,string2,false) == 0
{
//MoveObjects
}
return 1;
}

RafaelHDI
14/05/2019, 04:29 PM
Iīve done this but pawno keeps saying that is has stopped working, and it doesnīt compile nothing... itīs because something is wrong here?
this is the whole section code:

if(strcmp(cmdtext, "/rb1", true) == 0)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
if(!strcmp(name,"lol123"))//same as strcmp(string1,string2,false) == 0
{
MoveDynamicObject(Portao,316,-1192.3000488281,76.599998474121,4);
MoveDynamicObject(Portao2,316.10000610352,-1192.3000488281,78.900001525879,4);
}
return 1;
}
SendClientMessage(playerid,0x09D19BFF,"Portao aberto!"); //gate opened
SetTimer("CloseGate", 5000, false);
SendClientMessage(playerid,0x09D19BFF,"Portao fechando em 5 segundos!"); // gate closing in 5 secs
}

ty

Macronix
14/05/2019, 05:22 PM
if(strcmp(cmdtext, "/rb1", true) == 0)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));

if(!strcmp(name,"lol123"))//same as strcmp(string1,string2,false) == 0
{
MoveDynamicObject(Portao,316,-1192.3000488281,76.599998474121,4);
MoveDynamicObject(Portao2,316.10000610352,-1192.3000488281,78.900001525879,4);

SendClientMessage(playerid,0x09D19BFF,"Portao aberto!"); //gate opened
SetTimer("CloseGate", 5000, false);
SendClientMessage(playerid,0x09D19BFF,"Portao fechando em 5 segundos!"); // gate closing in 5 secs
}
return 1;
}

Plastikmensch
14/05/2019, 05:24 PM
return always comes at the end and there is a closing bracket which closes the if statement before Message is sent.
Tip: Use tabs or spaces, the code is easier to read that way and missing or too much brackets become very obvious to spot.

if(strcmp(cmdtext, "/rb1", true) == 0)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid,name,sizeof(name));
if(!strcmp(name,"lol123"))//same as strcmp(string1,string2,false) == 0
{
MoveDynamicObject(Portao,316,-1192.3000488281,76.599998474121,4);
MoveDynamicObject(Portao2,316.10000610352,-1192.3000488281,78.900001525879,4);
}
return 1; //<- remove
} //<-remove
SendClientMessage(playerid,0x09D19BFF,"Portao aberto!"); //gate opened
SetTimer("CloseGate", 5000, false);
SendClientMessage(playerid,0x09D19BFF,"Portao fechando em 5 segundos!"); // gate closing in 5 secs
return 1; //<- always at the end or to prevent any further actions.
}


Btw. that way the messages are sent and gates will close after 5 ceconds even when someone else uses the command.
Either put the messages and timers inside the the name check or replace it with

if(strcmp(name,"lol123")) return 0; //if name doesn't match do nothing

You can also return messages

if(...) return SendClientMessage(...);

RafaelHDI
15/05/2019, 12:55 PM
Macronix and Plastikmensch it all went right as i expected,thanks for all.
itīs nice to see people still playing gta sa and people willing to help others. ty again