OnPlayerRequestSpawn help
#1

Hello, i'm pretty noob at scripting, many of you may know haha. Anyways, I tried scripting this, but in game it just doesn't work. I compile and there's no errors or warnings, it's just there and not working.

Code:
Код:
public OnPlayerRequestSpawn(playerid)
{
    new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid, name, sizeof(name));
    if(gTeam[playerid] == TEAM_CIA)
    {
        if(strfind(name, "[CIA]", true) != 0)
        {
        	SendClientMessage(playerid,0xFF8000C8,"You are not a member of the Central Intelligence Agency! Choose another class.");
            ForceClassSelection(playerid);
            return 0;
        }
    }

    if(gTeam[playerid] == TEAM_ED)
        {
        if(strfind(name, "[ED]", true) != 0)
         {
    		SendClientMessage(playerid,0xFF8000C8,"You are not a member of the Electric Drifters! Choose another class.");
            ForceClassSelection(playerid);
            return 0;
         }
    }
    return 1;
  }
Reply
#2

Can you show us the CIA and ED codes , including your Enums? so that we can help you clearly
Reply
#3

This is the OnPlayerSpawn:
Код:
       case TEAM_CIA: {
   		 new name[ MAX_PLAYER_NAME ];
		 GetPlayerName(playerid, name, MAX_PLAYER_NAME);
		 SetPlayerPos(playerid,gCIASP[rand][0],gCIASP[rand][1],gCIASP[rand][2]);
	     SetPlayerFacingAngle(playerid,gCIASP[rand][3]);
	     SendClientMessage(playerid, HOODLUMS_COLOR, "If you are not an official member of the CIA, F4 + /kill and choose another class.");
	     SendClientMessage(playerid, HOODLUMS_COLOR, "If you are caught by an administrator in this class and you're not supposed to be, you will be punished.");
	     SendClientMessage(playerid, HOODLUMS_COLOR, "If you are not a member of the CIA, but would like to be, apply on gw-dm.boards.net");
         if(strfind(name,"[CIA]",true) != -1)
		 SendClientMessage(playerid, HOODLUMS_COLOR, "You have spawned as an official Central Intelligence Agency member.");
		 return 1;
       }
       case TEAM_ED: {
 		 new name[ MAX_PLAYER_NAME ];
		 GetPlayerName(playerid, name, MAX_PLAYER_NAME);
         SetPlayerPos(playerid,gEDSP[rand][0],gEDSP[rand][1],gEDSP[rand][2]);
	     SetPlayerFacingAngle(playerid,gEDSP[rand][3]);
   	     SendClientMessage(playerid, WORKERS_COLOR, "If you are not an official member of the Electric Drifters, F4 + /kill and choose another class.");
	     SendClientMessage(playerid, WORKERS_COLOR, "If you are caught by an administrator in this class and you're not supposed to be, you will be punished.");
   	     SendClientMessage(playerid, WORKERS_COLOR, "If you are not a member of the Electric Drifters, but would like to be, apply on gw-dm.boards.net");
 		 if(strfind(name,"[ED]",true) != -1)
		 SendClientMessage(playerid, WORKERS_COLOR, "You have spawned as an official Electric Drifters member.");
    	 return 1;
       }
	}
All of this works, but the OnPlayerRequestSpawn doesn't. I don't have any enum in my code. I did ctrl + f and typed enum, nothing found.
Reply
#4

You didn't clearly state what exactly wasn't working. I'm guessing you want it to send you to class selection but it won't. Try toggling spectate on and off (after ForceClassSelection).
Reply
#5

Quote:

SendClientMessage(playerid,0xFF8000C8,"You are not a member of the Central Intelligence Agency! Choose another class.");
ForceClassSelection(playerid);
return 0;

This is what isn't working. If the player doesn't have [ED] or [CIA] in their name for them, it still lets them spawn, but I have this scripted in to hold them back from spawning if they don't have it in their name, but it just doesn't work
Reply
#6

Is the message ever received?

If so, do what I said before.
If not, the gTeam variable was never set to either of those two teams.
Reply
#7

The message is never received
Reply
#8

PHP код:
#include <EasyNames>
public OnPlayerRequestSpawn(playerid)
{
    switch (
gTeam[playerid]) {
        case 
TEAM_CIA : if( (PlayerNameContains(playerid"[CIA]") == 0) return SendClientMessage(playerid,0xFF8000C8,"You are not a member of the Central Intelligence Agency! Choose another class."),ForceClassSelection(playerid);
        case 
TEAM_ED : if( (PlayerNameContains(playerid"[ED]") == 0) return SendClientMessage(playerid,0xFF8000C8,"You are not a member of the Electric Drifters! Choose another class."),ForceClassSelection(playerid);
    }
    return 
1;
  } 
https://sampforum.blast.hk/showthread.php?tid=51289
Reply
#9

Quote:
Originally Posted by nicholasramdhan
Посмотреть сообщение
The message is never received
Then one of the following lines are not 'true':
Код:
if(gTeam[playerid] == TEAM_CIA)

if(strfind(name, "[CIA]", true) != 0)

if(gTeam[playerid] == TEAM_ED)

if(strfind(name, "[ED]", true) != 0)
So, 1st show us where you set gTeam to the players team. 2nd, just make sure the name does in fact have those characters.

Lastly, try adding some debugging messages (try the code below).
Код:
public OnPlayerRequestSpawn(playerid)
{
	new name[MAX_PLAYER_NAME];
	GetPlayerName(playerid, name, sizeof(name));
	
	printf("OnPlayerRequestSpawn called for: [%i]%s.", playerid, name);
	
	if(gTeam[playerid] == TEAM_CIA)
	{
		printf("Player IS in the CIA team: [%i]%s.", playerid, name);
		if(strfind(name, "[CIA]", true) != 0)
		{
			printf("Player's name DOES contain '[CIA]': [%i]%s.", playerid, name);
			SendClientMessage(playerid,0xFF8000C8,"You are not a member of the Central Intelligence Agency! Choose another class.");
			ForceClassSelection(playerid);
			return 0;
		}
	}

	if(gTeam[playerid] == TEAM_ED)
	{
		printf("Player IS in the ED team: [%i]%s.", playerid, name);
		if(strfind(name, "[ED]", true) != 0)
		{
			printf("Player's name DOES contain '[ED]': [%i]%s.", playerid, name);
			SendClientMessage(playerid,0xFF8000C8,"You are not a member of the Electric Drifters! Choose another class.");
			ForceClassSelection(playerid);
			return 0;
		}
	}
	
	printf("Spawning Player: [%i]%s.", playerid, name);
	return 1;
}
After trying this code show us your log after you've been through class selection and have been (or have not been) spawned.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)