[NEED HELP] Have main game-mode script work in a filterscript
#1

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

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

You should use a PVar for this.

https://sampforum.blast.hk/showthread.php?pid=768983#pid768983

https://sampforum.blast.hk/showthread.php?tid=571043
Reply
#4

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

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.

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!
Reply
#6

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;
}
Reply
#7

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!
Reply
#8

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

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)
Reply
#10

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


Forum Jump:


Users browsing this thread: 2 Guest(s)