"New;" problems
#1

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?
Reply
#2

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()
Reply
#3

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

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"
Reply
#5

Fixed it. thanks rep'd up
Reply
#6

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.
Reply


Forum Jump:


Users browsing this thread: