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

[CS:GO] CreateEntityByName issue


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 06-11-2014 , 13:11   [CS:GO] CreateEntityByName issue
Reply With Quote #1

To avoid a pential XY problem, here is my initial issue.

I've got a DM plugin, but when players select a P2000 and have an usp-s in its loadout, plugin when calling
PHP Code:
GivePlayerItem(client"weapon_p2000"); 
actually gives ans usp-s.
Note that this was working great a few CS GO update ago...

I though of correcting this by checking the m_iItemDefinitionIndex and see if it matches the one I expect.
If it don't, I remove (kill) the weapon, Create a weapon using CreateEntityByName (this is to avoid having the game searching into the player loadout) and then I equip the player.

But created weapon is wierd. CreateEntityByName ("weapon_p2000") actually creates a P200, who sounds like a deagle, shot deagles bullet but at P2000 rate and accuracy.

Do you know what I'm doing wrong?

Here is the actual function:
PHP Code:
stock weapons_GivePlayerItem(clientIndexString:weaponEntityName[], weaponId=NO_WEAPON_SELECTED)
{
    new 
origTeam CS_TEAM_NONE;
    
    if(
weaponId NO_WEAPON_SELECTED)
       
origTeam player_FakeTeamSwitch(clientIndexweapons_GetSkinTeam(weaponId));
    
    if(
origTeam != weapons_GetSkinTeam(weaponId) && origTeam != CS_TEAM_NONE)
        
g_aWeapons_PlayerEquipment[clientIndex][weapons_PlayerEquipment_IsTeamInverted] = true;
    
    new 
weaponEntity GivePlayerItem(clientIndexweaponEntityName);
    
    
// Some hacking to bypass inventory
    
if(weaponId NO_WEAPON_SELECTED && weaponId != weapons_FindIdFromEntity(weaponEntity))
    {
        
weapons_RemovePlayerWeapon(weaponEntityclientIndex);
        
// Weapon is removed on a timer to prevent crash
        
CreateTimer(0.2weapons_Timer_DelayedWeaponKillEntIndexToEntRef(weaponEntity));
        
        
weaponEntity CreateEntityByName(weaponEntityName);
        
DispatchSpawn(weaponEntity);
        
EquipPlayerWeapon(clientIndexweaponEntity);
        
// For some reason clip and ammo are not initialized, fix this
        
weapons_RefillClip(EntIndexToEntRef(weaponEntity), weaponId);
        
weapons_GiveAmmo(clientIndexweaponEntityweapons_GetAmmoMax(weaponId));
    }
    
    if(
weaponId NO_WEAPON_SELECTED)
       
player_FakeTeamSwitch(clientIndexorigTeam);
    
    
weapons_TagEntity(weaponEntityweaponIdclientIndex, .isCT GetClientTeam(clientIndex) == CS_TEAM_CT);
    
    
g_aWeapons_PlayerEquipment[clientIndex][weapons_PlayerEquipment_IsTeamInverted] = false;
    
    return 
weaponEntity;

h3bus is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-11-2014 , 13:36   Re: [CS:GO] CreateEntityByName issue
Reply With Quote #2

You may want to look into the CSGO GiverNamedItem Econ extension, which was created to deal with this sort of thing.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 06-11-2014 , 14:44   Re: [CS:GO] CreateEntityByName issue
Reply With Quote #3

Well what I want is the complete inverse as the extension do.
I want player to get the selected weapon, regardless of their loadout.

Last edited by h3bus; 06-11-2014 at 14:44.
h3bus is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 06-11-2014 , 17:25   Re: [CS:GO] CreateEntityByName issue
Reply With Quote #4

They didn't delete old weapon names. And when you try to create them - the game will crash.
Use hkp2000, not p2000. The same goes for p228, which is p250 now. There are several weapons like these.
xf117 is offline
Send a message via ICQ to xf117
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 06-11-2014 , 17:31   Re: [CS:GO] CreateEntityByName issue
Reply With Quote #5

Incidentally, this game could really use an extension similar to what TF2Items does for TF2.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 06-11-2014 , 17:43   Re: [CS:GO] CreateEntityByName issue
Reply With Quote #6

Quote:
Originally Posted by Powerlord View Post
Incidentally, this game could really use an extension similar to what TF2Items does for TF2.
That would be really nice. I think it would be possible to create both weapons with custom properties (i assume it's TF2 style) and also weapons with custom skins (which, as i understand, is handled differently*).

But looking at the structure of script files, it feels they kinda half assed the whole weapon thing. Half of it works as an old CS:S script system and some part of it works as a new Item system. If it's truly that bad, then there are might be a lot of troubles to make an extension like that.

P.S.
* or at least those are different parts of one system.

Last edited by xf117; 06-11-2014 at 17:45.
xf117 is offline
Send a message via ICQ to xf117
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 06-11-2014 , 17:47   Re: [CS:GO] CreateEntityByName issue
Reply With Quote #7

Yup! It would be nice!

BTW I found a solution to my problem, kinda, but I shamefull and don't want to expose it there.
This is trash-coding.
h3bus 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 17:59.


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