PDA

View Full Version : Help with Event System


FunnyBear
17/01/2015, 06:33 PM
Hey,

I'm current in process of making an Event System. I've already made the basic commands like /startev /openev /closeev /finishev. But I came across a problem recently when I was trying to send a message to everyone in the Event that the player is joining.

When an Admin starts an event, people will have to join using /join [ID]. ID as in the playerid of the Admin who created the event. Multiple events can be created at the same time by different players. But that's the problem. If I was going make an event kick command for the Event Creator to kick people out of their event, how can I only let him/her kick people from their own event and not other events. So if I was creating a loop to send messages to people in the event a player was joining, how could I make it so it would only send to the people in THAT event only and not people in other different events.

Here are the variables for the event,

new
EventOpen[MAX_PLAYERS],
InEvent[MAX_PLAYERS],
EventOwner[MAX_PLAYERS],
Float:EventPos[MAX_PLAYERS][4],
EventInt[MAX_PLAYERS],
EventVW[MAX_PLAYERS];

And the join command,

CMD:join(playerid, params[])
{
new id;

if(sscanf(params, "u", id) )
return SendUsageError( playerid, "/join [ID]" );

if ( id == INVALID_PLAYER_ID )
return InvalidPlayerError( playerid );

if( EventOpen[id] == 0 )
return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} Teleports to the Event have been disabled!");

if( EventOwner[id] == 0 )
return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} This user has not started an Event");

SetPlayerPos(playerid, EventPos[id][0], EventPos[id][1], EventPos[id][2]);
SetPlayerFacingAngle(playerid, EventPos[id][3]);
SetPlayerInterior(playerid, EventInt[id]);
SetPlayerVirtualWorld(playerid, EventVW[id]);
InEvent[playerid] = 1;

SendClientMessage(playerid, 0xFFA200FF, "[EVENT] You have joined an Event, use /exit to leave");
return 1;
}


How am I able to fix this?

Thanks,

FunnyBear

Misiur
17/01/2015, 09:14 PM
Currently your setup can only hold single event. You have to add additional level of depth, but unfortunately this means some rewriting.

enum e_UserEvent {
bool:UserEventOpen,
Float:UserEventPos[4],
UserEventInt,
UserEventVW
};

#define MAX_EVENTS (32)
#define INVALID_EVENT_ID (-1)

new
Events[MAX_EVENTS],
UserEvent[MAX_PLAYERS] = { INVALID_EVENT_ID, ... },
bool:InEvent[MAX_PLAYERS char]
;

CMD:join(playerid, params[])
{
new id;

if(InEvent{playerid}) {
return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} You are already in some event");
}

if(sscanf(params, "u", id) )
return SendUsageError( playerid, "/join [owner id]" );

if (id == INVALID_PLAYER_ID )
return InvalidPlayerError( playerid );

new eventId = UserEvent[playerid];

if( eventId == INVALID_EVENT_ID )
return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} This user has not started an Event");

if( !Events[eventId][UserEventOpen] )
return SendClientMessage(playerid, RED, "ERROR:{FFFFFF} Teleports to the Event have been disabled!");

SetPlayerPos(playerid, Events[eventId][0], Events[eventId][1], Events[eventId][2]);
SetPlayerFacingAngle(playerid, Events[eventId][3]);
SetPlayerInterior(playerid, Events[eventId][UserEventInt]);
SetPlayerVirtualWorld(playerid, Events[eventId][UserEventVW]);
InEvent{playerid} = true;

SendClientMessage(playerid, 0xFFA200FF, "[EVENT] You have joined an Event, use /exit to leave");
return 1;
}

This is just an example. Events are separate entity - you need to fetch its event first from UserEvent (your old eventowner). Also you have to add some constraints, as currently there can be only maxiumum of 32 Events. I'd recommend using y_iterate and y_groups, as it's exactly what you need - but already implemented.