new public function, but only ID 0 works :(
#1

I made this function, but im still kinda novice. Admins cant get it to work unless they are ID 0 for some reason... I checked the data in the array, it works fine. I think there is a problem sending either the data from the array to the function, somehow always returning a 0, or something I'm obviously not educated enough in PAWN to notice.



static snoop[MAX_PLAYERS][2]; // 200 sections, 2 values for each: first dim is snooper, second is snoopee





forward Snoop(playerid);





public Snoop(playerid)
{
if(snoop[playerid][1] != 255)
{

// CHOOSE YOUR DISTANCES UP HERE
// NEGATIVE=BEHIND for veh/pedcamdist/look (NEGATIVE=LOWER for veh/pedcamalt)
// POSITIVE=IN FRONT for veh/pedcamdist/look (POSITIVE=RAISE for veh/pedcamalt)
new vehcamdist = -15;
new vehcamlook = 15;
new vehcamalt = 5;
new vehcamlensalt = 0;
new pedcamdist = 8;
new pedcamalt = 1;

// ASSIGN FLOAT VARIABLES TO HOLD THE CAMERA/PLAYER VALUES
new Float:cX,Float:cY,Float:cZ,Float:tX,Float:tY,Float :tZ,Float:tA;

if(IsPlayerInAnyVehicle(snoop[playerid][1]))
{
//********** PLAYER IS IN A VEHICLE **********//
GetPlayerPos(snoop[playerid][1], tX, tY, tZ); // stores the target's position in tX, tY, and tZ variables
cX = tX; // copy 2 of the 3 coords to new values because tX will be changed to achieve coords for camera positioning in front of/behind the player
cY = tY; // copy 2 of the 3 coords to new values because tY will be changed to achieve coords for camera positioning in front of/behind the player
GetVehicleZAngle(GetPlayerVehicleID(snoop[playerid][1]), tA); // stores the target's facing angle in tA variable

// MOVE THE CAMERA THIS FAR BEHIND THE PLAYER... [vehcamdist]
cX += (vehcamdist * floatsin(-tA, degrees)); // position camera X coord from target
cY += (vehcamdist * floatcos(-tA, degrees)); // position camera Y coord from target

// ...NOW TELL IT HOW FAR AHEAD TO LOOK [vehcamlook] ...
tX += (vehcamlook * floatsin(-tA, degrees)); // aim camera X coord from target
tY += (vehcamlook * floatcos(-tA, degrees)); // aim camera Y coord from target

// ...AND HOW FAR ABOVE/BELOW THE PLAYER THE CAMERA SHOULD BE [vehcamalt] AND HOW FAR ABOVE/BELOW THE PLAYER TO FOCUS ON [vehcamlensalt]
SetPlayerCameraPos(playerid, cX, cY, tZ+vehcamalt); // position camera
SetPlayerCameraLookAt(playerid, tX, tY, tZ+vehcamlensalt); // aim camera [here, we aim the camera at the same altitude as the player]
//********************************************//
} else
{
//************ PLAYER IS ON FOOT ************//
GetPlayerPos(snoop[playerid][1], cX, cY, cZ); // stores the target's position in cX, cY, and cZ variables
tX = cX; // copy all 3 coords to new values because cX will be changed to achieve coords for camera positioning in front of/behind the player
tY = cY; // copy all 3 coords to new values because cY will be changed to achieve coords for camera positioning in front of/behind the player
tZ = cZ; // copy all 3 coords to new values because cZ will be changed to achieve coords for camera positioning in front of/behind the player
GetPlayerFacingAngle(snoop[playerid][1], tA); // stores the target's facing angle in tA variable

// MOVE THE CAMERA THIS FAR BEHIND THE PLAYER... [pedcamdist]
cX += (pedcamdist * floatsin(-tA, degrees)); // position camera X coord from target
cY += (pedcamdist * floatcos(-tA, degrees)); // position camera Y coord from target

// ...THIS TIME AROUND, WE JUST WANT TO AIM DIRECTLY AT THE PLAYER, BUT SPECIFY HOW FAR ABOVE/BELOW THE PLAYER THE CAMERA SHOULD BE [pedcamalt]
SetPlayerCameraPos(playerid, cX, cY, tZ+pedcamalt); // position camera
SetPlayerCameraLookAt(playerid, tX, tY, tZ); // aim camera
//*******************************************//
}
}
}





public OnGameModeInit()
{

snoop[0][1] = 255;
snoop[1][1] = 255;
snoop[2][1] = 255;
// goies all the way up to... //
snoop[197][1] = 255;
snoop[198][1] = 255;
snoop[199][1] = 255;

SetTimer("Snoop",25,true);
}






if(strcmp(cmd, "/snoop", true) == 0)
{

tmp = strtok(cmdtext, idx);

if(!strlen(tmp))
{
SendClientMessage(playerid, ORANGE, "USAGE: /snoop [player ID]");
return 1;
}

new id = strval(tmp);

if(!IsPlayerConnected(id) || id == INVALID_PLAYER_ID)
{
SendClientMessage(playerid, RED, "Invalid player ID");
return 1;
}
/*
if(id == playerid)
{
SendClientMessage(playerid, RED, "You cannot /snoop yourself");
return 1;
}
*/
if(GetPlayerState(id) == 0)
{
SendClientMessage(playerid, RED, "Player is not spawned");
return 1;
}

if(snoop[playerid][1] != 255)
{
SendClientMessage(playerid, RED, "Switching targets...");
}

new string[128];
new name[MAX_PLAYER_NAME];
GetPlayerName(id, name, sizeof(name));
format(string,128,"You are now snooping %s(%d)", name, id);
SendClientMessage(playerid, ORANGE, string);
snoop[playerid][1] = id;

return 1;
}

//---------------------------------------------------------

if(strcmp(cmd, "/nosnoop", true) == 0)
{

if(snoop[playerid][1] != 255)
{
new string[128];
new name[MAX_PLAYER_NAME];
GetPlayerName(snoop[playerid][1], name, sizeof(name));
format(string,128,"You are no longer /snoop'ing %s(%d)", name, snoop[playerid][1]);
SendClientMessage(playerid, ORANGE, string);
SetCameraBehindPlayer(playerid);
snoop[playerid][1] = 255;
}

return 1;
}






Also, is there any way to load a far away portion of the map to view the player you are snooping on without actually being there? Going there would eliminate the point of it being called "snoop"... If the target is too far away, I just see blurry roads, etc.. but no players. Also, I dont use TogglePlayerSpectate or whatever it's called, because everytime I set it to 0, [not spectating] it respawns my character. [My mode uses teams]


IF YOU CAN HELP PLEASE DO. THANK YOU VERY MUCH!!!
Reply
#2

It's a common problem, maybe try to search next time :P

Problem is here: SetTimer("Snoop",25,true);
Do you see any variable such as playerid?

Use a loop.


For second question: no there is no other way, but why not just simply put the player a little under ground, hide his blip, and freeze him ?


Reply
#3

Quote:

Do you see any variable such as playerid?

Where should I be looking for this playerid? I'm sure you realize there are thousands of playerid's in my script.. xD


I dont see how that is relavent...

That's a timer, repeating itself, each time calling up the Snoop function.

I have a similar Timer called AreaCheck, but it does not use values:

forward Snoop(playerid,snoop[][]);
forward AreaCheck(playerid);


public AreaCheck(playerid)
{
if this do that
}


SetTimer("AreaCheck",30000,true);


Can you elaborate a little more on how I can remedy this, please Orb?
Reply
#4

Then your AreaCheck is also bugged and work only for id 0.

How the timer can guess the value of playerid, if you don't assign any value to it? It can't, so your variable playerid is always 0. And you run the timer under OnGameModeInit(), do you think there are any players connected at this moment?

You have to use a loop, as in this example:

pawn Код:
forward Snoop();

public Snoop()
{
  for (new playerid; playerid < MAX_PLAYERS; playerid ++)
  {
    //all your code here
  }
}
Reply
#5

Why not use SetTimerEx if he's trying to use a timer? But I guess a loop could work depending on what he's trying to accomplish (Haven't read the script only replies :P)
Reply
#6

thank you orb for your ingenius reply, everything woorks fine now.

and lavamike, i use several timers for different things, some involving many variables, some not. thanks for your input tho
Reply
#7

Quote:
Originally Posted by devil614
pawn Код:
snoop[0][1] = 255;
  snoop[1][1] = 255;
  snoop[2][1] = 255;
// goies all the way up to... //
  snoop[197][1] = 255;
  snoop[198][1] = 255;
  snoop[199][1] = 255;
Woow!
You should try a
pawn Код:
for(new j = 0; j < 200; j++)
{
  snoop[j][1] = 255;
}
Reply
#8

Quote:
Originally Posted by matrix_smq
Quote:
Originally Posted by devil614
pawn Код:
snoop[0][1] = 255;
 snoop[1][1] = 255;
 snoop[2][1] = 255;
// goies all the way up to... //
 snoop[197][1] = 255;
 snoop[198][1] = 255;
 snoop[199][1] = 255;
Woow!
You should try a
pawn Код:
for(new j = 0; j < 200; j++)
{
  snoop[j][1] = 255;
}
Can't use a loop on GameModeInit. Crashes my server.
Reply
#9

If you can't use a loop that can't script that, bye.

EDIT: What am i saying!?!? wrong topic or something? lol.
Reply
#10

Quote:
Originally Posted by Andom
If you can't use a loop that can't script that, bye.
Okay then? ...bye?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)