Spawn-weapons
#1

Hi. So I want to create a code which lets the player pick a weapon set at spawn, but I dont know how I'd do it.

What I've got so far:

Код:
OnPlayerConnect
{
     ShowMenu[playerid] = 1;
     return 1;
}
Код:
OnPlayerSpawn
{
   	if(ShowMenu[playerid] == 1)
	{
		ShowPlayerDialog(playerid, DIALOG_SHOWMENU, DIALOG_STYLE_TABLIST, "Spawn weapons",
		"Weapon set 1:\t Deagle\t$0\n\
		Weapon set 2:\t Deagle, shotgun\t$500\n\
		Weapon set 3:\t Deagle, shotgun, M4\t$500", //
		"Select", "Close");
                }
Код:
OnDialogResponse
    if(dialogid == DIALOG_SHOWMENU)
    {
        if(!response)
        {
      		ShowPlayerDialog(playerid, DIALOG_SHOWMENU, DIALOG_STYLE_TABLIST, "Spawn weapons",
			"Weapon set 1:\t Deagle\t$0\n\
			Weapon set 2:\t Deagle, shotgun\t$500\n\
			Weapon set 3:\t Deagle, shotgun, M4\t$500", //
			"Select", "Close");
		}
		else
		{
            switch(listitem)
            {
                case 0: SetTimerEx("SpawnprotectionGuns", 2500, false, "i", playerid);(playerid) 
                case 1: SetTimerEx("SpawnprotectionGuns", 2500, false, "i", playerid);(playerid)
                case 2: SetTimerEx("SpawnprotectionGuns", 2500, false, "i", playerid);(playerid)
            }

Код:
forward SpawnprotectionGuns(playerid);
public SpawnprotectionGuns(playerid)
{
	SpawnProtection[playerid] = 0;
	SendClientMessage(playerid, 0xAFAFAFAA, "SERVER: Spawn protection has ended!");
       GivePlayerWeapon(playerid, 24, 50); // perhaps something here?
	}
	return 1;
}






This is pretty much where I got stuck. How would I proceed? Should I create a public?
How would I make it so that when I Respawn it gives me the weaponset I selected?

Thanks!

(Sorry if there were any grammar mistakes 4:40am as I am writing this)
Reply
#2

We could problably create a function that handles giving out gunsets, like this.
PHP код:
GiveGuns(playerid)
{
    switch(
chosenGuns[playerid])
    {
        case 
0// just in case something broke along the way
        
{
            
ShowPlayerDialog(playeridDIALOG_SHOWMENUDIALOG_STYLE_TABLIST"Spawn weapons",
            
"Weapon set 1:\t Deagle\t$0\n\
            Weapon set 2:\t Deagle, shotgun\t$500\n\
            Weapon set 3:\t Deagle, shotgun, M4\t$500"
//
            
"Select""Close");
            return 
1;
        }
        case 
1:
        {
            
// give gunset 1..
        
}
        case 
2:
        {
            
// give gunset 2..
        
}
        case 
3:
        {
            
// give gunset 3..
        
}
    }

For that we'd create a global variable
PHP код:
new chosenGuns[MAX_PLAYERS]; 
and on the dialog response we'd set the gunset they chose and make the guns be given aswell,
PHP код:
switch(listitem)
{
    case 
0:
    {
        
chosenGuns[playerid] = 1;
        
GiveGuns(playerid);
    }
    case 
1:
    {
        
chosenGuns[playerid] = 2;
        
GiveGuns(playerid);
    }
    case 
2:
    {
        
chosenGuns[playerid] = 3;
        
GiveGuns(playerid);
    }

then OnPlayerConnect we'd add
PHP код:
chosenGuns[playerid] = 
to make sure the gunset gets reset for the playerid.

then OnPlayerSpawn we'd add
PHP код:
GiveGuns(playerid); 

Also, there won't actually be a need to show the gun menu, since if he has chosenGuns set to 0, the GiveGuns function will handle it.
I'm talking about the following code
PHP код:
OnPlayerSpawn
{
       if(
ShowMenu[playerid] == 1)
    {
        
ShowPlayerDialog(playeridDIALOG_SHOWMENUDIALOG_STYLE_TABLIST"Spawn weapons",
        
"Weapon set 1:\t Deagle\t$0\n\
        Weapon set 2:\t Deagle, shotgun\t$500\n\
        Weapon set 3:\t Deagle, shotgun, M4\t$500"
//
        
"Select""Close");
                } 
Reply
#3

Thanks alot for the response! I seem to have run into a problem though :p

Код:
bare.pwn(648) : warning 209: function "GiveGuns" should return a value
bare.pwn(967) : error 030: compound statement not closed at the end of file (started at line 933)
line 648 is at the end of the giveguns function and line 967 is at the end of my script:

Reply
#4

You need to add all the proper closing and opening brackets to your script, i can see by looking at it that it's not properly indented and you are missing some closing brackets.

the switch statement needs to be tabbed (4 spaces) and then you need to add the closing bracket for the else statement
Reply
#5

Thanks man, got it. I just tried it out ingame and it works. However I still got the warning about the function should return a value'. Any way I can 'hide' the warning from appearing or is there actually something wrong?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)