[NEED HELP] Have main game-mode script work in a filterscript -
XpoZzA - 09.11.2018
OK, so I have this type of code in my main gamemode:
PHP код:
new godmode[MAX_PLAYERS];
forward IsPlayerGod(TargetID);
public IsPlayerGod(TargetID)return (godmode[TargetID]);
I have read some of that "CallRemoteFunction" things, but I can't get it to work properly...
Code in filterscript:
PHP код:
#define IsPlayerGod() CallRemoteFunction("IsPlayerGod","")
Erros I get trying to compile filterscript:
Код HTML:
error 017: undefined symbol "IsPlayerGod"
Re: [NEED HELP] Have main game-mode script work in a filterscript -
AlfaSufaIndo - 10.11.2018
maybe you can use stock.. don't use public, and you don't have to use CallRemoteFunction if you using stock
PHP код:
stock IsPlayerGod(TargetID)
{
return (godMode[TargetID]);
}
-CMIIW
Re: [NEED HELP] Have main game-mode script work in a filterscript -
Rolux - 10.11.2018
You should use a PVar for this.
https://sampforum.blast.hk/showthread.php?pid=768983#pid768983
https://sampforum.blast.hk/showthread.php?tid=571043
Re: [NEED HELP] Have main game-mode script work in a filterscript -
nG Inverse - 10.11.2018
Ignore all of those suggestions! CallRemoteFunction is correct and will require your function be declared public.
pawn Код:
CallRemoteFunction("IsPlayerGod", "i", playerid);
Also since the function is called externally, and uses a passed index to directly access an array, you should add some bounds checking.
Re: [NEED HELP] Have main game-mode script work in a filterscript -
XpoZzA - 10.11.2018
Quote:
Originally Posted by AlfaSufaIndo
maybe you can use stock.. don't use public, and you don't have to use CallRemoteFunction if you using stock
PHP код:
stock IsPlayerGod(TargetID)
{
return (godMode[TargetID]);
}
-CMIIW
|
I've heard that stocks should be only used when writing includes or filterscripts and they should not be written down at the main gamemode, thanks a lot for the suggestion but I think I will try something else.
Quote:
Originally Posted by Rolux
|
Again, thanks a lot for your reply- but I want to use the "CallRemote" built-in function and not use PVar or something like that.
Quote:
Originally Posted by nG Inverse
Ignore all of those suggestions! CallRemoteFunction is correct and will require your function be declared public.
pawn Код:
CallRemoteFunction("IsPlayerGod", "i", playerid);
Also since the function is called externally, and uses a passed index to directly access an array, you should add some bounds checking.
|
I didn't really understand what did you mean with the bounds checking, but- I'll try re-constructing my code a bit and will update soon, thank you for your suggestion!
Re: [NEED HELP] Have main game-mode script work in a filterscript -
nG Inverse - 10.11.2018
If an invalid index is passed to the function it could cause an out-of-bound error, which can lead to incorrect return values or even crashes. So you should check that the index passed is valid before accessing the array.
pawn Код:
forward IsPlayerGod(TargetID);
public IsPlayerGod(TargetID) {
if(0 <= TargetID < MAX_PLAYERS) {
return godmode[TargetID];
}
return -1;
}
Re: [NEED HELP] Have main game-mode script work in a filterscript -
XpoZzA - 10.11.2018
Quote:
Originally Posted by nG Inverse
If an invalid index is passed to the function it could cause an out-of-bound error, which can lead to incorrect return values or even crashes. So you should check that the index passed is valid before accessing the array.
pawn Код:
forward IsPlayerGod(TargetID); public IsPlayerGod(TargetID) { if(0 <= TargetID < MAX_PLAYERS) { return godmode[TargetID]; } return -1; }
|
Ohh, OK. I think I understood now, thank you for your awesome help!
Re: [NEED HELP] Have main game-mode script work in a filterscript -
XpoZzA - 10.11.2018
Quote:
Originally Posted by nG Inverse
If an invalid index is passed to the function it could cause an out-of-bound error, which can lead to incorrect return values or even crashes. So you should check that the index passed is valid before accessing the array.
pawn Код:
forward IsPlayerGod(TargetID); public IsPlayerGod(TargetID) { if(0 <= TargetID < MAX_PLAYERS) { return godmode[TargetID]; } return -1; }
|
actually. It srtill does not work for me, maybe im doing something wrong?
Re: [NEED HELP] Have main game-mode script work in a filterscript -
kristo - 10.11.2018
Quote:
Originally Posted by nG Inverse
Ignore all of those suggestions! CallRemoteFunction is correct and will require your function be declared public.
pawn Код:
CallRemoteFunction("IsPlayerGod", "i", playerid);
|
^^^
Your macro didn't work since you tried to pass a parameter to it, but it doesn't use any. Replace your macro with this:
Код:
#define IsPlayerGod(%0) CallRemoteFunction("IsPlayerGod", "i", %0)
Re: [NEED HELP] Have main game-mode script work in a filterscript -
XpoZzA - 11.11.2018
Quote:
Originally Posted by kvann
^^^
Your macro didn't work since you tried to pass a parameter to it, but it doesn't use any. Replace your macro with this:
Код:
#define IsPlayerGod(%0) CallRemoteFunction("IsPlayerGod", "i", %0)
|
It still does not work, now it does not recognize the "IsPlayerGod" function... I've tried doing something like that:
Код:
new IsPlayerGod = 0;
IsPlayerGod = CallRemoteFunction("IsPlayerGod", "i", %0);
But now I get another error:
"error 010: invalid function or declaration"