Function question -
knackworst - 28.11.2010
Hi, there I got a question,
I want to make this:
In my GM there is the speedboost key, the flip key end the carjump key,
Now, I also have got a race script (downloaded)
How I want to do it is like this:
in my GM I make, new antispeedboost[MAX_PLAYERS]
So, at the keystate change, I can set you need antispeedboost=0 to use this command
and in my Race script I want: when player join race (/startrace and joinrace ) then: antispeedboost=1
Is there a possibilty to use the antispeedboost[maxplayers] in my GM and in my Race script?
Re: Function question -
iggy1 - 28.11.2010
PVars. They have cross script compatability.
Re: Function question -
XePloiT - 28.11.2010
you can define it in a .inc file and include it in both of them...maybe define it in a exist .inc file
Re: Function question -
JaTochNietDan - 28.11.2010
No, variables are localized to the script they are in.
The only way to use variables across scripts is by using PVars.
Although you could also create a public function that changes that specific variable to whatever you want, and call it using
CallRemoteFunction. For example:
pawn Код:
// In the Gamemode
public speedBoost(playerid, value)
{
antispeedboost[playerid] = value;
return 1;
}
// In the "race script" where you want it to be changed
CallRemoteFunction("speedBoost","ii",playerid,1);
pawn Код:
// In the Gamemode
public speedBoostValue(playerid, value)
{
return antispeedboost[playerid];
}
// In the "race script"
antispeedboost[playerid] = CallRemoteFunction("speedBoost","i",playerid);
That's basically the alternative to using PVars, hope it helps!
Re: Function question -
knackworst - 28.11.2010
Hmm, so like this?
pawn Код:
new Antiboost[MAX_PLAYERS]
public OnPlayerConnect(playerid)
{
Antiboost[playerid] = 0;
//Rest of my GM lines
OnPlayerKeyStateChange
{
new Keys,up,down;
GetPlayerKeys(playerid,Keys,up,down);
new Float:x,Float:y,Float:z;
if (PRESSED(KEY_CROUCH)){
{
if(Antiboost[playerid] == 0)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
GetVehicleVelocity(GetPlayerVehicleID(playerid),x,y,z);SetVehicleVelocity(GetPlayerVehicleID(playerid),x ,y ,z+0.3);}}}
and in the racescript:
pawn Код:
CallRemoteFunction("Antiboost","ii",playerid,1); //On top of the script
//Startrace cmd
CMD:startrace(playerid, params[])
{
if(AutomaticRace == true) return SendClientMessage(playerid, RED, "<!> Not possible. Automatic race is enabled!");
if(BuildRace != 0) return SendClientMessage(playerid, RED, "<!> There's someone building a race!");
if(RaceBusy == 0x01 || RaceStarted == 1) return SendClientMessage(playerid, RED, "<!> There's a race currently. Wait first till race ends!");
if(isnull(params)) return SendClientMessage(playerid, RED, "<!> /startrace [racename]");
Antiboost[playerid] = 0;
LoadRace(playerid, params);
return 1;
}
Like this?
Re: Function question -
iggy1 - 28.11.2010
I think you want this when a player enters a race,
pawn Код:
CallRemoteFunction("Antiboost","ii",playerid,1);
and when they leave
pawn Код:
CallRemoteFunction("Antiboost","ii",playerid,0);
Also have the function in your gamemode.
Re: Function question -
knackworst - 28.11.2010
Nope, still can use speedboost in the race...
Re: Function question -
JaTochNietDan - 28.11.2010
You would need to add this function in the script that you want to change the local variable in.
pawn Код:
public speedBoost(playerid, value)
{
antispeedboost[playerid] = value;
return 1;
}
This is because CallRemoteFunction executes a public function, it doesn't directly interact with variables.
Re: Function question -
knackworst - 28.11.2010
hmm, so where do I put the callremotefunction?
on top of the script? or like this?:
pawn Код:
public Antiboost(playerid, value)
{
Antiboost[playerid] = value;
return 1;
}
//and:
CMD:startrace(playerid, params[])
{
if(AutomaticRace == true) return SendClientMessage(playerid, RED, "<!> Not possible. Automatic race is enabled!");
if(BuildRace != 0) return SendClientMessage(playerid, RED, "<!> There's someone building a race!");
if(RaceBusy == 0x01 || RaceStarted == 1) return SendClientMessage(playerid, RED, "<!> There's a race currently. Wait first till race ends!");
if(isnull(params)) return SendClientMessage(playerid, RED, "<!> /startrace [racename]");
CallRemoteFunction("Antiboost","ii",playerid,1);
LoadRace(playerid, params);
return 1;
}
Cuz now I get 4 errors:
C:\Users\William\Downloads\Ti+Stuntacular\filtersc ripts\rRace.pwn(591) : warning 235: public function lacks forward declaration (symbol "Antiboost")
C:\Users\William\Downloads\Ti+Stuntacular\filtersc ripts\rRace.pwn(593) : error 028: invalid subscript (not an array or too many subscripts): "Antiboost"
C:\Users\William\Downloads\Ti+Stuntacular\filtersc ripts\rRace.pwn(593) : warning 215: expression has no effect
C:\Users\William\Downloads\Ti+Stuntacular\filtersc ripts\rRace.pwn(593) : error 001: expected token: ";", but found "]"
C:\Users\William\Downloads\Ti+Stuntacular\filtersc ripts\rRace.pwn(593) : error 029: invalid expression, assumed zero
C:\Users\William\Downloads\Ti+Stuntacular\filtersc ripts\rRace.pwn(593) : fatal error 107: too many error messages on one line
Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
4 Errors.
Re: Function question -
JaTochNietDan - 28.11.2010
You mis-understand, the public function needs to be IN the script with the variable, aka your gamemode, not your race script as you call it. You want the race script to call the function IN the gamemode, not from itself.