SA-MP Forums Archive
"New;" problems - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: "New;" problems (/showthread.php?tid=521405)



"New;" problems - Bek_Loking - 23.06.2014

Hey. I just recently made a script for rp server which is a parking lot that I mapped out as well. now what the problem is: I forwarded "close" as a timer of course. if I do uh. it's easier to explain with script, look:

Код:
public close()
{
new pgate = CreateObject(2933,1717.0000000,1308.0000000,11.5000000,0.0000000,0.0000000,90.0000000);
MoveObject(pgate, 1717.0000000,1308.0000000,11.5000000, 5);
return 1;
}
This is supposed to be a timer which will move parking lot gate to it's place when it runs out ( 4 seconds )
Now the script of parking lot:

Код:
CMD:parkinglot(playerid, params[])
{
   new pgate = CreateObject(2933,1717.0000000,1308.0000000,11.5000000,0.0000000,0.0000000,90.0000000);
   new pstate = GetPlayerState(playerid);
   if(GetPlayerMoney(playerid) < 500) return SendClientMessage(playerid, COLOR_RED, "You don't have enough money to park your car here!");
   if(pstate == PLAYER_STATE_ONFOOT) return SendClientMessage(playerid, COLOR_RED, "You're not in a vehicle!");
   MoveObject(pgate, 1717.0000000,1308.0000000,1.5000000, 5);
   SetTimer("close",3000,0);
   return 1;
 }
The gate seems to move but like there is a replica that just stands there and does nothing. What do I do?


Re: "New;" problems - DeStunter - 23.06.2014

That is because you are creating a new object every time you open and close the gate.

put
pawn Код:
new pgate;
somewhere at the top of script so its a global variable, and then put
pawn Код:
pgate = CreateObject(2933,1717.0000000,1308.0000000,11.5000000,0.0000000,0.0000000,90.0000000);
in OnGameModeInit()


Re: "New;" problems - Bek_Loking - 23.06.2014

a'ight lets see. if it works you have a rep up


Re: "New;" problems - Bek_Loking - 23.06.2014

This is what I get
Код:
C:\Users\MARKO\Desktop\Learning\gamemodes\Tutorial.pwn(32) : warning 219: local variable "pgate" shadows a variable at a preceding level
C:\Users\MARKO\Desktop\Learning\gamemodes\Tutorial.pwn(32) : warning 204: symbol is assigned a value that is never used: "pgate"



Re: "New;" problems - Bek_Loking - 23.06.2014

Fixed it. thanks rep'd up


Re: "New;" problems - DeStunter - 23.06.2014

well you need to remove
pawn Код:
new pgate = CreateObject(2933,1717.0000000,1308.0000000,11.5000000,0.0000000,0.0000000,90.0000000);
from your parkinglot command and close function as it is already a global variable. The error is saying your trying to create a variable that is already defined.