Raised This Month: $51 Target: $400
 12% 

[CS:GO] Help scripting


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
mikasonwar
Junior Member
Join Date: Sep 2015
Old 12-11-2015 , 14:49   [CS:GO] Help scripting
Reply With Quote #1

Guys as you can probably figure out i'm pretty new to the sourcepawn and therefore i can't make a simple plugin properly. my idea was to make a plugin that would give a round start bonus to a certain flag "p" and as soon as i jump into the game with the plugin it says on the server console "client index 0 is not valid" Any idea how to fix this? and try to explain also , so next time i don't have to annoy you guys ^-^
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <clients>

public Plugin:myinfo 
{
    
name "Round bonus",
    
author "Mikasonwar",
    
description "<- Description ->",
    
version "0.1",
    
url ""
}

public 
OnPluginStart()
{
    
HookEvent("round_start",RStartEvent);
}

public 
Action:RStartEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
    new 
client_id GetEventInt(event"userid");
    new 
client GetClientOfUserId(client_id);
    
    
CreateTimer(0.2GiveEquipmentclientTIMER_FLAG_NO_MAPCHANGE);
}

public 
Action:GiveEquipment(Handle:timerany:client)
{
if (
GetUserFlagBits(client) == ADMFLAG_CUSTOM2)
{
if(
GetClientTeam(client)==3)
{
GivePlayerItem(client"defuser");
}
CS_DropWeapon(client2falsefalse);
GivePlayerItem(client"weapon_hegrenade");
GivePlayerItem(client"weapon_deagle");
GivePlayerItem(client"item_assaultsuit");
GivePlayerItem(client"weapon_smokegrenade");
GivePlayerItem(client"weapon_molotov");
GivePlayerItem(client"weapon_flashbang");
}

CloseHandle(timer);

__________________
How 2 code?
mikasonwar is offline
Deathknife
Senior Member
Join Date: Aug 2014
Old 12-11-2015 , 16:23   Re: [CS:GO] Help scripting
Reply With Quote #2

round_start does not have the flag "userid", it's global and not called once per player.
What you want to do, is either hook it on player spawn or on round start loop through all players.
Something like this:
PHP Code:
for(int i=1i<= MaxClientsi++) {
    if(
IsClientInGame(i) && IsPlayerAlive(i)) {
        
CreateTimer(0.2GiveEquipmentiTIMER_FLAG_NO_MAPCHANGE);
    }

Also, on the timer event it would be a good idea to check if player is still connected & alive.

Last edited by Deathknife; 12-11-2015 at 16:53.
Deathknife is offline
mikasonwar
Junior Member
Join Date: Sep 2015
Old 12-11-2015 , 18:13   Re: [CS:GO] Help scripting
Reply With Quote #3

hmm for they to actually start the round don't they already need to be connected + alive?
__________________
How 2 code?
mikasonwar is offline
Deathknife
Senior Member
Join Date: Aug 2014
Old 12-11-2015 , 18:19   Re: [CS:GO] Help scripting
Reply With Quote #4

Quote:
Originally Posted by mikasonwar View Post
hmm for they to actually start the round don't they already need to be connected + alive?
The round start is not when players start the round, but when a new round begins on the server. The loop I included looped through possible client's indexes.
PHP Code:
for(int i=1;i<=MaxClientsi++) {
//

This doesn't loop through clients, but through "indexes". Thus, we have to ensure the client is in game, for example by
PHP Code:
if(IsClientInGame(i)) 
But the client could also be in spectator, so he would be dead. And can't really give guns to dead people. So we use
PHP Code:
if(IsPlayerAlive(i)) 
Deathknife is offline
mikasonwar
Junior Member
Join Date: Sep 2015
Old 12-11-2015 , 18:21   Re: [CS:GO] Help scripting
Reply With Quote #5

hmm it seems it still gives me an error something regarding the giveequipment + the timer...
__________________
How 2 code?
mikasonwar is offline
mikasonwar
Junior Member
Join Date: Sep 2015
Old 12-11-2015 , 18:26   Re: [CS:GO] Help scripting
Reply With Quote #6

gives me This errors.
__________________
How 2 code?
mikasonwar is offline
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 12-11-2015 , 19:10   Re: [CS:GO] Help scripting
Reply With Quote #7

Not tested.
Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <cstrike>

#define LoopAliveClients(%1) for(int %1 = 1;%1 <= MaxClients;%1++) if(IsValidClient(%1, true))

public Plugin myinfo =
{
	name = "VIPReward",
	author = "ESK0",
	description = "VIPRewards",
	version = "1.0",
	url = "www.github.com/esk0"
};
public void OnPluginStart()
{
	HookEvent("round_start", Event_OnRoundStart);
}
public Action Event_OnRoundStart(Handle event, char[] name, bool dontBroadcast)
{
	LoopAliveClients(i)
	{
		if(IsClientVIP(i))
		{
			CreateTimer(2.0, Timer_VIPPlayerReward, i, TIMER_FLAG_NO_MAPCHANGE);
		}
	}
}
public Action Timer_VIPPlayerReward(Handle timer, client)
{
	if(IsValidClient(client, true))
	{
		if(GetClientTeam(client) == CS_TEAM_CT)
		{
			GivePlayerItem(client, "defuser");
		}
		CS_DropWeapon(client, 2, false, false);
		GivePlayerItem(client, "weapon_hegrenade");
		GivePlayerItem(client, "weapon_deagle");
		GivePlayerItem(client, "item_assaultsuit");
		GivePlayerItem(client, "weapon_smokegrenade");
		GivePlayerItem(client, "weapon_molotov");
		GivePlayerItem(client, "weapon_flashbang");
	}
}
stock bool IsClientVIP(int client)
{
  if (GetAdminFlag(GetUserAdmin(client), Admin_Custom2))
  {
    return true;
  }
  return false;
}
stock bool IsValidClient(int client,bool alive = false)
{
  if(0 < client && client <= MaxClients && IsClientInGame(client) && (alive == false || IsPlayerAlive(client)))
  {
    return true;
  }
  return false;
}
ESK0 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-11-2015 , 19:40   Re: [CS:GO] Help scripting
Reply With Quote #8

You might be better off hooking the player_spawn event.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
mikasonwar
Junior Member
Join Date: Sep 2015
Old 12-12-2015 , 06:32   Re: [CS:GO] Help scripting
Reply With Quote #9

Thank you ESK0! i've been trying to understand your code so i learn more of soucemod (i'm a total noob at the time of being.)

Can i publish this plugin after i mess around with it? ^-^
__________________
How 2 code?
mikasonwar is offline
ESK0
BANNED
Join Date: May 2014
Location: Czech Republic
Old 12-12-2015 , 06:47   Re: [CS:GO] Help scripting
Reply With Quote #10

Quote:
Originally Posted by mikasonwar View Post
Thank you ESK0! i've been trying to understand your code so i learn more of soucemod (i'm a total noob at the time of being.)

Can i publish this plugin after i mess around with it? ^-^
Of course you can )
ESK0 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 07:26.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode